|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)uusnap.c 5.9 (Berkeley) 4/5/88";
3: #endif
4:
5: /*
6: * This file contains no ATT code and is not subject to the ATT
7: * license provisions regarding redistribution.
8: * Rick Adams 2/23/88
9: */
10:
11: /*
12: * Uusnap - displays a snapshot of the uucp system.
13: * originally by RJKing WECo-MG6565 May 83
14: */
15:
16: #include "uucp.h"
17: #include <sys/stat.h>
18: #ifdef NDIR
19: #include "ndir.h"
20: #else
21: #include <sys/dir.h>
22: #endif
23: #include <ctype.h>
24:
25: #define NSYSTEM 300 /* max # of systems queued */
26:
27: #define CMDSLEN 5 /* Length of trailer */
28: #define DATALEN 5 /* Length of trailer */
29: #define XEQTLEN 5 /* Length of trailer */
30: #define NUMCTRS 3 /* # file types to count */
31: #define CMDTYPE 0 /* Index into scnt.cntr */
32: #define DATTYPE 1 /* Index into scnt.cntr */
33: #define XEQTYPE 2 /* Index into scnt.cntr */
34:
35: struct scnt { /* System count structure */
36: char name[MAXBASENAME+1]; /* Name of system */
37: short cntr[NUMCTRS]; /* Count */
38: char stst[32]; /* STST Message */
39: time_t locked; /* If LCK..sys present */
40: int st_type; /* STST Type */
41: int st_count; /* STST Count */
42: time_t st_lastime; /* STST Last time tried */
43: time_t st_retry; /* STST Secs to retry */
44: };
45:
46: int sndx; /* Number of systems */
47: struct scnt sys[NSYSTEM]; /* Systems queued */
48: int xqtisrunning = 0;
49:
50: main()
51: {
52: register int i, j, nlen = 0;
53: time_t curtime, t;
54:
55: scandir(CMDSDIR, "C.", CMDSLEN, NULL, CMDTYPE);
56: scandir(DATADIR, "D.", DATALEN, NULL, DATTYPE);
57: scandir(XEQTDIR, "X.", XEQTLEN, 'X', XEQTYPE);
58: getstst(SPOOL);
59: time(&curtime);
60: for(i=0; i<sndx; ++i)
61: if((j = strlen(sys[i].name)) > nlen)
62: nlen = j;
63: for(i=0; i<sndx; ++i) {
64: t = (sys[i].st_lastime +sys[i].st_retry) - curtime;
65:
66: /* decide if STST text is worth printing */
67: if (-t < ONEDAY*2 && sys[i].st_type == SS_WRONGTIME) {
68: sys[i].stst[0] = '\0';
69: if (sys[i].cntr[0]+sys[i].cntr[1]+sys[i].cntr[2] == 0)
70: continue; /* ignore entire line */
71: }
72:
73: printf("%-*.*s ", nlen, nlen, sys[i].name);
74: if(sys[i].cntr[CMDTYPE])
75: printf("%3.d Cmd%s ", sys[i].cntr[CMDTYPE],
76: sys[i].cntr[CMDTYPE]>1?"s":" ");
77: else
78: printf(" --- ");
79: if(sys[i].cntr[DATTYPE])
80: printf("%3.d Data ", sys[i].cntr[DATTYPE]);
81: else
82: printf(" --- ");
83: if(sys[i].cntr[XEQTYPE])
84: printf("%3.d Xqt%s ", sys[i].cntr[XEQTYPE],
85: sys[i].cntr[XEQTYPE]>1?"s":" ");
86: else
87: printf(" --- ");
88: if(*sys[i].stst == NULL || sys[i].locked > sys[i].st_lastime) {
89: if(sys[i].locked)
90: printf("LOCKED\n");
91: else
92: printf("\n");
93: continue;
94: }
95: printf("%s ", sys[i].stst);
96: /* decide if STST info is worth pursuing */
97: if (-t < ONEDAY*2 && (sys[i].st_count == 0
98: || sys[i].st_type == SS_WRONGTIME
99: || (sys[i].st_type == SS_INPROGRESS && sys[i].locked))) {
100: printf("\n");
101: continue;
102: }
103: t = (sys[i].st_lastime +sys[i].st_retry) - curtime;
104: if (-t < ONEDAY*2 && sys[i].st_type != SS_FAIL)
105: t = 0;
106:
107: if (sys[i].st_count > MAXRECALLS)
108: printf("at MAX RECALLS");
109: else if (-t >= ONEDAY*2)
110: printf("%ld days ago", (long)-t/ONEDAY);
111: else if (t <= 0)
112: printf("Retry time reached");
113: else if (t < 60)
114: printf("Retry time %ld sec%s", (long)(t%60),
115: (t%60)!=1? "s": "");
116: else
117: printf("Retry time %ld min%s", (long)(t/60),
118: (t/60)!=1? "s": "");
119: if(sys[i].st_count > 1)
120: printf(" Count: %d\n", sys[i].st_count);
121: else
122: printf("\n");
123: }
124: if (xqtisrunning)
125: printf("\nUuxqt is running\n");
126: exit(0);
127: }
128:
129: scandir(dnam, prfx, flen, fchr, type)
130: char *dnam, *prfx, fchr;
131: {
132: register struct direct *dentp;
133: register DIR *dirp;
134: register int i, fnamlen, plen;
135: char fnam[MAXNAMLEN+1];
136:
137: plen = strlen(prfx);
138: if(chdir(dnam) < 0) {
139: perror(dnam);
140: exit(1);
141: }
142: if ((dirp = opendir(".")) == NULL) {
143: perror(dnam);
144: exit(1);
145: }
146: while((dentp = readdir(dirp)) != NULL) {
147: if(*dentp->d_name == '.')
148: continue;
149: if(strncmp(dentp->d_name, prfx, plen) != SAME) {
150: fprintf(stderr, "strange file (%s) in %s\n",
151: dentp->d_name, dnam);
152: continue;
153: }
154: strcpy(fnam, &dentp->d_name[plen]);
155: fnamlen = strlen(fnam);
156: if(flen > 0) {
157: fnamlen -= flen;
158: fnam[fnamlen] = NULL;
159: fnamlen = MAXBASENAME; /* yes, after = NULL*/
160: } else {
161: for(; fnamlen>0; --fnamlen) {
162: if(fnam[fnamlen] == fchr) {
163: fnam[fnamlen] = NULL;
164: break;
165: }
166: }
167: fnamlen = MAXBASENAME;
168: }
169: for(i=0; i<sndx; ++i) {
170: if(strncmp(fnam, sys[i].name, fnamlen) == SAME) {
171: ++sys[i].cntr[type];
172: break;
173: }
174: }
175: if(i == sndx) {
176: strcpy(sys[i].name, fnam);
177: ++sys[i].cntr[type];
178: if(++sndx >= NSYSTEM) {
179: sndx = NSYSTEM-1;
180: fprintf(stderr,"Too many system names.\n");
181: }
182: }
183: }
184: closedir(dirp);
185: }
186:
187: getstst(sdir)
188: char *sdir;
189: {
190: register int i, csys;
191: register char *tp;
192: char fnam[MAXNAMLEN+1], buff[128];
193: register struct direct *dentp;
194: register DIR *dirp;
195: register FILE *st;
196: struct stat stbuf;
197: long atol();
198:
199: if (chdir(sdir) < 0) {
200: perror(sdir);
201: exit(1);
202: }
203: if ((dirp = opendir(LOCKDIR)) == NULL) {
204: perror(sdir);
205: exit(1);
206: }
207: while ((dentp = readdir(dirp)) != NULL) {
208: if (strcmp(&dentp->d_name[5], X_LOCK) == SAME) {
209: xqtisrunning++;
210: continue;
211: }
212: if(strncmp(dentp->d_name, "LCK..", 5) == SAME) {
213: if(strncmp(&dentp->d_name[5], "tty", 3) == SAME ||
214: strncmp(&dentp->d_name[5], "cul", 3) == SAME)
215: continue;
216: strcpy(fnam, dentp->d_name);
217: for(csys=0; csys<sndx; ++csys) {
218: if(strncmp(&fnam[5], sys[csys].name, SYSNSIZE)
219: == SAME)
220: break;
221: }
222: strcpy(sys[csys].name, &fnam[5]);
223: if(csys == sndx) {
224: ++sndx;
225: }
226: if (stat(fnam, &stbuf) < 0)
227: sys[csys].locked = 1;
228: else
229: sys[csys].locked = stbuf.st_mtime;
230: continue;
231: }
232: }
233: closedir(dirp);
234: if (chdir("STST") < 0) {
235: perror("STST");
236: exit(1);
237: }
238: if ((dirp = opendir(".")) == NULL) {
239: perror("STST");
240: exit(1);
241: }
242: while ((dentp = readdir(dirp)) != NULL) {
243: if(*dentp->d_name == '.')
244: continue;
245: strcpy(fnam, dentp->d_name);
246: for(csys=0; csys<sndx; ++csys) {
247: if(strncmp(fnam, sys[csys].name, SYSNSIZE) == SAME)
248: break;
249: }
250: strcpy(sys[csys].name, fnam);
251: if(csys == sndx) {
252: ++sndx;
253: }
254: if((st = fopen(fnam, "r")) == NULL) {
255: sys[csys].stst[0] = '\0';
256: continue;
257: }
258: buff[0] = '\0';
259: fgets(buff, sizeof(buff), st);
260: fclose(st);
261: if(tp = rindex(buff, ' '))
262: *tp = NULL; /* drop system name */
263: else
264: continue;
265: for(i=0, tp=buff; i<4; ++i, ++tp)
266: if((tp = index(tp, ' ')) == NULL)
267: break;
268: if(i != 4)
269: continue;
270: strncpy(sys[csys].stst, tp, sizeof(sys[csys].stst));
271: tp = buff;
272: sys[csys].st_type = atoi(tp);
273: tp = index(tp+1, ' ');
274: sys[csys].st_count = atoi(tp+1);
275: tp = index(tp+1, ' ');
276: sys[csys].st_lastime = atol(tp+1);
277: tp = index(tp+1, ' ');
278: sys[csys].st_retry = atol(tp+1);
279: }
280: }
281: /*
282: * Return the ptr in sp at which the character c appears;
283: * NULL if not found
284: */
285:
286: char *
287: index(sp, c)
288: register char *sp, c;
289: {
290: do {
291: if (*sp == c)
292: return sp;
293: } while (*sp++);
294: return NULL;
295: }
296:
297: /*
298: * Return the ptr in sp at which the character c last
299: * appears; NULL if not found
300: */
301:
302: char *
303: rindex(sp, c)
304: register char *sp, c;
305: {
306: register char *r;
307:
308: r = NULL;
309: do {
310: if (*sp == c)
311: r = sp;
312: } while (*sp++);
313: return r;
314: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.