From 92bdf888a63d064ee798ed9c396f449fdc93598a Mon Sep 17 00:00:00 2001 From: Hajimu UMEMOTO Date: Thu, 14 Aug 2003 18:13:34 +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/rtsold/rtsold.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index 36ecb30e61b4..d6891e71f033 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -229,18 +229,23 @@ main(argc, argv) /* initialization to dump internal status to a file */ signal(SIGUSR1, rtsold_set_dump_file); + if (!fflag) + daemon(0, 0); /* act as a daemon */ + /* * Open a socket for sending RS and receiving RA. * This should be done before calling ifinit(), since the function * uses the socket. */ if ((s = sockopen()) < 0) { - errx(1, "failed to open a socket"); + warnmsg(LOG_ERR, __func__, "failed to open a socket"); + exit(1); /*NOTREACHED*/ } maxfd = s; if ((rtsock = rtsock_open()) < 0) { - errx(1, "failed to open a socket"); + warnmsg(LOG_ERR, __func__, "failed to open a socket"); + exit(1); /*NOTREACHED*/ } if (rtsock > maxfd) @@ -258,12 +263,16 @@ main(argc, argv) /* configuration per interface */ if (ifinit()) { - errx(1, "failed to initilizatoin interfaces"); + warnmsg(LOG_ERR, __func__, + "failed to initilizatoin interfaces"); + exit(1); /*NOTREACHED*/ } while (argc--) { if (ifconfig(*argv)) { - errx(1, "failed to initialize %s", *argv); + warnmsg(LOG_ERR, __func__, + "failed to initialize %s", *argv); + exit(1); /*NOTREACHED*/ } argv++; @@ -271,13 +280,12 @@ main(argc, argv) /* setup for probing default routers */ if (probe_init()) { - errx(1, "failed to setup for probing routers"); + warnmsg(LOG_ERR, __func__, + "failed to setup for probing routers"); + exit(1); /*NOTREACHED*/ } - if (!fflag) - daemon(0, 0); /* act as a daemon */ - /* dump the current pid */ if (!once) { pid_t pid = getpid();