bug fixes and changes from Rick Adams
[unix-history] / usr / src / usr.bin / uucp / shio.c
index 4c09e3f..1ef80a9 100644 (file)
@@ -1,11 +1,10 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)shio.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)shio.c     5.2 (Berkeley) %G%";
 #endif
 
 #include "uucp.h"
 #include <signal.h>
 
 #endif
 
 #include "uucp.h"
 #include <signal.h>
 
-
 /*******
  *     shio(cmd, fi, fo, user) execute shell of command with
  *     char *cmd, *fi, *fo;    fi and fo as standard input/output
 /*******
  *     shio(cmd, fi, fo, user) execute shell of command with
  *     char *cmd, *fi, *fo;    fi and fo as standard input/output
@@ -22,13 +21,17 @@ char *cmd, *fi, *fo, *user;
        int status, f;
        int uid, pid, ret;
        char path[MAXFULLNAME];
        int status, f;
        int uid, pid, ret;
        char path[MAXFULLNAME];
+       extern int errno;
 
        if (fi == NULL)
 
        if (fi == NULL)
-               fi = "/dev/null";
+               fi = DEVNULL;
        if (fo == NULL)
        if (fo == NULL)
-               fo = "/dev/null";
+               fo = DEVNULL;
 
        DEBUG(3, "shio - %s\n", cmd);
 
        DEBUG(3, "shio - %s\n", cmd);
+#ifdef SIGCHLD
+       signal(SIGCHLD, SIG_IGN);
+#endif SIGCHLD
        if ((pid = fork()) == 0) {
                signal(SIGINT, SIG_IGN);
                signal(SIGHUP, SIG_IGN);
        if ((pid = fork()) == 0) {
                signal(SIGINT, SIG_IGN);
                signal(SIGHUP, SIG_IGN);
@@ -37,21 +40,25 @@ char *cmd, *fi, *fo, *user;
                close(Ifn);
                close(Ofn);
                close(0);
                close(Ifn);
                close(Ofn);
                close(0);
-               if (user == NULL
-               || (gninfo(user, &uid, path) != 0)
-               || setuid(uid))
+               if (user == NULL || (gninfo(user, &uid, path) != 0)
+                       || setuid(uid))
                        setuid(getuid());
                f = open(subfile(fi), 0);
                        setuid(getuid());
                f = open(subfile(fi), 0);
-               if (f != 0)
-                       exit(f);
+               if (f != 0) {
+                       logent(fi, "CAN'T READ");
+                       exit(-errno);
+               }
                close(1);
                f = creat(subfile(fo), 0666);
                close(1);
                f = creat(subfile(fo), 0666);
-               if (f != 1)
-                       exit(f);
+               if (f != 1) {
+                       logent(fo, "CAN'T WRITE");
+                       exit(-errno);
+               }
                execl(SHELL, "sh", "-c", cmd, (char *)0);
                execl(SHELL, "sh", "-c", cmd, (char *)0);
-               exit(100);
+               exit(100+errno);
        }
        }
-       while ((ret = wait(&status)) != pid && ret != -1);
+       while ((ret = wait(&status)) != pid && ret != -1)
+               ;
        DEBUG(3, "status %d\n", status);
        DEBUG(3, "status %d\n", status);
-       return(status);
+       return status;
 }
 }