Berkeley header; declare strdup() properly for ANSI C
[unix-history] / usr / src / usr.sbin / inetd / inetd.c
index 9b61953..ceda3ff 100644 (file)
@@ -1,18 +1,24 @@
 /*
  * Copyright (c) 1983 Regents of the University of California.
 /*
  * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of California at 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'' without express or implied warranty.
  */
 
 #ifndef lint
 char copyright[] =
 "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  All rights reserved.\n";
  */
 
 #ifndef lint
 char copyright[] =
 "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)inetd.c    5.9 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)inetd.c    5.12 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Inetd - Internet super-server
 
 /*
  * Inetd - Internet super-server
@@ -178,24 +184,27 @@ nextopt:
        }
        if (argc > 0)
                CONFIG = argv[0];
        }
        if (argc > 0)
                CONFIG = argv[0];
-#ifndef DEBUG
-       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);
-         }
+       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);
        }
        }
-       (void) setpgrp(0, 0);
-#endif
        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;
@@ -291,14 +300,18 @@ nextopt:
                }
                sigsetmask(0L);
                if (pid == 0) {
                }
                sigsetmask(0L);
                if (pid == 0) {
-#ifdef DEBUG
-                       int tt;
+                       if (debug) {
+                           int tt;
 
 
-                       if (dofork && (tt = open("/dev/tty", O_RDWR)) > 0) {
+                           if (dofork && (tt = open("/dev/tty", O_RDWR)) > 0) {
                                ioctl(tt, TIOCNOTTY, 0);
                                close(tt);
                                ioctl(tt, TIOCNOTTY, 0);
                                close(tt);
+                           }
+                           (void) setpgrp(0, 0);
+                           signal(SIGTSTP, SIG_IGN);
+                           signal(SIGTTIN, SIG_IGN);
+                           signal(SIGTTOU, SIG_IGN);
                        }
                        }
-#endif
                        if (dofork)
                                for (i = getdtablesize(); --i > 2; )
                                        if (i != ctrl)
                        if (dofork)
                                for (i = getdtablesize(); --i > 2; )
                                        if (i != ctrl)
@@ -501,7 +514,6 @@ enter(cp)
 {
        register struct servtab *sep;
        long omask;
 {
        register struct servtab *sep;
        long omask;
-       char *strdup();
 
        sep = (struct servtab *)malloc(sizeof (*sep));
        if (sep == (struct servtab *)0) {
 
        sep = (struct servtab *)malloc(sizeof (*sep));
        if (sep == (struct servtab *)0) {
@@ -546,8 +558,8 @@ struct servtab *
 getconfigent()
 {
        register struct servtab *sep = &serv;
 getconfigent()
 {
        register struct servtab *sep = &serv;
-       char *cp, *arg;
        int argc;
        int argc;
+       char *cp, *arg, *strdup();
 
 more:
        while ((cp = nextline(fconfig)) && *cp == '#')
 
 more:
        while ((cp = nextline(fconfig)) && *cp == '#')
@@ -689,9 +701,9 @@ setproctitle(a, s)
        cp = Argv[0];
        size = sizeof(sin);
        if (getpeername(s, &sin, &size) == 0)
        cp = Argv[0];
        size = sizeof(sin);
        if (getpeername(s, &sin, &size) == 0)
-               sprintf(buf, "-%s [%s]", a, inet_ntoa(sin.sin_addr)); 
+               (void) sprintf(buf, "-%s [%s]", a, inet_ntoa(sin.sin_addr)); 
        else
        else
-               sprintf(buf, "-%s", a); 
+               (void) sprintf(buf, "-%s", a); 
        strncpy(cp, buf, LastArg - cp);
        cp += strlen(cp);
        while (cp < LastArg)
        strncpy(cp, buf, LastArg - cp);
        cp += strlen(cp);
        while (cp < LastArg)
@@ -898,7 +910,7 @@ daytime_stream(s, sep)              /* Return human-readable time of day */
 
        clock = time((time_t *) 0);
 
 
        clock = time((time_t *) 0);
 
-       sprintf(buffer, "%.24s\r\n", ctime(&clock));
+       (void) sprintf(buffer, "%.24s\r\n", ctime(&clock));
        (void) write(s, buffer, strlen(buffer));
 }
 
        (void) write(s, buffer, strlen(buffer));
 }
 
@@ -918,7 +930,7 @@ daytime_dg(s, sep)          /* Return human-readable time of day */
        size = sizeof(sa);
        if (recvfrom(s, buffer, sizeof(buffer), 0, &sa, &size) < 0)
                return;
        size = sizeof(sa);
        if (recvfrom(s, buffer, sizeof(buffer), 0, &sa, &size) < 0)
                return;
-       sprintf(buffer, "%.24s\r\n", ctime(&clock));
+       (void) sprintf(buffer, "%.24s\r\n", ctime(&clock));
        (void) sendto(s, buffer, strlen(buffer), 0, &sa, sizeof(sa));
 }
 
        (void) sendto(s, buffer, strlen(buffer), 0, &sa, sizeof(sa));
 }