Annotation of researchv10no/cmd/odist/ape/receive.c, revision 1.1

1.1     ! root        1: #include <stddef.h>
        !             2: #include <stdio.h>
        !             3: #include <sys/types.h>
        !             4: #include <sys/stat.h>
        !             5: #include <fcntl.h>
        !             6: #include <unistd.h>
        !             7: #include "dist.h"
        !             8: 
        !             9: void
        !            10: recvjob(void)
        !            11: {
        !            12:        char data[MAXNAME], errs[MAXNAME], mesg[MAXLINE];
        !            13:        int dfd, efd, attempt, status;
        !            14: 
        !            15:        if (!getline(mesg))
        !            16:                exit(0);
        !            17: 
        !            18:        if (sscanf(mesg, "begin job %s", data) != 1) {
        !            19:                eprintf("job header munged: mesg = %s", mesg);
        !            20:                exit(1);
        !            21:        }
        !            22: 
        !            23:        sprintf(data, "data.%d", getpid());
        !            24:        remove(data);
        !            25:        dfd = creat(data, 0600); /* ape deficiency */
        !            26:        close(dfd);
        !            27:        dfd = open(data, O_RDWR);
        !            28:        if (dfd < 0) {
        !            29:                eprintf("can't create data file %s", data);
        !            30:                exit(1);
        !            31:        }
        !            32: 
        !            33:        if (!recvfile(dfd)) {
        !            34:                remove(data);
        !            35:                eprintf("recvfile failed");
        !            36:                exit(1);
        !            37:        }
        !            38: 
        !            39:        /* see if file system permissions will likely allow inspkg to succeed */
        !            40:        lseek(dfd, 0L, 0);
        !            41:        attempt = tryperm(dfd);
        !            42:        sprintf(mesg, "client attempt=%d\n", attempt);
        !            43:        write(1, mesg, strlen(mesg));
        !            44: 
        !            45:        if (attempt) {
        !            46:                sprintf(errs, "errs.%d", getpid());
        !            47:                efd = creat(errs, 0600);        /* more ape bogosity */
        !            48:                close(efd);
        !            49:                efd = open(errs, O_RDWR);
        !            50:                if (efd < 0) {
        !            51:                        eprintf("can't create errs file %s", errs);
        !            52:                        exit(1);
        !            53:                }
        !            54: 
        !            55:                if (fork()) {
        !            56:                        status = 0xFF; /* evilly catch wait failures */
        !            57:                        wait(&status);
        !            58:                        if (status & 0xFF) {
        !            59:                                sprintf(mesg, "inspkg: exit %d\n", status & 0xFF);
        !            60:                                write(efd, mesg, strlen(mesg));
        !            61:                        }
        !            62:                } else {
        !            63:                        lseek(dfd, 0L, 0);
        !            64:                        dup2(dfd, 0);
        !            65:                        dup2(efd, 1);
        !            66:                        dup2(efd, 2);
        !            67:                        close(dfd);
        !            68:                        close(efd);
        !            69:                        execl(LDIR "/inspkg", "inspkg", 0);
        !            70:                        eprintf("can't exec inspkg");
        !            71:                        exit(1);
        !            72:                }
        !            73: 
        !            74:                lseek(efd, 0L, 0);
        !            75:                if (!sendfile(efd)) {
        !            76:                        remove(data);
        !            77:                        remove(errs);
        !            78:                        eprintf("can't send error log");
        !            79:                        exit(1);
        !            80:                }
        !            81:        }
        !            82: 
        !            83:        close(dfd);
        !            84:        remove(data);
        !            85:        close(efd);
        !            86:        remove(errs);
        !            87: }
        !            88: 
        !            89: int
        !            90: main(int argc, char *argv[])
        !            91: {
        !            92:        prog = argv[0];
        !            93:        for (;;)
        !            94:                recvjob();
        !            95: }

unix.superglobalmegacorp.com

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