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

1.1     ! root        1: #
        !             2: /*
        !             3:  * dpd -- data-phone daemon dispatcher using spider
        !             4:  *
        !             5:  */
        !             6: 
        !             7: #include       <errno.h>
        !             8: 
        !             9: #define        SPIDER  1
        !            10: #define        PHONE   0
        !            11: #define        LPD     0
        !            12: #define        FGET    0
        !            13: 
        !            14: #define        TIMEOUT 100
        !            15: 
        !            16: char   dname[] = "DPDS";
        !            17: char   dpd[]   = "/usr/spool/dpd";
        !            18: char   dfname[30] = "/usr/spool/dpd/";
        !            19: char   lock[]  = "/usr/spool/dpd/lock";
        !            20: char   error[] = "/usr/spool/dpd/errors";
        !            21: 
        !            22: #include       "daemon.c"
        !            23: #include       "gcos.c"
        !            24: 
        !            25: /* nak codes --
        !            26:  * i illegal
        !            27:  * b dest busy
        !            28:  * s illegal gcos command
        !            29:  * g gcos down/no resp
        !            30:  */
        !            31: #define        SETSIG  0
        !            32: #define        GETSIG  1
        !            33: #define        GETCHN  2
        !            34: #define        GETTRB  3
        !            35: #define        SETEOF  4
        !            36: #define        CLREOF  5
        !            37: 
        !            38: int    COMM[]  = {3};
        !            39: int    DATA[]  = {1};
        !            40: int    SPEOF[] = {2};
        !            41: int    TERM[]  = {4};
        !            42: 
        !            43: #define        LIDMES  9
        !            44: char   idmes[LIDMES+1] = "gXXrxxxxx";
        !            45: char   sndev[] = "/dev/tiu/d2";
        !            46: 
        !            47: FILE   *cfb = NULL;            /*data file*/
        !            48: char   ibuf[64];
        !            49: int    snf = -1;       /*spider device*/
        !            50: int    rathole[1];
        !            51: int    errno;
        !            52: 
        !            53: dem_con()
        !            54: {
        !            55:        return(0);
        !            56: }
        !            57: 
        !            58: dem_dis()
        !            59: {
        !            60:        FCLOSE(dfb);
        !            61:        FCLOSE(cfb);
        !            62:        if(snf >= 0){
        !            63:                close(snf);
        !            64:                snf = -1;
        !            65:        }
        !            66: }
        !            67: 
        !            68: dem_open(file)
        !            69: char   *file;
        !            70: {
        !            71:        static lastbad, badcount;
        !            72:        int badexit();
        !            73: 
        !            74:        signal(SIGALRM, badexit);
        !            75: /*
        !            76:  * Only allow 30 seconds to open file.
        !            77:  */
        !            78:        alarm(30);
        !            79:        if ((snf = open(sndev, 2)) < 0) {
        !            80:                if (errno == EBUSY)
        !            81:                        trouble("NG: Channel busy          ");
        !            82:                else {
        !            83:                        retcode = TIMEOUT;
        !            84:                        trouble("NG: Can't find TIU file   ");
        !            85:                }
        !            86:        }
        !            87:        snstat(snf, rathole, GETTRB);
        !            88:        snstat(snf, COMM, SETSIG);
        !            89:        idmes[1] = spider_id[0];
        !            90:        idmes[2] = spider_id[1];
        !            91:        snwrite(idmes, LIDMES);
        !            92:        if (read(snf, ibuf, 10) <= 0) {
        !            93:                snstat(snf, rathole, GETTRB);
        !            94:                trouble("read err %d %d, pid %8s", errno, rathole[0]&0377,
        !            95:                        file+LPID);
        !            96:        }
        !            97:        if (ibuf[0]!='+') {
        !            98:                if (lastbad=='B' && ibuf[0]=='B' && badcount>=4){
        !            99:                        /*reboot PDP8 on 4th consecutive
        !           100:                          busy response (~1+2+4+8=15 minutes)
        !           101:                        */
        !           102:                        lastbad=badcount=0; /*forget we've had busies*/
        !           103:                        waittm=60;      /*setup for retry after one minute*/
        !           104:                        snstat(snf, COMM, SETSIG);
        !           105:                        snwrite("b", 1);
        !           106:                        trouble("Another NAK:B, reboot     ");
        !           107:                }
        !           108:                lastbad = ibuf[0];
        !           109:                badcount = lastbad=='B'?++badcount:0;
        !           110:                trouble("NAK:%-22c", ibuf[0]);
        !           111:        }
        !           112:        lastbad=badcount=0;
        !           113:        snumb = &ibuf[1];
        !           114:        snumb[5] = 0;
        !           115: }
        !           116: 
        !           117: get_snumb()
        !           118: {
        !           119: }
        !           120: 
        !           121: lwrite()
        !           122: {
        !           123:        setcom('h');
        !           124:        line[linel] = '\n';
        !           125:        snwrite(&line[1], linel);
        !           126: }
        !           127: 
        !           128: dem_close()
        !           129: {
        !           130:        snstat(snf, COMM, SETSIG);
        !           131:        snwrite("t\001", 2);
        !           132:        snstat(snf, TERM, SETSIG);
        !           133:        snwrite((char *)0, 0);
        !           134: /*
        !           135:        read(snf, ibuf, 10);
        !           136: */
        !           137: }
        !           138: 
        !           139: sascii(fff)
        !           140: {
        !           141:        register n;
        !           142:        static char buf[BUFSIZ];
        !           143: 
        !           144:        if((cfb = fopen(&line[1], "r")) == NULL){
        !           145:                logerr("Can't open %s", &line[1]);
        !           146:                return(0);
        !           147:        }
        !           148:        setcom('a');
        !           149:        snstat(snf, DATA, SETSIG);
        !           150:        if (fff)
        !           151:                snwrite(&ff, 1);
        !           152:        while ((n=fread(buf, 1, BUFSIZ, cfb))==BUFSIZ) {
        !           153:                snwrite(buf, BUFSIZ);
        !           154:        }
        !           155:        if (n<0)
        !           156:                n = 0;
        !           157:        snstat(snf, SPEOF, SETSIG);
        !           158:        snwrite(buf, n);
        !           159:        FCLOSE(cfb);
        !           160:        return(0);
        !           161: }
        !           162: 
        !           163: setcom(c)
        !           164: char   c;
        !           165: {
        !           166:        snstat(snf, COMM, SETSIG);
        !           167:        snwrite(&c, 1);
        !           168:        snstat(snf, SPEOF, SETSIG);
        !           169: }
        !           170: 
        !           171: snwrite(b, n)
        !           172: char   *b;
        !           173: int    n;
        !           174: {
        !           175:        int ercode;
        !           176:        register nw;
        !           177: 
        !           178:        alarm(30);
        !           179:        nw = write(snf, b, n);
        !           180:        ercode = 0;
        !           181:        snstat(snf, &ercode, GETTRB);
        !           182:        if (nw!=n || ercode) {
        !           183:                if (ercode >= 0100)
        !           184:                        retcode = TIMEOUT;
        !           185:                trouble("wrote %d sent %d err %o, %s",
        !           186:                        n, nw, ercode&0377, dfname+LPID);
        !           187:        }
        !           188:        snsum += n;
        !           189: }
        !           190: 
        !           191: /* VARARGS */
        !           192: trouble(s, a1, a2, a3, a4)
        !           193: char   *s;
        !           194: int    a1, a2, a3, a4;
        !           195: {
        !           196:        alarm(0);
        !           197:        sleep(8); /* temporary to overcome timing problem in pdp8 ADH */
        !           198:        dem_dis();
        !           199:        logerr(s, a1, a2, a3, a4);
        !           200:        sleep(5);
        !           201:        if (retcode==TIMEOUT) {
        !           202:                /*
        !           203:                 * Give up.
        !           204:                 */
        !           205:                unlink(lock);
        !           206:                execl("/usr/lib/odpd", "odpd", (char *)0);
        !           207:                execl("/etc/odpd", "odpd", (char *)0);
        !           208:                execl("/usr/lib/dpd", "dpd", (char *)0);
        !           209:                execl("/etc/dpd", "dpd", (char *)0);
        !           210:                logerr("Can't find dpd.");
        !           211:                exit(1);
        !           212:        }
        !           213:        longjmp(env, 1);
        !           214: }
        !           215: 
        !           216: badexit()
        !           217: {
        !           218:        if (waittm >= 2*60) {   /* Second try */
        !           219:                retcode = TIMEOUT;
        !           220:                trouble("Another timeout, I give up");
        !           221:        }
        !           222:        trouble("Timed out.                ");
        !           223: }

unix.superglobalmegacorp.com

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