BSD 4_3 release
[unix-history] / usr / src / usr.bin / uucp / uusnap.c
index 3cdd543..c06c1b5 100644 (file)
@@ -1,56 +1,40 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)uusnap.c   5.2 (Berkeley) 7/2/83";
+static char sccsid[] = "@(#)uusnap.c   5.7 (Berkeley) 10/9/85";
 #endif
 
 /*
  *     Uusnap - displays a snapshot of the uucp system.
 #endif
 
 /*
  *     Uusnap - displays a snapshot of the uucp system.
- *                                     RJKing WECo-MG6565 May 83
+ *     originally by   RJKing WECo-MG6565 May 83
  */
 
 #include "uucp.h"
  */
 
 #include "uucp.h"
-#include <sys/types.h>
 #include <sys/stat.h>
 #ifdef NDIR
 #include "ndir.h"
 #else
 #include <sys/dir.h>
 #endif
 #include <sys/stat.h>
 #ifdef NDIR
 #include "ndir.h"
 #else
 #include <sys/dir.h>
 #endif
+#include <ctype.h>
 
 #ifndef        SYSBUF
 char SYSBUF[BUFSIZ];
 #endif
 
 #define        NSYSTEM 100                             /* max # of systems queued */
 
 #ifndef        SYSBUF
 char SYSBUF[BUFSIZ];
 #endif
 
 #define        NSYSTEM 100                             /* max # of systems queued */
-#define        SPOOLDR "/usr/spool/uucp"               /* Where STST files are */
-#ifdef UUDIR
-#define        CMDSDIR "/usr/spool/uucp/C."            /* Name of commands dir */
-#define        DATADIR "/usr/spool/uucp/D."            /* Name of data directory */
-#define        XEQTDIR "/usr/spool/uucp/X."            /* Name of execute dir */
-#else
-#define        CMDSDIR "/usr/spool/uucp"               /* Name of commands dir */
-#define        DATADIR "/usr/spool/uucp"               /* Name of data directory */
-#define        XEQTDIR "/usr/spool/uucp"               /* Name of execute dir */
-#endif
 
 #define        CMDSLEN 5                               /* Length of trailer */
 #define        DATALEN 5                               /* Length of trailer */
 
 #define        CMDSLEN 5                               /* Length of trailer */
 #define        DATALEN 5                               /* Length of trailer */
-/* rti!trt: XEQTLEN was 0, for reverse search, but that did not work. */
 #define        XEQTLEN 5                               /* Length of trailer */
 #define        NUMCTRS 3                               /* # file types to count */
 #define        CMDTYPE 0                               /* Index into scnt.cntr */
 #define        DATTYPE 1                               /* Index into scnt.cntr */
 #define        XEQTYPE 2                               /* Index into scnt.cntr */
 
 #define        XEQTLEN 5                               /* Length of trailer */
 #define        NUMCTRS 3                               /* # file types to count */
 #define        CMDTYPE 0                               /* Index into scnt.cntr */
 #define        DATTYPE 1                               /* Index into scnt.cntr */
 #define        XEQTYPE 2                               /* Index into scnt.cntr */
 
-void   scandir(), getstst();
-extern char *index(), *rindex(), *strcpy(), *strncpy();;
-extern long atol();
-extern time_t  time();
-
 struct scnt {                                  /* System count structure */
 struct scnt {                                  /* System count structure */
-               char    name[16];               /* Name of system */
+               char    name[MAXBASENAME+1];    /* Name of system */
                short   cntr[NUMCTRS];          /* Count */
                char    stst[32];               /* STST Message */
                short   cntr[NUMCTRS];          /* Count */
                char    stst[32];               /* STST Message */
-               short   locked;                 /* If LCK..sys present */
+               time_t  locked;                 /* If LCK..sys present */
                int     st_type;                /* STST Type */
                int     st_count;               /* STST Count */
                time_t  st_lastime;             /* STST Last time tried */
                int     st_type;                /* STST Type */
                int     st_count;               /* STST Count */
                time_t  st_lastime;             /* STST Last time tried */
@@ -59,6 +43,7 @@ struct        scnt {                                  /* System count structure */
 
 int    sndx;                                   /* Number of systems */
 struct scnt    sys[NSYSTEM];                   /* Systems queued */
 
 int    sndx;                                   /* Number of systems */
 struct scnt    sys[NSYSTEM];                   /* Systems queued */
+int xqtisrunning = 0;
 
 main()
 {      register int i, j, nlen = 0;
 
 main()
 {      register int i, j, nlen = 0;
@@ -68,202 +53,256 @@ main()
        scandir(CMDSDIR, "C.", CMDSLEN, NULL, CMDTYPE);
        scandir(DATADIR, "D.", DATALEN, NULL, DATTYPE);
        scandir(XEQTDIR, "X.", XEQTLEN, 'X', XEQTYPE);
        scandir(CMDSDIR, "C.", CMDSLEN, NULL, CMDTYPE);
        scandir(DATADIR, "D.", DATALEN, NULL, DATTYPE);
        scandir(XEQTDIR, "X.", XEQTLEN, 'X', XEQTYPE);
-       getstst(SPOOLDR);
+       getstst(SPOOL);
        time(&curtime);
        for(i=0; i<sndx; ++i)
                if((j = strlen(sys[i].name)) > nlen)
                        nlen = j;
        time(&curtime);
        for(i=0; i<sndx; ++i)
                if((j = strlen(sys[i].name)) > nlen)
                        nlen = j;
-       for(i=0; i<sndx; ++i)
-       {       printf("%-*.*s ", nlen, nlen, sys[i].name);
+       for(i=0; i<sndx; ++i) {
+               t = (sys[i].st_lastime +sys[i].st_retry) - curtime;
+
+               /* decide if STST text is worth printing */
+               if (-t < ONEDAY*2 && sys[i].st_type == SS_WRONGTIME) {
+                       sys[i].stst[0] = '\0';
+                       if (sys[i].cntr[0]+sys[i].cntr[1]+sys[i].cntr[2] == 0)
+                               continue;       /* ignore entire line */
+               }
+
+               printf("%-*.*s ", nlen, nlen, sys[i].name);
                if(sys[i].cntr[CMDTYPE])
                        printf("%3.d Cmd%s ", sys[i].cntr[CMDTYPE],
                                sys[i].cntr[CMDTYPE]>1?"s":" ");
                if(sys[i].cntr[CMDTYPE])
                        printf("%3.d Cmd%s ", sys[i].cntr[CMDTYPE],
                                sys[i].cntr[CMDTYPE]>1?"s":" ");
-               else    printf("   ---   ");
+               else
+                       printf("   ---   ");
                if(sys[i].cntr[DATTYPE])
                        printf("%3.d Data ", sys[i].cntr[DATTYPE]);
                if(sys[i].cntr[DATTYPE])
                        printf("%3.d Data ", sys[i].cntr[DATTYPE]);
-               else    printf("   ---   ");
+               else
+                       printf("   ---   ");
                if(sys[i].cntr[XEQTYPE])
                        printf("%3.d Xqt%s ", sys[i].cntr[XEQTYPE],
                                sys[i].cntr[XEQTYPE]>1?"s":" ");
                if(sys[i].cntr[XEQTYPE])
                        printf("%3.d Xqt%s ", sys[i].cntr[XEQTYPE],
                                sys[i].cntr[XEQTYPE]>1?"s":" ");
-               else    printf("   ---   ");
-               if(*sys[i].stst == NULL)
-               {       if(sys[i].locked)
+               else
+                       printf("   ---   ");
+               if(*sys[i].stst == NULL || sys[i].locked > sys[i].st_lastime) {
+                       if(sys[i].locked)
                                printf("LOCKED\n");
                                printf("LOCKED\n");
-                       else    printf("\n");
+                       else
+                               printf("\n");
                        continue;
                }
                printf("%s  ", sys[i].stst);
                        continue;
                }
                printf("%s  ", sys[i].stst);
-               if(sys[i].st_type == SS_INPROGRESS)
-               {       printf("\n");
+               /* decide if STST info is worth pursuing */
+               if (-t < ONEDAY*2 && (sys[i].st_count == 0
+                 || sys[i].st_type == SS_WRONGTIME
+                 || (sys[i].st_type == SS_INPROGRESS && sys[i].locked))) {
+                       printf("\n");
                        continue;
                }
                t = (sys[i].st_lastime +sys[i].st_retry) - curtime;
                        continue;
                }
                t = (sys[i].st_lastime +sys[i].st_retry) - curtime;
-               if(t <= 0)
-                       printf("Retry time reached  ");
-               else
-               {       if(t < 60)
-                               printf("Retry time %ld sec%s  ", (long)(t%60),
+               if (-t < ONEDAY*2 && sys[i].st_type != SS_FAIL)
+                       t = 0;
+
+               if (sys[i].st_count > MAXRECALLS)
+                       printf("at MAX RECALLS");
+               else if (-t >= ONEDAY*2)
+                       printf("%ld days ago", (long)-t/ONEDAY);
+               else if (t <= 0)
+                       printf("Retry time reached");
+               else if (t < 60)
+                       printf("Retry time %ld sec%s", (long)(t%60),
                                        (t%60)!=1? "s": "");
                                        (t%60)!=1? "s": "");
-                       else    printf("Retry time %ld min%s  ", (long)(t/60),
-                                       (t/60)!=1? "s": "");
-               }
+               else
+                       printf("Retry time %ld min%s", (long)(t/60),
+                               (t/60)!=1? "s": "");
                if(sys[i].st_count > 1)
                if(sys[i].st_count > 1)
-                       printf("Count: %d\n", sys[i].st_count);
-               else    printf("\n");
+                       printf(" Count: %d\n", sys[i].st_count);
+               else
+                       printf("\n");
        }
        }
+       if (xqtisrunning)
+               printf("\nUuxqt is running\n");
        exit(0);
 }
        exit(0);
 }
-void scandir(dnam, prfx, flen, fchr, type)
+
+scandir(dnam, prfx, flen, fchr, type)
 char *dnam, *prfx, fchr;
 char *dnam, *prfx, fchr;
-{      register int i, plen;
-       char    fnam[MAXNAMLEN+1];
+{
        register struct direct *dentp;
        register DIR *dirp;
        register struct direct *dentp;
        register DIR *dirp;
+       register int i, fnamlen, plen;
+       char    fnam[MAXNAMLEN+1];
 
        plen = strlen(prfx);
 
        plen = strlen(prfx);
-       if(chdir(dnam) < 0)
-       {       perror(dnam);
+       if(chdir(dnam) < 0) {
+               perror(dnam);
                exit(1);
        }
                exit(1);
        }
-       if ((dirp = opendir(".", "r")) == NULL)
-       {       perror(dnam);
+       if ((dirp = opendir(".")) == NULL) {
+               perror(dnam);
                exit(1);
        }
                exit(1);
        }
-       while((dentp = readdir(dirp)) != NULL)
-       {       if(*dentp->d_name == '.' || dentp->d_ino == 0)
+       while((dentp = readdir(dirp)) != NULL) {
+               if(*dentp->d_name == '.')
                        continue;
                if(strncmp(dentp->d_name, prfx, plen) != SAME) {
                        continue;
                if(strncmp(dentp->d_name, prfx, plen) != SAME) {
-#ifdef UUDIR
                        fprintf(stderr, "strange file (%s) in %s\n",
                                dentp->d_name, dnam);
                        fprintf(stderr, "strange file (%s) in %s\n",
                                dentp->d_name, dnam);
-#endif
                        continue;
                }
                strcpy(fnam, &dentp->d_name[plen]);
                        continue;
                }
                strcpy(fnam, &dentp->d_name[plen]);
-               i = strlen(fnam);
-               if(flen > 0)
-                       fnam[i -flen] = NULL;
-               else
-               for(; i>0; --i)
-               {       if(fnam[i] == fchr)
-                       {       fnam[i] = NULL;
-                               break;
+               fnamlen = strlen(fnam);
+               if(flen > 0) {
+                       char c;
+                       fnamlen -= flen;
+                       c = fnam[fnamlen];
+                       if (islower(c))
+                               c = toupper(c);
+                       if (type == DATTYPE && (c != 'S' && c != 'B')) {
+                               fnamlen -= 2;   /* For Honey DanBer */
+                               fnam[fnamlen] = NULL;
+                       } else {
+                               fnam[fnamlen] = NULL;
+                               fnamlen = MAXBASENAME; /* yes, after = NULL*/
+                       }
+               } else {
+                       for(; fnamlen>0; --fnamlen) {
+                               if(fnam[fnamlen] == fchr) {
+                                       fnam[fnamlen] = NULL;
+                                       break;
+                               }
                        }
                        }
+                       fnamlen = MAXBASENAME;
                }
                }
-               for(i=0; i<sndx; ++i)
-               {       if(strcmp(fnam, sys[i].name) == SAME)
-                       {       ++sys[i].cntr[type];
+               for(i=0; i<sndx; ++i) {
+                       if(strncmp(fnam, sys[i].name, fnamlen) == SAME) {
+                               ++sys[i].cntr[type];
                                break;
                        }
                }
                                break;
                        }
                }
-               if(i == sndx)
-               {       strcpy(sys[i].name, fnam);
+               if(i == sndx) {
+                       strcpy(sys[i].name, fnam);
                        ++sys[i].cntr[type];
                        ++sndx;
                }
        }
        closedir(dirp);
 }
                        ++sys[i].cntr[type];
                        ++sndx;
                }
        }
        closedir(dirp);
 }
-void getstst(sdir)
+
+getstst(sdir)
 char *sdir;
 char *sdir;
-{      register int i, csys;
+{
+       register int i, csys;
        register char *tp;
        char    fnam[MAXNAMLEN+1], buff[128];
        register struct direct *dentp;
        register DIR *dirp;
        register FILE *st;
        register char *tp;
        char    fnam[MAXNAMLEN+1], buff[128];
        register struct direct *dentp;
        register DIR *dirp;
        register FILE *st;
+       struct stat stbuf;
+       long atol();
 
 
-       if(chdir(sdir) < 0)
-       {       perror(sdir);
+       if (chdir(sdir) < 0) {
+               perror(sdir);
                exit(1);
        }
                exit(1);
        }
-       if((dirp = opendir(".", "r")) == NULL)
-       {       perror(sdir);
+       if ((dirp = opendir(LOCKDIR)) == NULL) {
+               perror(sdir);
                exit(1);
        }
                exit(1);
        }
-       while((dentp = readdir(dirp)) != NULL)
-       {       if(dentp->d_ino == 0)
+       while ((dentp = readdir(dirp)) != NULL) {
+               if (strcmp(&dentp->d_name[5], X_LOCK) == SAME) {
+                       xqtisrunning++;
                        continue;
                        continue;
-               if(strncmp(dentp->d_name, "LCK..", 5) == SAME)
-               {       if(strncmp(&dentp->d_name[5], "tty", 3) == SAME ||
+               }
+               if(strncmp(dentp->d_name, "LCK..", 5) == SAME) {
+                       if(strncmp(&dentp->d_name[5], "tty", 3) == SAME ||
                           strncmp(&dentp->d_name[5], "cul", 3) == SAME)
                                continue;
                        strcpy(fnam, dentp->d_name);
                           strncmp(&dentp->d_name[5], "cul", 3) == SAME)
                                continue;
                        strcpy(fnam, dentp->d_name);
-                       for(csys=0; csys<sndx; ++csys)
-                       {       if(strcmp(&fnam[5], sys[csys].name) == SAME)
+                       for(csys=0; csys<sndx; ++csys) {
+                               if(strncmp(&fnam[5], sys[csys].name, SYSNSIZE)
+                                       == SAME)
                                        break;
                        }
                                        break;
                        }
-                       if(csys == sndx)
-                       {       strcpy(sys[csys].name, &fnam[5]);
+                       strcpy(sys[csys].name, &fnam[5]);
+                       if(csys == sndx) {
                                ++sndx;
                        }
                                ++sndx;
                        }
-                       ++sys[csys].locked;
+                       if (stat(fnam, &stbuf) < 0)
+                               sys[csys].locked = 1;
+                       else
+                               sys[csys].locked = stbuf.st_mtime;
                        continue;
                }
                        continue;
                }
-               if(strncmp(dentp->d_name, "STST.", 5) == SAME)
-               {       strcpy(fnam, dentp->d_name);
-                       for(csys=0; csys<sndx; ++csys)
-                       {       if(strcmp(&fnam[5], sys[csys].name) == SAME)
-                                       break;
-                       }
-                       if(csys == sndx)
-                       {       strcpy(sys[csys].name, &fnam[5]);
-                               ++sndx;
-                       }
-                       if((st = fopen(fnam, "r")) == NULL)
-                       {       strncpy(sys[csys].stst, "",
-                                       sizeof(sys[csys].stst));
-                               continue;
-                       }
-                       strncpy(buff, "", sizeof(buff));
-                       fgets(buff, sizeof(buff), st);
-                       fclose(st);
-                       if(tp = rindex(buff, ' '))
-                               *tp = NULL;             /* drop system name */
-                       else    continue;
-                       for(i=0, tp=buff;  i<4;  ++i, ++tp)
-                               if((tp = index(tp, ' ')) == NULL)
-                                       break;
-                       if(i != 4)
-                               continue;
-                       strncpy(sys[csys].stst, tp, sizeof(sys[csys].stst));
-                       tp = buff;
-                       sys[csys].st_type = atoi(tp);
-                       tp = index(tp+1, ' ');
-                       sys[csys].st_count = atoi(tp+1);
-                       tp = index(tp+1, ' ');
-                       sys[csys].st_lastime = (time_t)atol(tp+1);
-                       tp = index(tp+1, ' ');
-                       sys[csys].st_retry = (time_t)atol(tp+1);
-               }
        }
        closedir(dirp);
        }
        closedir(dirp);
+       if (chdir("STST") < 0) {
+               perror("STST");
+               exit(1);
+       }
+       if ((dirp = opendir(".")) == NULL) {
+               perror("STST");
+               exit(1);
+       }
+       while ((dentp = readdir(dirp)) != NULL) {
+               if(*dentp->d_name == '.')
+                       continue;
+               strcpy(fnam, dentp->d_name);
+               for(csys=0; csys<sndx; ++csys) {
+                       if(strncmp(fnam, sys[csys].name, SYSNSIZE) == SAME)
+                               break;
+               }
+               strcpy(sys[csys].name, fnam);
+               if(csys == sndx) {
+                       ++sndx;
+               }
+               if((st = fopen(fnam, "r")) == NULL) {
+                       sys[csys].stst[0] = '\0';
+                       continue;
+               }
+               buff[0] = '\0';
+               fgets(buff, sizeof(buff), st);
+               fclose(st);
+               if(tp = rindex(buff, ' '))
+                       *tp = NULL;             /* drop system name */
+               else
+                       continue;
+               for(i=0, tp=buff;  i<4;  ++i, ++tp)
+                       if((tp = index(tp, ' ')) == NULL)
+                               break;
+               if(i != 4)
+                       continue;
+               strncpy(sys[csys].stst, tp, sizeof(sys[csys].stst));
+               tp = buff;
+               sys[csys].st_type = atoi(tp);
+               tp = index(tp+1, ' ');
+               sys[csys].st_count = atoi(tp+1);
+               tp = index(tp+1, ' ');
+               sys[csys].st_lastime = atol(tp+1);
+               tp = index(tp+1, ' ');
+               sys[csys].st_retry = atol(tp+1);
+       }
 }
 }
-/* @(#)index.c 4.1 (Berkeley) 12/21/80 */
 /*
  * Return the ptr in sp at which the character c appears;
  * NULL if not found
  */
 
 /*
  * Return the ptr in sp at which the character c appears;
  * NULL if not found
  */
 
-
 char *
 index(sp, c)
 register char *sp, c;
 {
        do {
                if (*sp == c)
 char *
 index(sp, c)
 register char *sp, c;
 {
        do {
                if (*sp == c)
-                       return(sp);
+                       return sp;
        } while (*sp++);
        } while (*sp++);
-       return(NULL);
+       return NULL;
 }
 
 }
 
-/* @(#)rindex.c        4.1 (Berkeley) 12/21/80 */
 /*
  * Return the ptr in sp at which the character c last
  * appears; NULL if not found
 */
 
 /*
  * Return the ptr in sp at which the character c last
  * appears; NULL if not found
 */
 
-
 char *
 rindex(sp, c)
 register char *sp, c;
 char *
 rindex(sp, c)
 register char *sp, c;
@@ -275,5 +314,5 @@ register char *sp, c;
                if (*sp == c)
                        r = sp;
        } while (*sp++);
                if (*sp == c)
                        r = sp;
        } while (*sp++);
-       return(r);
+       return r;
 }
 }