Annotation of researchv10no/cmd/daemon/spider.fgd.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * I/O routines to retrieve files from GCOS via Spider
        !             3:  */
        !             4: 
        !             5: #include       <stdio.h>
        !             6: 
        !             7: #define        SPIDER  1
        !             8: #define        PHONE   0
        !             9: #define        LPD     0
        !            10: #define        FGET    1
        !            11: 
        !            12: char   dname[] = "FGETS";
        !            13: 
        !            14: #include       "gcos.c"
        !            15: #include       "fgdemon.c"
        !            16: 
        !            17: /* nak codes --
        !            18:  * I illegal
        !            19:  * B dest busy
        !            20:  * S illegal gcos command
        !            21:  * G gcos down/no resp
        !            22:  */
        !            23: 
        !            24: #define        SETSIG  0
        !            25: #define        GETSIG  1
        !            26: #define        GETCHN  2
        !            27: #define        GETTRB  3
        !            28: #define        SETEOF  4
        !            29: #define        CLREOF  5
        !            30: 
        !            31: int    COMM[]  = {3};
        !            32: int    DATA[]  = {1};
        !            33: int    SPEOF[] = {2};
        !            34: int    TERM[]  = {4};
        !            35: 
        !            36: char   sndev[] = "/dev/tiu/d2";
        !            37: #define        LIDMES  4
        !            38: char   idmes[LIDMES+1] = "gXXa";
        !            39: 
        !            40: int    sfd = -1;       /*spider file*/
        !            41: int    rathole[1];
        !            42: int    errno;
        !            43: int    ioerr;
        !            44: char   sbuf[BUFSIZ];
        !            45: 
        !            46: fgd_read()
        !            47: {
        !            48:        int nr, i;
        !            49:        extern hungup();
        !            50: 
        !            51:        /* allow 50 seconds to open the file and get going */
        !            52: 
        !            53:        signal(SIGALRM, hungup);
        !            54:        alarm(50);
        !            55: 
        !            56:        if ((sfd = open(sndev, 2)) < 0) {
        !            57:                ioerr = errno;
        !            58:                if (ioerr == EBUSY)
        !            59:                        trouble(OKTRB, 10, "unix chan bsy");
        !            60:                else
        !            61:                        trouble(FATTRB, 0, "TIU down %d, 201 used", ioerr);
        !            62:                }
        !            63: 
        !            64:        snstat(sfd, rathole, GETTRB);
        !            65:        snstat(sfd, COMM, SETSIG);
        !            66: 
        !            67:        idmes[1] = fget_id[0];
        !            68:        idmes[2] = fget_id[1];
        !            69:        if (nr = write(sfd, idmes, LIDMES) != LIDMES) {
        !            70:                if((nr=write(sfd,idmes,LIDMES))!=LIDMES){  /*try once again*/
        !            71:                    snstat(sfd, rathole, GETTRB);
        !            72:                    trouble(BADTRB, 20, "wrote 4, sent %d, error %o, 201 used",
        !            73:                      nr,rathole[0]&0377);
        !            74:                }
        !            75:        }
        !            76: 
        !            77: #ifdef DEBUG
        !            78:        fprintf(stderr, "sent %s\n", idmes); /* PRINTF */
        !            79: #endif
        !            80: 
        !            81:        if (read(sfd, sbuf, BUFSIZ) <= 0) {
        !            82:                ioerr = errno;
        !            83:                snstat(sfd, rathole, GETTRB);
        !            84:                trouble(BADTRB, 20, "read1 err %d tbyte %o, 201 used", ioerr, rathole[0]&0377);
        !            85:                }
        !            86: 
        !            87: #ifdef DEBUG
        !            88:        fprintf(stderr, "acknowledgement: %c\n", sbuf[0]); /* PRINTF */
        !            89: #endif
        !            90: 
        !            91:        if (sbuf[0] != '+') {
        !            92:                if (sbuf[0] == 'B')
        !            93:                        trouble(OKTRB, 10, "pdp8 busy    ");
        !            94: 
        !            95:                if (sbuf[0] == 'G')
        !            96:                        trouble(OKTRB, -120, "gcos down");
        !            97: 
        !            98:                trouble(FATTRB, 0, "nak %c, 201 used", sbuf[0]);
        !            99: 
        !           100:                }
        !           101: 
        !           102:        while ( (nr = read(sfd, sbuf, BUFSIZ)) > 0 ) {
        !           103: 
        !           104:            alarm(240);
        !           105:                
        !           106: #ifdef DEBUG
        !           107:            fprintf(stderr, "chars read = %d\n", nr); /* PRINTF */
        !           108: #endif
        !           109:            for ( i = 0; i < nr; i += sbuf[i+1]+2 ) {
        !           110: 
        !           111: #ifdef DEBUG
        !           112:                /* fprintf(stderr, "sbuf[i], sbuf[i+1] = %d %d\n",
        !           113:                        sbuf[i],sbuf[i+1]); /* PRINTF */
        !           114: #endif
        !           115:                switch ( sbuf[i] ) {
        !           116: 
        !           117:                    case 0:
        !           118:                        (*output)(&sbuf[i+2], sbuf[i+1]);
        !           119:                        break;
        !           120: 
        !           121:                    case 1: 
        !           122:                    case 2:
        !           123: #ifdef DEBUG
        !           124:                        sbuf[i+sbuf[i+1]+1] = '\0'; /* PRINTF */
        !           125:                        fprintf(stderr, "misc card - %s\n", &sbuf[i+2]); /* PRINTF */
        !           126: #endif
        !           127:                        output = ignore;
        !           128:                        break;
        !           129: 
        !           130:                    case 3:
        !           131: #ifdef DEBUG
        !           132:                        fprintf(stderr, "binary card - %o\n",sbuf[i+2]); /* PRINTF */
        !           133: #endif
        !           134:                        if (((sbuf[i+2]&0377) == 0377)
        !           135:                           && ((sbuf[i+3]&0377) == 0360)) endfile();
        !           136:                        else output = ignore;
        !           137:                            break;
        !           138: 
        !           139:                    default:
        !           140:                        if((tfd = fopen(badbuf, "w")) != NULL){
        !           141:                                fwrite(sbuf, 1, nr, tfd);
        !           142:                                FCLOSE(tfd);
        !           143:                        }
        !           144:                        trouble(FATTRB, 0, "bad record type %d, 201 used", sbuf[i]);
        !           145: 
        !           146:                }
        !           147: 
        !           148:            }
        !           149: 
        !           150:        }
        !           151: 
        !           152:        if (nr < 0) {
        !           153:                ioerr = errno;
        !           154:                snstat(sfd, rathole, GETTRB);
        !           155:                gotit = 0;
        !           156:                trouble(BADTRB, 20, "read2 err %d tbyte %o, 201 used", ioerr, rathole[0]&0377);
        !           157:                }
        !           158: 
        !           159:        snstat(sfd, rathole, GETSIG);
        !           160:        if ((rathole[0]&0377) != 4)
        !           161:                trouble(FATTRB, 0, "unexpected signal byte %d, 201 used", rathole[0]&377);
        !           162: }
        !           163: 
        !           164: 
        !           165: dem_dis()
        !           166: {
        !           167:        FCLOSE(ofd);
        !           168:        FCLOSE(tfd);
        !           169:        if(sfd >= 0){
        !           170:                close(sfd);
        !           171:                sfd = -1;
        !           172:        }
        !           173: }
        !           174: 
        !           175: 
        !           176: hungup()
        !           177: {
        !           178:        trouble(BADTRB, 10, "timeout, 201 used");
        !           179: }

unix.superglobalmegacorp.com

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