diff --git a/daemonize.c b/daemonize.c index b1bfe9c..9a10276 100644 --- a/daemonize.c +++ b/daemonize.c @@ -41,12 +41,12 @@ #include "config.h" #include "log.h" -#ifndef USE_DAEMON - int daemonize(void) { - int pid, i; + int pid; +#ifndef USE_DAEMON + int i; switch(fork()) { @@ -72,16 +72,20 @@ daemonize(void) dup(i); /* stderr */ umask(027); - chdir("/"); /* chdir to /tmp ? */ - - return pid; + chdir("/"); + break; /* parent process */ default: exit(0); } -} +#else + if( daemon(0, 0) < 0 ) + perror("daemon()"); + pid = getpid(); #endif + return pid; +} int writepidfile(const char * fname, int pid) diff --git a/daemonize.h b/daemonize.h index ee763bd..7a05d6c 100644 --- a/daemonize.h +++ b/daemonize.h @@ -31,13 +31,11 @@ #include "config.h" -#ifndef USE_DAEMON /* daemonize() * "fork" to background, detach from terminal, etc... * returns: pid of the daemon, exits upon failure */ int daemonize(void); -#endif /* writepidfile() * write the pid to a file */ diff --git a/minidlna.c b/minidlna.c index 1ce0d52..4fa5f2e 100644 --- a/minidlna.c +++ b/minidlna.c @@ -789,14 +789,7 @@ init(int argc, char * * argv) } else { -#ifdef USE_DAEMON - if(daemon(0, 0)<0) { - perror("daemon()"); - } - pid = getpid(); -#else pid = daemonize(); -#endif #ifdef READYNAS log_init("/var/log/upnp-av.log", "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn"); #else