use daemon() call
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Sat, 30 Jun 1990 11:14:33 +0000 (03:14 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Sat, 30 Jun 1990 11:14:33 +0000 (03:14 -0800)
SCCS-vsn: sbin/XNSrouted/main.c 5.10
SCCS-vsn: sbin/mountd/Makefile 5.4
SCCS-vsn: sbin/mountd/mountd.c 5.11
SCCS-vsn: sbin/nfsd/Makefile 5.3
SCCS-vsn: sbin/nfsd/nfsd.c 5.8
SCCS-vsn: sbin/routed/main.c 5.21
SCCS-vsn: sbin/routed/Makefile 5.14
SCCS-vsn: sbin/nfsiod/Makefile 5.3
SCCS-vsn: sbin/nfsiod/nfsiod.c 5.4
SCCS-vsn: usr.sbin/syslogd/Makefile 5.6
SCCS-vsn: usr.sbin/syslogd/syslogd.c 5.42

usr/src/sbin/XNSrouted/main.c
usr/src/sbin/mountd/Makefile
usr/src/sbin/mountd/mountd.c
usr/src/sbin/nfsd/Makefile
usr/src/sbin/nfsd/nfsd.c
usr/src/sbin/nfsiod/Makefile
usr/src/sbin/nfsiod/nfsiod.c
usr/src/sbin/routed/Makefile
usr/src/sbin/routed/main.c
usr/src/usr.sbin/syslogd/Makefile
usr/src/usr.sbin/syslogd/syslogd.c

index 9fd4c77..efb591d 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.10 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -88,22 +88,8 @@ main(argc, argv)
        
        
 #ifndef DEBUG
        
        
 #ifndef DEBUG
-       if (!tracepackets) {
-               int t;
-
-               if (fork())
-                       exit(0);
-               for (t = 0; t < 20; t++)
-                       (void) close(t);
-               (void) open("/", 0);
-               (void) dup2(0, 1);
-               (void) dup2(0, 2);
-               t = open(_PATH_TTY, 2);
-               if (t >= 0) {
-                       ioctl(t, TIOCNOTTY, (char *)0);
-                       (void) close(t);
-               }
-       }
+       if (!tracepackets)
+               daemon(0, 0);
 #endif
        openlog("XNSrouted", LOG_PID, LOG_DAEMON);
 
 #endif
        openlog("XNSrouted", LOG_PID, LOG_DAEMON);
 
index 17035dd..48129bd 100644 (file)
@@ -1,10 +1,10 @@
-#      @(#)Makefile    5.3 (Berkeley) %G%
+#      @(#)Makefile    5.4 (Berkeley) %G%
 
 PROG=  mountd
 CFLAGS+=-DNFS
 MAN5=  exports.0
 MAN8=  mountd.0
 DPADD= ${LIBRPC}
 
 PROG=  mountd
 CFLAGS+=-DNFS
 MAN5=  exports.0
 MAN8=  mountd.0
 DPADD= ${LIBRPC}
-LDADD= -lrpc
+LDADD= -lrpc -lutil
 
 .include <bsd.prog.mk>
 
 .include <bsd.prog.mk>
index e0562d7..95222b9 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)mountd.c   5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)mountd.c   5.11 (Berkeley) %G%";
 #endif not lint
 
 #include <sys/param.h>
 #endif not lint
 
 #include <sys/param.h>
@@ -120,25 +120,7 @@ main(argc, argv)
        get_exportlist();
        get_mountlist();
        if (debug == 0) {
        get_exportlist();
        get_mountlist();
        if (debug == 0) {
-               if (fork())
-                       exit(0);
-               { int s;
-               for (s = 0; s < 10; s++)
-                       (void) close(s);
-               }
-               (void) open("/", O_RDONLY);
-               (void) dup2(0, 1);
-               (void) dup2(0, 2);
-               { int tt = open("/dev/tty", O_RDWR);
-                 if (tt > 0) {
-                       ioctl(tt, TIOCNOTTY, (char *)0);
-                       close(tt);
-                 }
-               }
-               (void) setpgrp(0, 0);
-               signal(SIGTSTP, SIG_IGN);
-               signal(SIGTTIN, SIG_IGN);
-               signal(SIGTTOU, SIG_IGN);
+               daemon(0, 0);
                signal(SIGINT, SIG_IGN);
                signal(SIGQUIT, SIG_IGN);
        }
                signal(SIGINT, SIG_IGN);
                signal(SIGQUIT, SIG_IGN);
        }
@@ -161,6 +143,7 @@ main(argc, argv)
        }
        svc_run();
        syslog(LOG_ERR, "Mountd died");
        }
        svc_run();
        syslog(LOG_ERR, "Mountd died");
+       exit(1);
 }
 
 /*
 }
 
 /*
index 61d4123..f611f24 100644 (file)
@@ -1,9 +1,9 @@
-#      @(#)Makefile    5.2 (Berkeley) %G%
+#      @(#)Makefile    5.3 (Berkeley) %G%
 
 PROG=  nfsd
 CFLAGS+=-DNFS
 MAN8=  nfsd.0
 DPADD= ${LIBRPC}
 
 PROG=  nfsd
 CFLAGS+=-DNFS
 MAN8=  nfsd.0
 DPADD= ${LIBRPC}
-LDADD= -lrpc
+LDADD= -lrpc -lutil
 
 .include <bsd.prog.mk>
 
 .include <bsd.prog.mk>
index 7c4c3ba..e853b32 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)nfsd.c     5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)nfsd.c     5.8 (Berkeley) %G%";
 #endif not lint
 
 #include <sys/types.h>
 #endif not lint
 
 #include <sys/types.h>
@@ -142,25 +142,7 @@ main(argc, argv)
                udpflag++;
        }
        if (debug == 0) {
                udpflag++;
        }
        if (debug == 0) {
-               if (fork())
-                       exit(0);
-               { int s;
-               for (s = 0; s < 10; s++)
-                       (void) close(s);
-               }
-               (void) open("/dev/null", O_RDONLY);
-               (void) open("/dev/null", O_WRONLY);
-               (void) dup2(1, 2);
-               { int tt = open("/dev/tty", O_RDWR);
-                 if (tt > 0) {
-                       ioctl(tt, TIOCNOTTY, (char *)0);
-                       close(tt);
-                 }
-               }
-               (void) setpgrp(0, 0);
-               signal(SIGTSTP, SIG_IGN);
-               signal(SIGTTIN, SIG_IGN);
-               signal(SIGTTOU, SIG_IGN);
+               daemon(0, 0);
                signal(SIGINT, SIG_IGN);
                signal(SIGQUIT, SIG_IGN);
                signal(SIGTERM, SIG_IGN);
                signal(SIGINT, SIG_IGN);
                signal(SIGQUIT, SIG_IGN);
                signal(SIGTERM, SIG_IGN);
index 3ece8a9..6c30459 100644 (file)
@@ -1,7 +1,8 @@
-#      @(#)Makefile    5.2 (Berkeley) %G%
+#      @(#)Makefile    5.3 (Berkeley) %G%
 
 PROG=  nfsiod
 CFLAGS+=-DNFS
 MAN8=  nfsiod.0
 
 PROG=  nfsiod
 CFLAGS+=-DNFS
 MAN8=  nfsiod.0
+LDADD= -lutil
 
 .include <bsd.prog.mk>
 
 .include <bsd.prog.mk>
index 1aa86ba..973c797 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)nfsiod.c   5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)nfsiod.c   5.4 (Berkeley) %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -44,25 +44,7 @@ main(argc, argv)
        int cnt;
 
        if (debug == 0) {
        int cnt;
 
        if (debug == 0) {
-               if (fork())
-                       exit(0);
-               { int s;
-               for (s = 0; s < 10; s++)
-                       (void) close(s);
-               }
-               (void) open("/", O_RDONLY);
-               (void) dup2(0, 1);
-               (void) dup2(0, 2);
-               { int tt = open("/dev/tty", O_RDWR);
-                 if (tt > 0) {
-                       ioctl(tt, TIOCNOTTY, (char *)0);
-                       close(tt);
-                 }
-               }
-               (void) setpgrp(0, 0);
-               signal(SIGTSTP, SIG_IGN);
-               signal(SIGTTIN, SIG_IGN);
-               signal(SIGTTOU, SIG_IGN);
+               daemon(0, 0);
                signal(SIGINT, SIG_IGN);
                signal(SIGQUIT, SIG_IGN);
                signal(SIGTERM, SIG_IGN);
                signal(SIGINT, SIG_IGN);
                signal(SIGQUIT, SIG_IGN);
                signal(SIGTERM, SIG_IGN);
index e3092b0..b605761 100644 (file)
@@ -1,10 +1,11 @@
-#      @(#)Makefile    5.13 (Berkeley) %G%
+#      @(#)Makefile    5.14 (Berkeley) %G%
 
 PROG=  routed
 SRCS=  af.c if.c input.c main.c output.c startup.c tables.c timer.c \
        trace.c inet.c
 MAN8=  routed.0
 SUBDIR=        query trace
 
 PROG=  routed
 SRCS=  af.c if.c input.c main.c output.c startup.c tables.c timer.c \
        trace.c inet.c
 MAN8=  routed.0
 SUBDIR=        query trace
+LDADD= -lutil
 
 .include <bsd.prog.mk>
 
 
 .include <bsd.prog.mk>
 
index 1c713b8..34a240b 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -97,23 +97,8 @@ main(argc, argv)
                exit(1);
        }
 
                exit(1);
        }
 
-       if (debug == 0) {
-               int t;
-
-               if (fork())
-                       exit(0);
-               for (t = 0; t < 20; t++)
-                       if (t != s)
-                               (void) close(t);
-               (void) open("/", 0);
-               (void) dup2(0, 1);
-               (void) dup2(0, 2);
-               t = open(_PATH_TTY, 2);
-               if (t >= 0) {
-                       ioctl(t, TIOCNOTTY, (char *)0);
-                       (void) close(t);
-               }
-       }
+       if (debug == 0)
+               daemon(0, 0);
        /*
         * Any extra argument is considered
         * a tracing log file.
        /*
         * Any extra argument is considered
         * a tracing log file.
index 767b087..3c5c42f 100644 (file)
@@ -1,8 +1,9 @@
-#      @(#)Makefile    5.5 (Berkeley) %G%
+#      @(#)Makefile    5.6 (Berkeley) %G%
 
 PROG=  syslogd
 SRCS=  syslogd.c ttymsg.c
 .PATH: ${.CURDIR}/../../usr.bin/wall
 MAN8=  syslogd.0
 
 PROG=  syslogd
 SRCS=  syslogd.c ttymsg.c
 .PATH: ${.CURDIR}/../../usr.bin/wall
 MAN8=  syslogd.0
+LDADD= -lutil
 
 .include <bsd.prog.mk>
 
 .include <bsd.prog.mk>
index 40e5794..c3d8703 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)syslogd.c  5.41 (Berkeley) %G%";
+static char sccsid[] = "@(#)syslogd.c  5.42 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -198,16 +198,9 @@ main(argc, argv)
        if (argc -= optind)
                usage();
 
        if (argc -= optind)
                usage();
 
-       if (!Debug) {
-               if (fork())
-                       exit(0);
-               for (i = 0; i < 10; i++)
-                       (void) close(i);
-               (void) open("/", O_RDONLY, 0);
-               (void) dup2(STDIN_FILENO, STDOUT_FILENO);
-               (void) dup2(STDIN_FILENO, STDERR_FILENO);
-               untty();
-       } else
+       if (!Debug)
+               daemon(0, 0);
+       else
                setlinebuf(stdout);
 
        consfile.f_type = F_CONSOLE;
                setlinebuf(stdout);
 
        consfile.f_type = F_CONSOLE;
@@ -338,19 +331,6 @@ usage()
        exit(1);
 }
 
        exit(1);
 }
 
-untty()
-{
-       int i;
-
-       if (!Debug) {
-               i = open(_PATH_TTY, O_RDWR, 0);
-               if (i >= 0) {
-                       (void) ioctl(i, (int) TIOCNOTTY, (char *)0);
-                       (void) close(i);
-               }
-       }
-}
-
 /*
  * Take a raw input line, decode the message, and print the message
  * on the appropriate log files.
 /*
  * Take a raw input line, decode the message, and print the message
  * on the appropriate log files.
@@ -494,7 +474,6 @@ logmsg(pri, msg, from, flags)
                f->f_file = open(ctty, O_WRONLY, 0);
 
                if (f->f_file >= 0) {
                f->f_file = open(ctty, O_WRONLY, 0);
 
                if (f->f_file >= 0) {
-                       untty();
                        fprintlog(f, flags, msg);
                        (void) close(f->f_file);
                }
                        fprintlog(f, flags, msg);
                        (void) close(f->f_file);
                }
@@ -660,10 +639,8 @@ fprintlog(f, flags, msg)
                                if (f->f_file < 0) {
                                        f->f_type = F_UNUSED;
                                        logerror(f->f_un.f_fname);
                                if (f->f_file < 0) {
                                        f->f_type = F_UNUSED;
                                        logerror(f->f_un.f_fname);
-                               } else {
-                                       untty();
+                               } else
                                        goto again;
                                        goto again;
-                               }
                        } else {
                                f->f_type = F_UNUSED;
                                errno = e;
                        } else {
                                f->f_type = F_UNUSED;
                                errno = e;
@@ -1057,10 +1034,8 @@ cfline(line, f)
                        logerror(p);
                        break;
                }
                        logerror(p);
                        break;
                }
-               if (isatty(f->f_file)) {
+               if (isatty(f->f_file))
                        f->f_type = F_TTY;
                        f->f_type = F_TTY;
-                       untty();
-               }
                else
                        f->f_type = F_FILE;
                if (strcmp(p, ctty) == 0)
                else
                        f->f_type = F_FILE;
                if (strcmp(p, ctty) == 0)