BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / at / atq / atq.c
index 117382c..b46434b 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)atq.c      5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)atq.c      5.6 (Berkeley) 5/11/89";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -38,10 +38,7 @@ static char sccsid[] = "@(#)atq.c    5.1 (Berkeley) %G%";
 # include <sys/time.h>
 # include <pwd.h>
 # include <ctype.h>
 # include <sys/time.h>
 # include <pwd.h>
 # include <ctype.h>
-# define ATDIR         "/usr/spool/at"                 /* spooling area */
-# define LASTFILE      "/usr/spool/at/lasttimedone"    /* update time record 
-                                                          file */
+# include "pathnames.h"
 
 /*
  * Months of the year
 
 /*
  * Months of the year
@@ -51,7 +48,7 @@ static char *mthnames[12] = {
        "Aug","Sep","Oct","Nov","Dec",
 };
 
        "Aug","Sep","Oct","Nov","Dec",
 };
 
-
+char *nullentry = NULL;                        /* avoid 'namelist' NULL ptr problems */
 int numentries;                                /* number of entries in spooling area */
 int namewanted = 0;                    /* only print jobs belonging to a 
                                           certain person */
 int numentries;                                /* number of entries in spooling area */
 int namewanted = 0;                    /* only print jobs belonging to a 
                                           certain person */
@@ -73,7 +70,7 @@ char **argv;
        int printqueue();               /* print the queue */
        int countfiles();               /* count the number of files in queue
                                           for a given person */
        int printqueue();               /* print the queue */
        int countfiles();               /* count the number of files in queue
                                           for a given person */
-       char **namelist;                /* array of specific name(s) requested*/
+       char **namelist = &nullentry;   /* array of specific name(s) requested*/
 
 
        --argc, ++argv;
 
 
        --argc, ++argv;
@@ -101,7 +98,7 @@ char **argv;
         * If a certain name (or names) is requested, set a pointer to the
         * beginning of the list.
         */
         * If a certain name (or names) is requested, set a pointer to the
         * beginning of the list.
         */
-       if (**argv) {
+       if (argc > 0) {
                ++namewanted;
                namelist = argv;
        }
                ++namewanted;
                namelist = argv;
        }
@@ -111,13 +108,13 @@ char **argv;
         * files in the queue structure. The queue comes back sorted by
         * execution time or creation time.
         */
         * files in the queue structure. The queue comes back sorted by
         * execution time or creation time.
         */
-       if (chdir(ATDIR) == -1) {
-               perror(ATDIR);
+       if (chdir(_PATH_ATDIR) == -1) {
+               perror(_PATH_ATDIR);
                exit(1);
        }
        if ((numentries = scandir(".",&queue,filewanted, (cflag) ? creation : 
                                alphasort)) < 0) {
                exit(1);
        }
        if ((numentries = scandir(".",&queue,filewanted, (cflag) ? creation : 
                                alphasort)) < 0) {
-               perror(ATDIR);
+               perror(_PATH_ATDIR);
                exit(1);
        }
 
                exit(1);
        }
 
@@ -203,7 +200,6 @@ char **namelist;
                                                   spooling area was updated */
        int powner();                           /* print the name of the owner
                                                   of the job */
                                                   spooling area was updated */
        int powner();                           /* print the name of the owner
                                                   of the job */
-       int getid();                            /* get uid of a person */
        char **ptr;                             /* scratch pointer */
        struct stat stbuf;                      /* buffer for file stats */
 
        char **ptr;                             /* scratch pointer */
        struct stat stbuf;                      /* buffer for file stats */
 
@@ -259,17 +255,17 @@ isowner(name,job)
 char *name;
 char *job;
 {
 char *name;
 char *job;
 {
-       char buf[30];                   /* buffer for 1st line of spoolfile 
+       char buf[128];                  /* buffer for 1st line of spoolfile 
                                           header */
        FILE *infile;                   /* I/O stream to spoolfile */
 
        if ((infile = fopen(job,"r")) == NULL) {
                                           header */
        FILE *infile;                   /* I/O stream to spoolfile */
 
        if ((infile = fopen(job,"r")) == NULL) {
-               fprintf(stderr,"Couldn't open spoolfile");
+               fprintf(stderr,"Couldn't open spoolfile ");
                perror(job);
                return(0);
        }
 
                perror(job);
                return(0);
        }
 
-       if (fscanf(infile,"# owner: %s\n",buf) != 1) {
+       if (fscanf(infile,"# owner: %127s%*[^\n]\n",buf) != 1) {
                fclose(infile);
                return(0);
        }
                fclose(infile);
                return(0);
        }
@@ -285,7 +281,7 @@ char *job;
 powner(file)
 char *file;
 {
 powner(file)
 char *file;
 {
-       char owner[80];                         /* the owner */
+       char owner[10];                         /* the owner */
        FILE *infile;                           /* I/O stream to spoolfile */
 
        /*
        FILE *infile;                           /* I/O stream to spoolfile */
 
        /*
@@ -294,10 +290,11 @@ char *file;
 
        if ((infile = fopen(file,"r")) == NULL) {
                printf("%-10.9s","???");
 
        if ((infile = fopen(file,"r")) == NULL) {
                printf("%-10.9s","???");
+               perror(file);
                return;
        }
 
                return;
        }
 
-       if (fscanf(infile,"# owner: %s",owner) != 1) {
+       if (fscanf(infile,"# owner: %9s%*[^\n]\n",owner) != 1) {
                printf("%-10.9s","???");
                fclose(infile);
                return;
                printf("%-10.9s","???");
                fclose(infile);
                return;
@@ -308,24 +305,6 @@ char *file;
 
 }
        
 
 }
        
-
-/*
- * Get the uid of a person using his/her login name. Return -1 if no
- * such account name exists.
- */
-getid(name)
-char *name;
-{
-
-       struct passwd *pwdinfo;                 /* password info structure */
-
-
-       if ((pwdinfo = getpwnam(name)) == 0)
-               return(-1);
-
-       return(pwdinfo->pw_uid);
-}
-
 /*
  * Print the time the spooling area was updated.
  */
 /*
  * Print the time the spooling area was updated.
  */
@@ -345,11 +324,11 @@ plastrun()
         * last update hour. The update time is measured in seconds since
         * 1/1/70.
         */
         * last update hour. The update time is measured in seconds since
         * 1/1/70.
         */
-       if ((last = fopen(LASTFILE,"r")) == NULL) {
-               perror(LASTFILE);
+       if ((last = fopen(_PATH_LASTFILE,"r")) == NULL) {
+               perror(_PATH_LASTFILE);
                exit(1);
        }
                exit(1);
        }
-       fscanf(last,"%d",(u_long) &lasttime);
+       fscanf(last,"%lu",&lasttime);
        fclose(last);
 
        /*
        fclose(last);
 
        /*
@@ -397,7 +376,7 @@ char *filename;
        int year  =  0;                         /* year file will be executed */
        int get_mth_day();                      /* convert a day of year to a
                                                   month and day of month */
        int year  =  0;                         /* year file will be executed */
        int get_mth_day();                      /* convert a day of year to a
                                                   month and day of month */
-       char date[18];                          /* reformatted execution date */
+       char date[19];                          /* reformatted execution date */
 
        /*
         * Pick off the necessary info from the file name and convert the day
 
        /*
         * Pick off the necessary info from the file name and convert the day
@@ -465,7 +444,7 @@ printjobname(file)
 char *file;
 {
        char *ptr;                              /* scratch pointer */
 char *file;
 {
        char *ptr;                              /* scratch pointer */
-       char jobname[80];                       /* the job name */
+       char jobname[28];                       /* the job name */
        FILE *filename;                         /* job file in spooling area */
 
        /*
        FILE *filename;                         /* job file in spooling area */
 
        /*
@@ -475,17 +454,18 @@ char *file;
 
        if ((filename = fopen(file,"r")) == NULL) {
                printf("%.27s\n", "???");
 
        if ((filename = fopen(file,"r")) == NULL) {
                printf("%.27s\n", "???");
+               perror(file);
                return;
        }
        /*
                return;
        }
        /*
-        * We'll yank the first line into the buffer temporarily.
+        * Skip over the first line.
         */
         */
-       fgets(jobname,80,filename);
+       fscanf(filename,"%*[^\n]\n");
 
        /*
         * Now get the job name.
         */
 
        /*
         * Now get the job name.
         */
-       if (fscanf(filename,"# jobname: %s",jobname) != 1) {
+       if (fscanf(filename,"# jobname: %27s%*[^\n]\n",jobname) != 1) {
                printf("%.27s\n", "???");
                fclose(filename);
                return;
                printf("%.27s\n", "???");
                fclose(filename);
                return;