Annotation of researchv10no/cmd/uucp/shio.c, revision 1.1

1.1     ! root        1: /*     /sccs/src/cmd/uucp/s.shio.c
        !             2:        shio.c  1.1     8/30/84 17:37:41
        !             3: */
        !             4: #include "uucp.h"
        !             5: 
        !             6: VERSION(@(#)shio.c     1.1);
        !             7: 
        !             8: /*
        !             9:  * use shell to execute command with
        !            10:  * fi, fo, and fe as standard input/output/error
        !            11:  *     cmd     -> command to execute
        !            12:  *     fi      -> standard input
        !            13:  *     fo      -> standard output
        !            14:  *     fe      -> standard error
        !            15:  * return:
        !            16:  *     0               -> success 
        !            17:  *     non zero        -> failure  -  status from child
        !            18:                        (Note - -1 means the fork failed)
        !            19:  */
        !            20: shio(cmd, fi, fo, fe)
        !            21: char *cmd, *fi, *fo, *fe;
        !            22: {
        !            23:        register int pid, ret;
        !            24:        int status;
        !            25: 
        !            26:        if (fi == NULL)
        !            27:                fi = "/dev/null";
        !            28:        if (fo == NULL)
        !            29:                fo = "/dev/null";
        !            30:        if (fe == NULL)
        !            31:                fe = "/dev/null";
        !            32: 
        !            33:        DEBUG(3, "shio - %s\n", cmd);
        !            34:        if ((pid = fork()) == 0) {
        !            35:                (void) signal(SIGINT, SIG_IGN);
        !            36:                (void) signal(SIGHUP, SIG_IGN);
        !            37:                (void) signal(SIGQUIT, SIG_IGN);
        !            38:                closelog();
        !            39:                (void) close(Ifn);      /* close connection fd's */
        !            40:                (void) close(Ofn);
        !            41:                (void) close(0);        /* get stdin from file fi */
        !            42:                if (open(fi, 0) != 0)
        !            43:                        exit(errno);
        !            44:                (void) close(1);        /* divert stdout to fo */
        !            45:                if (creat(fo, 0666) != 1)
        !            46:                        exit(errno);
        !            47:                (void) close(2);        /* divert stderr to fe */
        !            48:                if (creat(fe, 0666) != 2)
        !            49:                        exit(errno);
        !            50: #ifdef V8
        !            51:                close(3);               /* get rid of /dev/tty */
        !            52: #endif
        !            53:                (void) execle(SHELL, "sh", "-c", cmd, 0, Env);
        !            54:                exit(100);
        !            55:        }
        !            56: 
        !            57:        /*
        !            58:         * the status returned from wait can never be -1
        !            59:         * see man page wait(2)
        !            60:         * So we use the -1 value to indicate fork failed
        !            61:         */
        !            62:        if (pid == -1)
        !            63:                return(-1);
        !            64:        
        !            65: 
        !            66:        while ((ret = wait(&status)) != pid && ret != -1);
        !            67:        DEBUG(3, "status %d\n", status);
        !            68:        return(status);
        !            69: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.