use daemon() call
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Sat, 30 Jun 1990 11:55:57 +0000 (03:55 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Sat, 30 Jun 1990 11:55:57 +0000 (03:55 -0800)
SCCS-vsn: usr.sbin/timed/timed/Makefile 5.11
SCCS-vsn: usr.sbin/timed/timed/timed.c 2.20
SCCS-vsn: usr.sbin/sendmail/src/main.c 5.30
SCCS-vsn: usr.sbin/rwhod/rwhod.c 5.19
SCCS-vsn: usr.sbin/lpr/lpd/Makefile 5.3
SCCS-vsn: usr.sbin/lpr/lpd/lpd.c 5.9

usr/src/usr.sbin/lpr/lpd/Makefile
usr/src/usr.sbin/lpr/lpd/lpd.c
usr/src/usr.sbin/rwhod/rwhod.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/timed/timed/Makefile
usr/src/usr.sbin/timed/timed/timed.c

index 25a8c63..d634ca0 100644 (file)
@@ -1,7 +1,8 @@
-#      @(#)Makefile    5.2 (Berkeley) %G%
+#      @(#)Makefile    5.3 (Berkeley) %G%
 
 PROG=  lpd
 CFLAGS+=-I${.CURDIR}/../common_source
 
 PROG=  lpd
 CFLAGS+=-I${.CURDIR}/../common_source
+LDADD= -lutil
 MAN8=  lpd.0
 SRCS=  lpd.c printjob.c recvjob.c displayq.c rmjob.c startdaemon.c \
        lpdchar.c common.c printcap.c
 MAN8=  lpd.0
 SRCS=  lpd.c printjob.c recvjob.c displayq.c rmjob.c startdaemon.c \
        lpdchar.c common.c printcap.c
index b9ab84c..c1d752b 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)lpd.c      5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)lpd.c      5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -81,18 +81,7 @@ main(argc, argv)
        /*
         * Set up standard environment by detaching from the parent.
         */
        /*
         * Set up standard environment by detaching from the parent.
         */
-       if (fork())
-               exit(0);
-       for (f = 0; f < 5; f++)
-               (void) close(f);
-       (void) open(_PATH_DEVNULL, O_RDONLY);
-       (void) open(_PATH_DEVNULL, O_WRONLY);
-       (void) dup(1);
-       f = open(_PATH_TTY, O_RDWR);
-       if (f > 0) {
-               ioctl(f, TIOCNOTTY, 0);
-               (void) close(f);
-       }
+       daemon(0, 0);
 #endif
 
        openlog("lpd", LOG_PID, LOG_LPR);
 #endif
 
        openlog("lpd", LOG_PID, LOG_LPR);
index eaa9564..2bb9c12 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)rwhod.c    5.18 (Berkeley) %G%";
+static char sccsid[] = "@(#)rwhod.c    5.19 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -97,20 +97,7 @@ main()
                exit(1);
        }
 #ifndef DEBUG
                exit(1);
        }
 #ifndef DEBUG
-       if (fork())
-               exit(0);
-       { int s;
-         for (s = 0; s < 10; s++)
-               (void) close(s);
-         (void) open("/", 0);
-         (void) dup2(0, 1);
-         (void) dup2(0, 2);
-         s = open(_PATH_TTY, 2);
-         if (s >= 0) {
-               ioctl(s, TIOCNOTTY, 0);
-               (void) close(s);
-         }
-       }
+       daemon(1, 0);
 #endif
        if (chdir(_PATH_RWHODIR) < 0) {
                (void)fprintf(stderr, "rwhod: %s: %s\n",
 #endif
        if (chdir(_PATH_RWHODIR) < 0) {
                (void)fprintf(stderr, "rwhod: %s: %s\n",
index 86cb930..cca4f88 100644 (file)
@@ -13,11 +13,12 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.29 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.30 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        _DEFINE
 
 #endif /* not lint */
 
 #define        _DEFINE
 
+#include <sys/param.h>
 #include <sys/file.h>
 #include <signal.h>
 #include <sgtty.h>
 #include <sys/file.h>
 #include <signal.h>
 #include <sgtty.h>
@@ -1047,10 +1048,13 @@ disconnect(fulldrop)
        while ((fd = dup(fileno(CurEnv->e_xfp))) < 2 && fd > 0)
                continue;
 
        while ((fd = dup(fileno(CurEnv->e_xfp))) < 2 && fd > 0)
                continue;
 
-#ifdef TIOCNOTTY
        /* drop our controlling TTY completely if possible */
        if (fulldrop)
        {
        /* drop our controlling TTY completely if possible */
        if (fulldrop)
        {
+#if BSD > 43
+               daemon(1, 1);
+#else
+#ifdef TIOCNOTTY
                fd = open("/dev/tty", 2);
                if (fd >= 0)
                {
                fd = open("/dev/tty", 2);
                if (fd >= 0)
                {
@@ -1058,9 +1062,10 @@ disconnect(fulldrop)
                        (void) close(fd);
                }
                (void) setpgrp(0, 0);
                        (void) close(fd);
                }
                (void) setpgrp(0, 0);
+#endif /* TIOCNOTTY */
+#endif /* BSD */
                errno = 0;
        }
                errno = 0;
        }
-#endif TIOCNOTTY
 
 # ifdef LOG
        if (LogLevel > 11)
 
 # ifdef LOG
        if (LogLevel > 11)
index 0d0da6a..7177c81 100644 (file)
@@ -1,4 +1,4 @@
-#      @(#)Makefile    5.10 (Berkeley) %G%
+#      @(#)Makefile    5.11 (Berkeley) %G%
 #
 # optional flags are: MEASURE TESTING DEBUG
 
 #
 # optional flags are: MEASURE TESTING DEBUG
 
index 739752f..6f63962 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)timed.c    2.19 (Berkeley) %G%";
+static char sccsid[] = "@(#)timed.c    2.20 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "globals.h"
 #endif /* not lint */
 
 #include "globals.h"