BSD 4_3_Reno release
[unix-history] / usr / src / usr.sbin / inetd / inetd.c
index 933974a..6973d0c 100644 (file)
@@ -2,17 +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.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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
@@ -22,7 +24,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)inetd.c    5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)inetd.c    5.25 (Berkeley) 6/29/90";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -78,7 +80,7 @@ static char sccsid[] = "@(#)inetd.c   5.20 (Berkeley) %G%";
 #include <syslog.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <syslog.h>
 #include <pwd.h>
 #include <stdio.h>
-#include <strings.h>
+#include <string.h>
 #include "pathnames.h"
 
 #define        TOOMANY         40              /* don't start more than TOOMANY */
 #include "pathnames.h"
 
 #define        TOOMANY         40              /* don't start more than TOOMANY */
@@ -192,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;
@@ -254,7 +240,7 @@ main(argc, argv, envp)
                n--;
                if (debug)
                        fprintf(stderr, "someone wants %s\n", sep->se_service);
                n--;
                if (debug)
                        fprintf(stderr, "someone wants %s\n", sep->se_service);
-               if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) {
+               if (sep->se_socktype == SOCK_STREAM) {
                        ctrl = accept(sep->se_fd, (struct sockaddr *)0,
                            (int *)0);
                        if (debug)
                        ctrl = accept(sep->se_fd, (struct sockaddr *)0,
                            (int *)0);
                        if (debug)
@@ -262,7 +248,8 @@ main(argc, argv, envp)
                        if (ctrl < 0) {
                                if (errno == EINTR)
                                        continue;
                        if (ctrl < 0) {
                                if (errno == EINTR)
                                        continue;
-                               syslog(LOG_WARNING, "accept: %m");
+                               syslog(LOG_WARNING, "accept (for %s): %m",
+                                       sep->se_service);
                                continue;
                        }
                } else
                                continue;
                        }
                } else
@@ -302,7 +289,7 @@ main(argc, argv, envp)
                        pid = fork();
                }
                if (pid < 0) {
                        pid = fork();
                }
                if (pid < 0) {
-                       if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
+                       if (sep->se_socktype == SOCK_STREAM)
                                close(ctrl);
                        sigsetmask(0L);
                        sleep(1);
                                close(ctrl);
                        sigsetmask(0L);
                        sleep(1);
@@ -315,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)
@@ -360,7 +338,7 @@ main(argc, argv, envp)
                                _exit(1);
                        }
                }
                                _exit(1);
                        }
                }
-               if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
+               if (sep->se_socktype == SOCK_STREAM)
                        close(ctrl);
            }
        }
                        close(ctrl);
            }
        }
@@ -662,7 +640,7 @@ again:
        while (*cp == ' ' || *cp == '\t')
                cp++;
        if (*cp == '\0') {
        while (*cp == ' ' || *cp == '\t')
                cp++;
        if (*cp == '\0') {
-               char c;
+               int c;
 
                c = getc(fconfig);
                (void) ungetc(c, fconfig);
 
                c = getc(fconfig);
                (void) ungetc(c, fconfig);