1: #ifndef lint 2: static char sccsid[] = "@(#)systat.c 5.4 (Berkeley) 6/23/85"; 3: #endif 4: 5: #include "uucp.h" 6: 7: #define STATNAME(f, n) sprintf(f, "%s/%s/%s", Spool, "STST", n) 8: #define S_SIZE 100 9: 10: /*LINTLIBRARY*/ 11: 12: /* 13: * make system status entry 14: * return codes: none 15: */ 16: systat(name, type, text) 17: char *name, *text; 18: int type; 19: { 20: char filename[MAXFULLNAME], line[S_SIZE]; 21: int count, oldtype; 22: register FILE *fp; 23: time_t prestime, rtry; 24: 25: if (type == 0) 26: return; 27: line[0] = '\0'; 28: time(&prestime); 29: count = 0; 30: STATNAME(filename, name); 31: 32: fp = fopen(filename, "r"); 33: if (fp != NULL) { 34: fgets(line, S_SIZE, fp); 35: sscanf(line, "%d %d", &oldtype, &count); 36: if (count <= 0) 37: count = 0; 38: fclose(fp); 39: /* If merely 'wrong time', don't change existing STST */ 40: if (type == SS_WRONGTIME && oldtype != SS_INPROGRESS) 41: return; 42: } 43: 44: rtry = Retrytime; 45: /* if failures repeat, don't try so often, 46: * to forstall a 'MAX RECALLS' situation. 47: */ 48: if (type == SS_FAIL) { 49: count++; 50: if (count > 5) { 51: rtry = rtry * (count-5); 52: if (rtry > ONEDAY/2) 53: rtry = ONEDAY/2; 54: } 55: } 56: 57: 58: #ifdef VMS 59: unlink(filename); 60: #endif VMS 61: fp = fopen(filename, "w"); 62: ASSERT(fp != NULL, "SYSTAT OPEN FAIL", filename, 0); 63: fprintf(fp, "%d %d %ld %ld %s %s\n", type, count, prestime, rtry, text, name); 64: fclose(fp); 65: return; 66: } 67: 68: /*** 69: * rmstat(name) remove system status entry 70: * char *name; 71: * 72: * return codes: none 73: */ 74: 75: rmstat(name) 76: char *name; 77: { 78: char filename[MAXFULLNAME]; 79: 80: STATNAME(filename, name); 81: unlink(filename); 82: } 83: 84: /* 85: * check system status for call 86: * 87: * return codes 0 - ok | >0 system status 88: */ 89: 90: callok(name) 91: char *name; 92: { 93: char filename[MAXFULLNAME], line[S_SIZE]; 94: register FILE *fp; 95: time_t lasttime, prestime, retrytime; 96: long t1, t2; 97: int count, type; 98: 99: STATNAME(filename, name); 100: fp = fopen(filename, "r"); 101: if (fp == NULL) 102: return(SS_OK); 103: 104: if (fgets(line, S_SIZE, fp) == NULL) { 105: /* no data */ 106: fclose(fp); 107: unlink(filename); 108: return(SS_OK); 109: } 110: 111: fclose(fp); 112: time(&prestime); 113: sscanf(line, "%d%d%ld%ld", &type, &count, &t1, &t2); 114: lasttime = t1; 115: retrytime = t2; 116: 117: switch(type) { 118: case SS_BADSEQ: 119: case SS_CALLBACK: 120: case SS_NODEVICE: 121: case SS_INPROGRESS: /*let LCK take care of it */ 122: return(SS_OK); 123: 124: case SS_FAIL: 125: if (count > MAXRECALLS) { 126: logent("MAX RECALLS", "NO CALL"); 127: DEBUG(4, "MAX RECALL COUNT %d\n", count); 128: if (Debug) { 129: logent("debugging", "continuing anyway"); 130: return SS_OK; 131: } 132: return type; 133: } 134: 135: if (prestime - lasttime < retrytime) { 136: logent("RETRY TIME NOT REACHED", "NO CALL"); 137: DEBUG(4, "RETRY TIME (%ld) NOT REACHED\n", retrytime); 138: if (Debug) { 139: logent("debugging", "continuing anyway"); 140: return SS_OK; 141: } 142: return type; 143: } 144: 145: return SS_OK; 146: default: 147: return SS_OK; 148: } 149: }