daemon() has to be called prior to file descriptor setups
(otherwise file descriptors could be closed mistakenly) Obtained from: KAME MFC after: 1 week
This commit is contained in:
parent
8a92d72c44
commit
532ba48e39
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=119037
@ -349,6 +349,14 @@ main(argc, argv)
|
||||
nflag = 1;
|
||||
fprintf(stderr, "No kernel update is allowed\n");
|
||||
}
|
||||
|
||||
if (dflag == 0) {
|
||||
if (daemon(0, 0) < 0) {
|
||||
fatal("daemon");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
|
||||
openlog(progname, LOG_NDELAY|LOG_PID, LOG_DAEMON);
|
||||
logopened++;
|
||||
|
||||
@ -389,21 +397,6 @@ main(argc, argv)
|
||||
if (dflag)
|
||||
ifrtdump(0);
|
||||
|
||||
if (dflag == 0) {
|
||||
#if 1
|
||||
if (daemon(0, 0) < 0) {
|
||||
fatal("daemon");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
#else
|
||||
if (fork())
|
||||
exit(0);
|
||||
if (setsid() < 0) {
|
||||
fatal("setid");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
#endif
|
||||
}
|
||||
pid = getpid();
|
||||
if ((pidfile = fopen(ROUTE6D_PID, "w")) != NULL) {
|
||||
fprintf(pidfile, "%d\n", pid);
|
||||
|
Loading…
Reference in New Issue
Block a user