|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)systat.c 5.5 (Berkeley) 4/5/88";
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: if (fp == NULL) {
63: syslog(LOG_ERR, "fopen(%s) failed: %m", filename);
64: cleanup(FAIL);
65: }
66: fprintf(fp, "%d %d %ld %ld %s %s\n", type, count, prestime, rtry, text, name);
67: fclose(fp);
68: }
69:
70: /*
71: * remove system status entry
72: *
73: * return codes: none
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: callok(name)
90: char *name;
91: {
92: char filename[MAXFULLNAME], line[S_SIZE];
93: register FILE *fp;
94: time_t lasttime, prestime, retrytime;
95: long t1, t2;
96: int count, type;
97:
98: STATNAME(filename, name);
99: fp = fopen(filename, "r");
100: if (fp == NULL)
101: return(SS_OK);
102:
103: if (fgets(line, S_SIZE, fp) == NULL) {
104: /* no data */
105: fclose(fp);
106: unlink(filename);
107: return(SS_OK);
108: }
109:
110: fclose(fp);
111: time(&prestime);
112: sscanf(line, "%d%d%ld%ld", &type, &count, &t1, &t2);
113: lasttime = t1;
114: retrytime = t2;
115:
116: switch(type) {
117: case SS_BADSEQ:
118: case SS_CALLBACK:
119: case SS_NODEVICE:
120: case SS_INPROGRESS: /*let LCK take care of it */
121: return(SS_OK);
122:
123: case SS_FAIL:
124: if (count > MAXRECALLS) {
125: logent("MAX RECALLS", "NO CALL");
126: DEBUG(4, "MAX RECALL COUNT %d\n", count);
127: if (Debug) {
128: logent("debugging", "continuing anyway");
129: return SS_OK;
130: }
131: return type;
132: }
133:
134: if (prestime - lasttime < retrytime) {
135: logent("RETRY TIME NOT REACHED", "NO CALL");
136: DEBUG(4, "RETRY TIME (%ld) NOT REACHED\n", retrytime);
137: if (Debug) {
138: logent("debugging", "continuing anyway");
139: return SS_OK;
140: }
141: return type;
142: }
143:
144: return SS_OK;
145: default:
146: return SS_OK;
147: }
148: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.