Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/mrouted Use daemon(3) and pidfile(3).



details:   https://anonhg.NetBSD.org/src/rev/f2dff18dff93
branches:  trunk
changeset: 473507:f2dff18dff93
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Jun 06 03:27:06 1999 +0000

description:
Use daemon(3) and pidfile(3).

diffstat:

 usr.sbin/mrouted/Makefile |   5 ++++-
 usr.sbin/mrouted/main.c   |  40 ++++++++--------------------------------
 2 files changed, 12 insertions(+), 33 deletions(-)

diffs (90 lines):

diff -r c02e732699b8 -r f2dff18dff93 usr.sbin/mrouted/Makefile
--- a/usr.sbin/mrouted/Makefile Sun Jun 06 02:52:16 1999 +0000
+++ b/usr.sbin/mrouted/Makefile Sun Jun 06 03:27:06 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.8 1998/04/09 00:32:41 tv Exp $
+#      $NetBSD: Makefile,v 1.9 1999/06/06 03:27:06 thorpej Exp $
 #      from: Id: Makefile,v 1.5 1993/06/24 05:11:16 deering Exp
 
 PROG=  mrouted
@@ -6,4 +6,7 @@
        route.c vif.c
 MAN=   mrouted.8
 
+LDADD+=        -lutil
+DPADD+=        ${LIBUTIL}
+
 .include <bsd.prog.mk>
diff -r c02e732699b8 -r f2dff18dff93 usr.sbin/mrouted/main.c
--- a/usr.sbin/mrouted/main.c   Sun Jun 06 02:52:16 1999 +0000
+++ b/usr.sbin/mrouted/main.c   Sun Jun 06 03:27:06 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.11 1998/05/09 17:22:08 kleink Exp $ */
+/*     $NetBSD: main.c,v 1.12 1999/06/06 03:27:06 thorpej Exp $        */
 
 /*
  * The mrouted program is covered by the license in the accompanying file
@@ -33,13 +33,15 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("@(#) $NetBSD: main.c,v 1.11 1998/05/09 17:22:08 kleink Exp $");
+__RCSID("@(#) $NetBSD: main.c,v 1.12 1999/06/06 03:27:06 thorpej Exp $");
 #endif
 
+#include <err.h>
+#include <util.h>
+
 extern char *configfilename;
 char versionstring[100];
 
-static char pidfilename[]  = _PATH_MROUTED_PID;
 static char dumpfilename[] = _PATH_MROUTED_DUMP;
 static char cachefilename[] = _PATH_MROUTED_CACHE;
 static char genidfilename[] = _PATH_MROUTED_GENID;
@@ -158,29 +160,9 @@
        /*
         * Detach from the terminal
         */
-       int t;
-
-       if (fork()) exit(0);
-       (void)close(0);
-       (void)close(1);
-       (void)close(2);
-       (void)open("/", 0);
-       (void)dup2(0, 1);
-       (void)dup2(0, 2);
-#ifdef SYSV
-       (void)setpgrp();
-#else
-#ifdef TIOCNOTTY
-       t = open("/dev/tty", 2);
-       if (t >= 0) {
-           (void)ioctl(t, TIOCNOTTY, (char *)0);
-           (void)close(t);
-       }
-#else
-       if (setsid() < 0)
-           perror("setsid");
-#endif
-#endif
+       if (daemon(0, 0))
+           err(1, "can't fork");
+       pidfile(NULL);
     }
     else
        fprintf(stderr, "debug level %u\n", debug);
@@ -272,12 +254,6 @@
     if (debug)
        fprintf(stderr, "pruning %s\n", pruning ? "on" : "off");
 
-    fp = fopen(pidfilename, "w");              
-    if (fp != NULL) {
-       fprintf(fp, "%d\n", (int)getpid());
-       (void) fclose(fp);
-    }
-
     (void)signal(SIGALRM, fasttimer);
 
     (void)signal(SIGHUP,  restart);



Home | Main Index | Thread Index | Old Index