minissdpd: daemonize after init

In order to fail launch and return an error to the parent process
if the init fails.

See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644509
This commit is contained in:
Thomas Bernard 2011-10-07 11:36:07 +02:00
parent 5e69a32343
commit 7846aaa4c2
2 changed files with 16 additions and 14 deletions

View File

@ -3,6 +3,7 @@ $Id: Changelog.txt,v 1.20 2011/10/07 09:21:19 nanard Exp $
2011/10/07:
unlink unix socket before binding.
set SO_REUSEADDR on SSDP socket.
daemonize after init
VERSION 1.1:

View File

@ -819,18 +819,6 @@ int main(int argc, char * * argv)
return 1;
}
/* daemonize or in any case get pid ! */
if(debug_flag)
pid = getpid();
else {
#ifdef USE_DAEMON
if(daemon(0, 0) < 0)
perror("daemon()");
pid = getpid();
#else
pid = daemonize();
#endif
}
/* open log */
openlog("minissdpd",
LOG_CONS|LOG_PID|(debug_flag?LOG_PERROR:0),
@ -844,8 +832,6 @@ int main(int argc, char * * argv)
return 1;
}
writepidfile(pidfilename, pid);
/* set signal handlers */
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = sigterm;
@ -923,6 +909,21 @@ int main(int argc, char * * argv)
}
#endif
/* daemonize or in any case get pid ! */
if(debug_flag)
pid = getpid();
else {
#ifdef USE_DAEMON
if(daemon(0, 0) < 0)
perror("daemon()");
pid = getpid();
#else
pid = daemonize();
#endif
}
writepidfile(pidfilename, pid);
/* Main loop */
while(!quitting)
{