diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-01-11 03:51:09 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-01-11 03:51:09 +0000 |
commit | 1e286bf79bcff9bd04964a6d4b7b0773a1e7afa6 (patch) | |
tree | 0fbc05365ca874a6326cdf81a3b8732218b12bfa /usr.sbin/rtsold/rtsold.c | |
parent | 9f1463a8c6c1b28e4c9707469ac02a119f30e7d6 (diff) |
call daemon(3) prior to socket setups to avoid file descriptor close mistakes.
noted by markus, sync with kame
Diffstat (limited to 'usr.sbin/rtsold/rtsold.c')
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index b8443763675..e17fc79cea2 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsold.c,v 1.13 2001/12/01 23:27:24 miod Exp $ */ +/* $OpenBSD: rtsold.c,v 1.14 2002/01/11 03:51:08 itojun Exp $ */ /* $KAME: rtsold.c,v 1.32 2001/07/09 22:34:07 itojun Exp $ */ /* @@ -217,19 +217,24 @@ main(argc, argv) /*NOTREACHED*/ } + 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, __FUNCTION__, "failed to open a socket"); + exit(1); /*NOTREACHED*/ } maxfd = s; #if 0 if ((rtsock = rtsock_open()) < 0) { - errx(1, "failed to open a socket"); + warnmsg(LOG_ERR, __FUNCTION__, "failed to open a socket"); + exit(1); /*NOTREACHED*/ } if (rtsock > maxfd) @@ -238,12 +243,16 @@ main(argc, argv) /* configuration per interface */ if (ifinit()) { - errx(1, "failed to initilizatoin interfaces"); + warnmsg(LOG_ERR, __FUNCTION__, + "failed to initilizatoin interfaces"); + exit(1); /*NOTREACHED*/ } while (argc--) { if (ifconfig(*argv)) { - errx(1, "failed to initialize %s", *argv); + warnmsg(LOG_ERR, __FUNCTION__, + "failed to initialize %s", *argv); + exit(1); /*NOTREACHED*/ } argv++; @@ -251,13 +260,12 @@ main(argc, argv) /* setup for probing default routers */ if (probe_init()) { - errx(1, "failed to setup for probing routers"); + warnmsg(LOG_ERR, __FUNCTION__, + "failed to setup for probing routers"); + exit(1); /*NOTREACHED*/ } - if (!fflag) - daemon(0, 0); /* act as a daemon */ - /* dump the current pid */ if (!once) { if (pidfile(NULL) < 0) { |