remove backoff; DEBUG change before was wrong
[unix-history] / usr / src / libexec / rexecd / rexecd.c
index 539b036..7c826b7 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rexecd.c   4.5 82/12/25";
+static char sccsid[] = "@(#)rexecd.c   4.7 83/01/22";
 #endif
 
 #include <sys/ioctl.h>
 #endif
 
 #include <sys/ioctl.h>
@@ -21,6 +21,7 @@ struct        passwd *getpwnam();
 char   *crypt(), *rindex(), *sprintf();
 /* VARARGS 1 */
 int    error();
 char   *crypt(), *rindex(), *sprintf();
 /* VARARGS 1 */
 int    error();
+int    reapchild();
 /*
  * remote execute server:
  *     username\0
 /*
  * remote execute server:
  *     username\0
@@ -32,7 +33,6 @@ main(argc, argv)
        int argc;
        char **argv;
 {
        int argc;
        char **argv;
 {
-       union wait status;
        int f;
        struct sockaddr_in from;
        struct servent *sp;
        int f;
        struct sockaddr_in from;
        struct servent *sp;
@@ -68,12 +68,15 @@ main(argc, argv)
                perror("rexecd: bind:");
                exit(1);
        }
                perror("rexecd: bind:");
                exit(1);
        }
+       sigset(SIGCHLD, reapchild);
        listen(f, 10);
        for (;;) {
                int s, len = sizeof (from);
 
                s = accept(f, &from, &len, 0);
                if (s < 0) {
        listen(f, 10);
        for (;;) {
                int s, len = sizeof (from);
 
                s = accept(f, &from, &len, 0);
                if (s < 0) {
+                       if (errno == EINTR)
+                               continue;
                        perror("rexecd: accept");
                        sleep(1);
                        continue;
                        perror("rexecd: accept");
                        sleep(1);
                        continue;
@@ -81,11 +84,17 @@ main(argc, argv)
                if (fork() == 0)
                        doit(s, &from);
                (void) close(s);
                if (fork() == 0)
                        doit(s, &from);
                (void) close(s);
-               while (wait3(status, WNOHANG, 0) > 0)
-                       continue;
        }
 }
 
        }
 }
 
+reapchild()
+{
+       union wait status;
+
+       while (wait3(&status, WNOHANG, 0) > 0)
+               ;
+}
+
 char   username[20] = "USER=";
 char   homedir[64] = "HOME=";
 char   shell[64] = "SHELL=";
 char   username[20] = "USER=";
 char   homedir[64] = "HOME=";
 char   shell[64] = "SHELL=";
@@ -192,8 +201,7 @@ doit(f, fromp)
                                if (ready & (1<<pv[0])) {
                                        cc = read(pv[0], buf, sizeof (buf));
                                        if (cc <= 0) {
                                if (ready & (1<<pv[0])) {
                                        cc = read(pv[0], buf, sizeof (buf));
                                        if (cc <= 0) {
-                                               int done = 1+1;
-                                               ioctl(s, SIOCDONE, (char *)&done);
+                                               shutdown(s, 1+1);
                                                readfrom &= ~(1<<pv[0]);
                                        } else
                                                (void) write(s, buf, cc);
                                                readfrom &= ~(1<<pv[0]);
                                        } else
                                                (void) write(s, buf, cc);