Annotation of researchv10no/cmd/lp/ipcopen.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <string.h>
        !             3: #include <signal.h>
        !             4: #if research
        !             5: #include <ipc.h>
        !             6: #include <sys/ttyio.h>
        !             7: #endif
        !             8: 
        !             9: int ppid;
        !            10: void abortpass();
        !            11: char * ipcpath();
        !            12: 
        !            13: /*
        !            14:  *  Connect to given datakit port
        !            15:  */
        !            16: main(argc, argv)
        !            17:        char *argv[];
        !            18: {
        !            19:        int gatefd;
        !            20:        int ppid, cpid;
        !            21:        char *cp;
        !            22: 
        !            23:        if (argc != 4) {
        !            24:                fprintf(stderr, "usage: %s destination network service\n", argv[0]);
        !            25:                exit(1);
        !            26:        }
        !            27:        if ((gatefd = ipcopen((cp = ipcpath(argv[1], argv[2], argv[3])), "heavy tcphup hup")) < 0){
        !            28: #if research
        !            29:                fprintf(stderr, "ipcopen(%s):%s\n", cp, errstr);
        !            30: #endif
        !            31:                exit(2);
        !            32:        }
        !            33: 
        !            34:        /*
        !            35:         * Initialize the input fd, and copy bytes.
        !            36:         */
        !            37: 
        !            38:        ppid = getpid();
        !            39:        switch(cpid = fork()){
        !            40:        case -1:
        !            41:                perror("fork error");
        !            42:                exit(10);
        !            43:        case 0:
        !            44:                close(0);
        !            45:                pass(gatefd, 1);        /* child - from remote */
        !            46:                close(1);
        !            47: #if !research
        !            48:                shutdown(gatefd, 0);
        !            49: #endif
        !            50:                close(gatefd);
        !            51: /*             fprintf(stderr, "from remote - exiting\n"); */
        !            52:                exit(0);
        !            53:        default:
        !            54:                close(1);
        !            55:                pass(0, gatefd);        /* parent - to remote */
        !            56:                close(0);
        !            57: #if !research
        !            58:                shutdown(gatefd, 1);
        !            59: #endif
        !            60:                close(gatefd);
        !            61: /*             fprintf(stderr, "to remote - exiting\n"); */
        !            62:                while(wait(0) != cpid);
        !            63:                exit(0);
        !            64:        }
        !            65: }
        !            66: 
        !            67: void
        !            68: rdtimout()
        !            69: {
        !            70: /*     fprintf(stderr, "read timeout\n"); */
        !            71:        exit(0);
        !            72: }
        !            73: 
        !            74: #define RDTIMOUT 10
        !            75: #define SIGALRM 14
        !            76: 
        !            77: pass(from, to)
        !            78:        int from, to;
        !            79: {
        !            80:        char buf[1024];
        !            81:        int n; 
        !            82: 
        !            83:        signal(SIGALRM, rdtimout);
        !            84:        while (alarm(RDTIMOUT),((n=read(from, buf, sizeof(buf))) > 0)) {
        !            85:                if (write(to, buf, n)!=n) {
        !            86:                        perror("pass write error");
        !            87:                        exit(6);
        !            88:                }
        !            89:        }
        !            90:        alarm(0);
        !            91: }

unix.superglobalmegacorp.com

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