Annotation of researchv10no/cmd/spitbol/ospipe.c, revision 1.1.1.1

1.1       root        1: 
                      2: 
                      3: /*
                      4:        ospipe( ioptr ) builds a pipe for the input association.
                      5:        the value returned is the file descriptor.
                      6: */
                      7: 
                      8: #include "spitblks.h"
                      9: #include "spitio.h"
                     10: 
                     11: ospipe( ioptr )
                     12: 
                     13: struct ioblk   *ioptr;
                     14: 
                     15: {
                     16:        int     childfd, childpid, fd[2], len, parentfd, status;
                     17:        char    *cp;
                     18:        struct  scblk   *scptr;
                     19: 
                     20:        if ( (status = pipe( fd )) < 0 )
                     21:                return -1;
                     22: 
                     23:        if ( ioptr -> flg & IO_INP ) {
                     24:                parentfd = fd[0];
                     25:                childfd  = fd[1];
                     26:        } else {
                     27:                parentfd = fd[1];
                     28:                childfd  = fd[0];
                     29:        }
                     30: 
                     31:        switch ( childpid = fork() ) {
                     32: 
                     33:                case -1:
                     34:                        close( parentfd );
                     35:                        close( childfd );
                     36:                        parentfd = -1;
                     37:                        break;
                     38: 
                     39:                case 0:  
                     40:                        if ( ioptr -> flg & IO_INP ) 
                     41:                                close( 1 );
                     42:                        else
                     43:                                close( 0 );
                     44:                        dup( childfd );
                     45:                        for ( childfd = 3; childfd <= 32; close( childfd++ ));
                     46:                        scptr = ioptr -> fnm;
                     47:                        cp    = scptr -> str;
                     48:                        len   = lenfnm( scptr );
                     49:                        cp[len] = '\0';
                     50:                        if ( cp[len - 1] == cp[1] )
                     51:                                cp[len - 1] = ' ';
                     52:                        cp[1] = ' ';
                     53:                        cp[0] = ' ';
                     54:                        execl( "/bin/sh","sh","-c",cp,0 );
                     55:                        break;
                     56: 
                     57:                default:
                     58:                        ioptr -> pid = childpid;
                     59:                        close( childfd );
                     60:                        break;
                     61:        }
                     62: 
                     63:        return parentfd;
                     64: 
                     65: }      
                     66: 

unix.superglobalmegacorp.com

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