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:
Hajimu UMEMOTO 2003-08-14 18:13:34 +00:00
parent 4eb4a0e6ec
commit 92bdf888a6

View File

@ -229,18 +229,23 @@ main(argc, argv)
/* initialization to dump internal status to a file */ /* initialization to dump internal status to a file */
signal(SIGUSR1, rtsold_set_dump_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. * Open a socket for sending RS and receiving RA.
* This should be done before calling ifinit(), since the function * This should be done before calling ifinit(), since the function
* uses the socket. * uses the socket.
*/ */
if ((s = sockopen()) < 0) { if ((s = sockopen()) < 0) {
errx(1, "failed to open a socket"); warnmsg(LOG_ERR, __func__, "failed to open a socket");
exit(1);
/*NOTREACHED*/ /*NOTREACHED*/
} }
maxfd = s; maxfd = s;
if ((rtsock = rtsock_open()) < 0) { if ((rtsock = rtsock_open()) < 0) {
errx(1, "failed to open a socket"); warnmsg(LOG_ERR, __func__, "failed to open a socket");
exit(1);
/*NOTREACHED*/ /*NOTREACHED*/
} }
if (rtsock > maxfd) if (rtsock > maxfd)
@ -258,12 +263,16 @@ main(argc, argv)
/* configuration per interface */ /* configuration per interface */
if (ifinit()) { if (ifinit()) {
errx(1, "failed to initilizatoin interfaces"); warnmsg(LOG_ERR, __func__,
"failed to initilizatoin interfaces");
exit(1);
/*NOTREACHED*/ /*NOTREACHED*/
} }
while (argc--) { while (argc--) {
if (ifconfig(*argv)) { if (ifconfig(*argv)) {
errx(1, "failed to initialize %s", *argv); warnmsg(LOG_ERR, __func__,
"failed to initialize %s", *argv);
exit(1);
/*NOTREACHED*/ /*NOTREACHED*/
} }
argv++; argv++;
@ -271,13 +280,12 @@ main(argc, argv)
/* setup for probing default routers */ /* setup for probing default routers */
if (probe_init()) { if (probe_init()) {
errx(1, "failed to setup for probing routers"); warnmsg(LOG_ERR, __func__,
"failed to setup for probing routers");
exit(1);
/*NOTREACHED*/ /*NOTREACHED*/
} }
if (!fflag)
daemon(0, 0); /* act as a daemon */
/* dump the current pid */ /* dump the current pid */
if (!once) { if (!once) {
pid_t pid = getpid(); pid_t pid = getpid();