From a89d80761c211ae91acf3bbb1f6325202e1d2b40 Mon Sep 17 00:00:00 2001 From: ume Date: Sun, 17 Aug 2003 17:29:54 +0000 Subject: [PATCH] daemon() has to be called prior to file descriptor setups (otherwise file descriptors could be closed mistakenly) Obtained from: KAME MFC after: 1 week --- usr.sbin/route6d/route6d.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/usr.sbin/route6d/route6d.c b/usr.sbin/route6d/route6d.c index 696a9bc112b2..e8d06bbe6496 100644 --- a/usr.sbin/route6d/route6d.c +++ b/usr.sbin/route6d/route6d.c @@ -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);