* Simplify daemonize ifdefs.

This commit is contained in:
Justin Maggard 2011-09-03 01:32:56 +00:00
parent ef37d2e993
commit 4857493e4f
3 changed files with 11 additions and 16 deletions

View File

@ -41,12 +41,12 @@
#include "config.h" #include "config.h"
#include "log.h" #include "log.h"
#ifndef USE_DAEMON
int int
daemonize(void) daemonize(void)
{ {
int pid, i; int pid;
#ifndef USE_DAEMON
int i;
switch(fork()) switch(fork())
{ {
@ -72,16 +72,20 @@ daemonize(void)
dup(i); /* stderr */ dup(i); /* stderr */
umask(027); umask(027);
chdir("/"); /* chdir to /tmp ? */ chdir("/");
return pid;
break;
/* parent process */ /* parent process */
default: default:
exit(0); exit(0);
} }
} #else
if( daemon(0, 0) < 0 )
perror("daemon()");
pid = getpid();
#endif #endif
return pid;
}
int int
writepidfile(const char * fname, int pid) writepidfile(const char * fname, int pid)

View File

@ -31,13 +31,11 @@
#include "config.h" #include "config.h"
#ifndef USE_DAEMON
/* daemonize() /* daemonize()
* "fork" to background, detach from terminal, etc... * "fork" to background, detach from terminal, etc...
* returns: pid of the daemon, exits upon failure */ * returns: pid of the daemon, exits upon failure */
int int
daemonize(void); daemonize(void);
#endif
/* writepidfile() /* writepidfile()
* write the pid to a file */ * write the pid to a file */

View File

@ -789,14 +789,7 @@ init(int argc, char * * argv)
} }
else else
{ {
#ifdef USE_DAEMON
if(daemon(0, 0)<0) {
perror("daemon()");
}
pid = getpid();
#else
pid = daemonize(); pid = daemonize();
#endif
#ifdef READYNAS #ifdef READYNAS
log_init("/var/log/upnp-av.log", "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn"); log_init("/var/log/upnp-av.log", "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn");
#else #else