Annotation of 41BSD/cmd/uucp/systat.c, revision 1.1.1.1

1.1       root        1: #include "uucp.h"
                      2: #include <sys/types.h>
                      3: 
                      4: #define STATNAME(f, n) sprintf(f, "%s/%s.%.7s", Spool, "STST", n)
                      5: #define S_SIZE 100
                      6: 
                      7: /*******
                      8:  *     systat(name, type, text)        make system status entry
                      9:  *     char *name, *text;
                     10:  *     int type.
                     11:  *
                     12:  *     return codes:  none
                     13:  */
                     14: 
                     15: systat(name, type, text)
                     16: char *name, *text;
                     17: int type;
                     18: {
                     19:        char filename[MAXFULLNAME], line[S_SIZE];
                     20:        int count;
                     21:        FILE *fp;
                     22:        time_t prestime;
                     23: 
                     24:        if (type == 0)
                     25:                return;
                     26:        line[0] = '\0';
                     27:        time(&prestime);
                     28:        count = 0;
                     29:        STATNAME(filename, name);
                     30: 
                     31:        fp = fopen(filename, "r");
                     32:        if (fp != NULL) {
                     33:                fgets(line, S_SIZE, fp);
                     34:                sscanf(&line[2], "%d", &count);
                     35:                if (count <= 0)
                     36:                        count = 0;
                     37:                fclose(fp);
                     38:        }
                     39: 
                     40:        if (type == SS_FAIL)
                     41:                count++;
                     42: 
                     43:        fp = fopen(filename, "w");
                     44:        ASSERT(fp != NULL, "SYSTAT OPEN FAIL %s", "");
                     45:        chmod(filename, 0666);
                     46:        fprintf(fp, "%d %d %D %s %s\n", type, count, prestime, text, name);
                     47:        fclose(fp);
                     48:        return;
                     49: }
                     50: 
                     51: /***
                     52:  *     rmstat(name)    remove system status entry
                     53:  *     char *name;
                     54:  *
                     55:  *     return codes:  none
                     56:  */
                     57: 
                     58: rmstat(name)
                     59: char *name;
                     60: {
                     61:        char filename[MAXFULLNAME];
                     62: 
                     63:        STATNAME(filename, name);
                     64:        unlink(filename);
                     65: }
                     66: 
                     67: /***
                     68:  *     callok(name)    check system status for call
                     69:  *     char *name;
                     70:  *
                     71:  *     return codes  0 - ok | >0 system status
                     72:  */
                     73: 
                     74: callok(name)
                     75: char *name;
                     76: {
                     77:        char filename[MAXFULLNAME], line[S_SIZE];
                     78:        FILE *fp;
                     79:        time_t lasttime, prestime;
                     80:        int count, type;
                     81: 
                     82:        STATNAME(filename, name);
                     83:        fp = fopen(filename, "r");
                     84:        if (fp == NULL)
                     85:                return(SS_OK);
                     86: 
                     87:        if (fgets(line, S_SIZE, fp) == NULL) {
                     88:                /*  no data  */
                     89:                fclose(fp);
                     90:                unlink(filename);
                     91:                return(SS_OK);
                     92:        }
                     93: 
                     94:        fclose(fp);
                     95:        time(&prestime);
                     96:        sscanf(line, "%d%d%D", &type, &count, &lasttime);
                     97: 
                     98:        switch(type) {
                     99:        case SS_BADSEQ:
                    100:        case SS_CALLBACK:
                    101:                return(SS_OK);
                    102:        case SS_NODEVICE:
                    103:                return(SS_OK);
                    104: 
                    105:        case SS_INPROGRESS:
                    106:                if (prestime - lasttime < INPROGTIME) {
                    107:                        DEBUG(4, "CALL IN PROGRESS %s\n", "");
                    108:                        return(type);
                    109:                }
                    110:                else
                    111:                        return(SS_OK);
                    112: 
                    113: 
                    114:        case SS_FAIL:
                    115:                if (count > MAXRECALLS) {
                    116:                        logent("MAX RECALLS", "NO CALL");
                    117:                        DEBUG(4, "MAX RECALL COUNT %d\n", count);
                    118:                        return(type);
                    119:                }
                    120: 
                    121:                if (prestime - lasttime < RETRYTIME) {
                    122:                        logent("RETRY TIME NOT REACHED", "NO CALL");
                    123:                        DEBUG(4, "RETRY TIME (%d) NOT REACHED\n", RETRYTIME);
                    124:                        return(type);
                    125:                }
                    126: 
                    127:                return(SS_OK);
                    128:        default:
                    129:                return(SS_OK);
                    130:        }
                    131: }

unix.superglobalmegacorp.com

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