BSD 4_3_Reno release
[unix-history] / usr / src / usr.sbin / inetd / inetd.c
index abac458..6973d0c 100644 (file)
@@ -2,7 +2,19 @@
  * Copyright (c) 1983 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1983 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * Neither the name of the University nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -12,7 +24,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)inetd.c    5.24 (Berkeley) %G%";
+static char sccsid[] = "@(#)inetd.c    5.25 (Berkeley) 6/29/90";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -182,24 +194,8 @@ main(argc, argv, envp)
 
        if (argc > 0)
                CONFIG = argv[0];
 
        if (argc > 0)
                CONFIG = argv[0];
-       if (debug == 0) {
-               if (fork())
-                       exit(0);
-               for (tmpint = 0; tmpint < 10; tmpint++)
-                       (void) close(tmpint);
-               (void) open("/", O_RDONLY);
-               (void) dup2(0, 1);
-               (void) dup2(0, 2);
-               tmpint = open(_PATH_TTY, O_RDWR);
-               if (tmpint > 0) {
-                       ioctl(tmpint, TIOCNOTTY, (char *)0);
-                       close(tmpint);
-               }
-               (void) setpgrp(0, 0);
-               (void) signal(SIGTSTP, SIG_IGN);
-               (void) signal(SIGTTIN, SIG_IGN);
-               (void) signal(SIGTTOU, SIG_IGN);
-       }
+       if (debug == 0)
+               daemon(0, 0);
        openlog("inetd", LOG_PID | LOG_NOWAIT, LOG_DAEMON);
        bzero((char *)&sv, sizeof(sv));
        sv.sv_mask = SIGBLOCK;
        openlog("inetd", LOG_PID | LOG_NOWAIT, LOG_DAEMON);
        bzero((char *)&sv, sizeof(sv));
        sv.sv_mask = SIGBLOCK;
@@ -306,17 +302,8 @@ main(argc, argv, envp)
                }
                sigsetmask(0L);
                if (pid == 0) {
                }
                sigsetmask(0L);
                if (pid == 0) {
-                       if (debug) {
-                               if (dofork &&
-                                   (tmpint = open(_PATH_TTY, O_RDWR)) > 0) {
-                                       ioctl(tmpint, TIOCNOTTY, 0);
-                                       close(tmpint);
-                               }
-                               (void) setpgrp(0, 0);
-                               (void) signal(SIGTSTP, SIG_IGN);
-                               (void) signal(SIGTTIN, SIG_IGN);
-                               (void) signal(SIGTTOU, SIG_IGN);
-                       }
+                       if (debug && dofork)
+                               setsid();
                        if (dofork)
                                for (tmpint = getdtablesize(); --tmpint > 2; )
                                        if (tmpint != ctrl)
                        if (dofork)
                                for (tmpint = getdtablesize(); --tmpint > 2; )
                                        if (tmpint != ctrl)