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