update from dss%fatkid@SUN.COM (Daniel Steinberg)
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Thu, 29 May 1986 09:43:43 +0000 (01:43 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Thu, 29 May 1986 09:43:43 +0000 (01:43 -0800)
SCCS-vsn: usr.bin/at/at/at.c 5.4
SCCS-vsn: usr.bin/at/atrun/atrun.c 5.4
SCCS-vsn: usr.bin/at/atq/atq.c 5.2
SCCS-vsn: usr.bin/at/atrm/atrm.c 5.2

usr/src/usr.bin/at/at/at.c
usr/src/usr.bin/at/atq/atq.c
usr/src/usr.bin/at/atrm/atrm.c
usr/src/usr.bin/at/atrun/atrun.c

index d06f6ea..b35061b 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)at.c       5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)at.c       5.4 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -43,13 +43,14 @@ static char sccsid[] = "@(#)at.c    5.3 (Berkeley) %G%";
 #define DAY            2               /* day requested is a weekday */
 #define MONTH          3               /* day requested is a month */
 
 #define DAY            2               /* day requested is a weekday */
 #define MONTH          3               /* day requested is a month */
 
-#define BOURNE         0               /* run commands with Bourne shell*/
-#define CSHELL         1               /* run commands with C shell */
+#define BOURNE         "/bin/sh"       /* run commands with Bourne shell*/
+#define CSHELL         "/bin/csh"      /* run commands with C shell */
 
 #define NODATEFOUND    -1              /* no date was given on command line */
 
 #define ATDIR          "/usr/spool/at"         /* spooling area */
 
 
 #define NODATEFOUND    -1              /* no date was given on command line */
 
 #define ATDIR          "/usr/spool/at"         /* spooling area */
 
+#define LINSIZ         256             /* length of input buffer */
 
 /*
  * A table to identify potential command line values for "time". 
 
 /*
  * A table to identify potential command line values for "time". 
@@ -134,10 +135,9 @@ char **argv;
        int c;                          /* scratch variable */
        int usage();                    /* print usage info and exit */
        int cleanup();                  /* do cleanup on an interrupt signal */
        int c;                          /* scratch variable */
        int usage();                    /* print usage info and exit */
        int cleanup();                  /* do cleanup on an interrupt signal */
-       int dateindex;                  /* if a day is specified, what option
+       int dateindex = NODATEFOUND;    /* if a day is specified, what option
                                           is it? (mon day, week, dayofweek) */
                                           is it? (mon day, week, dayofweek) */
-       int shell = 0;                  /* what shell do we use to run job?   
-                                          BOURNE = 0   CSHELL = 1 */
+       char *shell = BOURNE;           /* what shell do we use to run job? */
        int shflag = 0;                 /* override the current shell and run
                                           job using the Bourne Shell */
        int cshflag = 0;                /* override the current shell and run 
        int shflag = 0;                 /* override the current shell and run
                                           job using the Bourne Shell */
        int cshflag = 0;                /* override the current shell and run 
@@ -145,7 +145,7 @@ char **argv;
        int mailflag = 0;               /* send mail after a job has been run?*/
        int standardin = 0;             /* are we reading from stardard input */
        char *tmp;                      /* scratch pointer */
        int mailflag = 0;               /* send mail after a job has been run?*/
        int standardin = 0;             /* are we reading from stardard input */
        char *tmp;                      /* scratch pointer */
-       char line[100];                 /* a line from input file */
+       char line[LINSIZ];              /* a line from input file */
        char pwbuf[MAXPATHLEN];         /* the current working directory */
        char *jobfile = "stdin";        /* file containing job to be run */
        char *getname();                /* get the login name of a user */
        char pwbuf[MAXPATHLEN];         /* the current working directory */
        char *jobfile = "stdin";        /* file containing job to be run */
        char *getname();                /* get the login name of a user */
@@ -196,7 +196,7 @@ char **argv;
        printit();
 #endif
 
        printit();
 #endif
 
-       if (!(*argv))
+       if (argc <= 0)
                usage();
 
        /*
                usage();
 
        /*
@@ -212,18 +212,7 @@ char **argv;
 #endif
 
        /*
 #endif
 
        /*
-        * If no argv[2] exists, then we are reading from standard input
-        * and only a time of day has been specified. Therefore, we set
-        * the standard input flag, and indicate that a date was not
-        * specified (NODATEFOUND).
-        */
-       if (!*argv) {
-               ++standardin;
-               dateindex = NODATEFOUND;
-       } else {
-
-       /*
-        * Otherwise, we are dealing with a request to run a job on a certain
+        * If argv[(2)] exists, this is a request to run a job on a certain
         * day of year or a certain day of week.
         *
         * We send  argv to the function "getdateindex" which returns the 
         * day of year or a certain day of week.
         *
         * We send  argv to the function "getdateindex" which returns the 
@@ -233,6 +222,7 @@ char **argv;
         * this means that the argument is a "filename"). If the requested 
         * day is found, we continue to process command line arguments.
         */
         * this means that the argument is a "filename"). If the requested 
         * day is found, we continue to process command line arguments.
         */
+       if (argc > 0) {
                if ((dateindex = getdateindex(*argv)) != NODATEFOUND) {
 
                        ++argv; --argc;
                if ((dateindex = getdateindex(*argv)) != NODATEFOUND) {
 
                        ++argv; --argc;
@@ -241,30 +231,7 @@ char **argv;
                         * Determine the day of year that the job will be run
                         * depending on the value of argv.
                         */
                         * Determine the day of year that the job will be run
                         * depending on the value of argv.
                         */
-                       makedayofyear(dateindex, argv);
-
-                       /*
-                        * If we were dealing with the <month day> format,
-                        * we need to skip over the next argv (the day of
-                        * month).
-                        */
-                       if (dates_info[dateindex].type == MONTH)
-                               ++argv; --argc;
-
-                       /*
-                        * If 'week' was requested, we need to skip over 
-                        * the next argv ('week').
-                        */
-                       if (strcmp(*argv,"week") == 0) 
-                               ++argv; --argc;
-
-                       /*
-                        * If no more arguments exist, then we are reading
-                        * from standard input. Thus, we set the standard
-                        * input flag (++standardin).
-                        */
-                       if (!(*argv))
-                               ++standardin;
+                       makedayofyear(dateindex, &argv, &argc);
                }
        }
 
                }
        }
 
@@ -279,10 +246,10 @@ char **argv;
         */
        if (dateindex == NODATEFOUND) {
                int daysinyear;
         */
        if (dateindex == NODATEFOUND) {
                int daysinyear;
-               if (strncmp(*argv,"week",4) == 0)
+               if ((argc > 0) && (strcmp(*argv,"week") == 0)) {
                        attime.yday += 7;
                        attime.yday += 7;
-
-               else if (istomorrow())
+                       ++argv; --argc;
+               else if (istomorrow())
                        ++attime.yday;
 
                daysinyear = isleap(attime.year) ? 366 : 365;
                        ++attime.yday;
 
                daysinyear = isleap(attime.year) ? 366 : 365;
@@ -292,6 +259,14 @@ char **argv;
                }
        }
 
                }
        }
 
+       /*
+        * If no more arguments exist, then we are reading
+        * from standard input. Thus, we set the standard
+        * input flag (++standardin).
+        */
+       if (argc <= 0)
+               ++standardin;
+
 
 #ifdef DEBUG
        printf("\n\nAFTER ADDDAYS\n");
 
 #ifdef DEBUG
        printf("\n\nAFTER ADDDAYS\n");
@@ -383,25 +358,34 @@ char **argv;
                }
        }
                
                }
        }
                
+       /*
+        * If the inputfile is not from a tty then turn off standardin
+        * If the inputfile is a tty, put out a prompt now, instead of
+        * waiting for a lot of file activity to complete.
+        */
+       if (!(isatty(fileno(inputfile)))) 
+               standardin = 0 ;
+       if (standardin) {
+               fputs("at> ", stdout);
+               fflush(stdout);
+       }
+
        /*
         * Determine what shell we should use to run the job. If the user
         * didn't explicitly request that his/her current shell be over-
         * ridden (shflag of cshflag) then we use the current shell.
         */
        /*
         * Determine what shell we should use to run the job. If the user
         * didn't explicitly request that his/her current shell be over-
         * ridden (shflag of cshflag) then we use the current shell.
         */
-       if ((!shflag) && (!cshflag)) {
-               tmp = getenv("SHELL");
-               shell = ((strcmp(tmp+strlen(tmp)-3, "csh") == 0) ? 
-                                                       CSHELL : BOURNE);
-       }
+       if ((!shflag) && (!cshflag) && (getenv("SHELL") != NULL))
+               shell = "$SHELL";
 
        /*
         * Put some standard information at the top of the spoolfile.
         * This info is used by the other "at"-oriented programs (atq,
         * atrm, atrun).
         */
 
        /*
         * Put some standard information at the top of the spoolfile.
         * This info is used by the other "at"-oriented programs (atq,
         * atrm, atrun).
         */
-       fprintf(spoolfile, "# owner: %s\n",getname(getuid()));
-       fprintf(spoolfile, "# jobname: %s\n",jobfile);
-       fprintf(spoolfile, "# shell: %s\n",(shell == 1) ? "csh" : "sh");
+       fprintf(spoolfile, "# owner: %.127s\n",getname(getuid()));
+       fprintf(spoolfile, "# jobname: %.127s\n",jobfile);
+       fprintf(spoolfile, "# shell: sh\n");
        fprintf(spoolfile, "# notify by mail: %s\n",(mailflag) ? "yes" : "no");
        fprintf(spoolfile, "\n");
 
        fprintf(spoolfile, "# notify by mail: %s\n",(mailflag) ? "yes" : "no");
        fprintf(spoolfile, "\n");
 
@@ -426,14 +410,16 @@ char **argv;
         * Copy the user's environment to the spoolfile.
         */
        if (environ) {
         * Copy the user's environment to the spoolfile.
         */
        if (environ) {
-               copyenvironment(shell,&spoolfile);
+               copyenvironment(&spoolfile);
        }
 
        /*
        }
 
        /*
-        * If the inputfile is not from a tty then turn off standardin
+        * Put in a line to run the proper shell using the rest of
+        * the file as input.  Note that 'exec'ing the shell will
+        * cause sh() to leave a /tmp/sh### file around.
         */
         */
-       if (!(isatty(fileno(inputfile)))) 
-               standardin = 0 ;
+       fprintf(spoolfile,
+           "%s << '...the rest of this file is shell input'\n", shell);
 
        /*
         * Now that we have all the files set up, we can start reading in
 
        /*
         * Now that we have all the files set up, we can start reading in
@@ -443,10 +429,13 @@ char **argv;
         * message that said it was waiting for input if it was reading
         * form standard input).
         */
         * message that said it was waiting for input if it was reading
         * form standard input).
         */
-       while(fputs((standardin) ? "at> " : "",stdout) != EOF
-                               && (fgets(line,100,inputfile) != NULL)) {
+       while (fgets(line, LINSIZ, inputfile) != NULL) {
                fputs(line, spoolfile);
                fputs(line, spoolfile);
+               if (standardin)
+                       fputs("at> ", stdout);
        }
        }
+       if (standardin)
+               fputs("<EOT>\n", stdout);       /* clean up the final output */
 
        /*
         * Close all files and change the mode of the spoolfile.
 
        /*
         * Close all files and change the mode of the spoolfile.
@@ -459,47 +448,35 @@ char **argv;
 }
 
 /*
 }
 
 /*
- * Copy the user's environment to the spoolfile. Depending on the value of
- * "shell" we convert the environment values so they correspond to the syntax 
- * of the Cshell (1) or the Bourne shell (0). This thing DOES work, although 
- * it may look a bit kludgey.
+ * Copy the user's environment to the spoolfile in the syntax of the
+ * Bourne shell.  After the environment is set up, the proper shell
+ * will be invoked.
  */
  */
-copyenvironment(shell,spoolfile)
-int shell;
+copyenvironment(spoolfile)
 FILE **spoolfile;
 {
        char *tmp;                      /* scratch pointer */
        char **environptr = environ;    /* pointer to an environment setting */
 
 FILE **spoolfile;
 {
        char *tmp;                      /* scratch pointer */
        char **environptr = environ;    /* pointer to an environment setting */
 
-       if (shell == CSHELL) {
-               fprintf(*spoolfile, "if ($?histchars) then\n");
-               fprintf(*spoolfile, "set xxhist=$histchars\nendif\n");
-               fprintf(*spoolfile, "set histchars=''\n");
-               fprintf(*spoolfile, "set noglob\n");
-       }
        while(*environptr) {
                tmp = *environptr;
 
                /*
                 * We don't want the termcap or terminal entry so skip them.
                 */
        while(*environptr) {
                tmp = *environptr;
 
                /*
                 * We don't want the termcap or terminal entry so skip them.
                 */
-               if (strncmp(tmp,"TERM",4) == 0) {
+               if ((strncmp(tmp,"TERM=",5) == 0) ||
+                   (strncmp(tmp,"TERMCAP=",8) == 0)) {
                        ++environptr;
                        continue;
                }
 
                /*
                        ++environptr;
                        continue;
                }
 
                /*
-                * Set up the proper syntax. ("setenv xx yy" for the Cshell
-                * and "xx = 'yy'" for the Bourne shell).
+                * Set up the proper syntax.
                 */
                 */
-               if (shell == CSHELL)
-                       fputs("setenv ",*spoolfile);
                while (*tmp != '=')
                        fputc(*tmp++,*spoolfile);
                while (*tmp != '=')
                        fputc(*tmp++,*spoolfile);
-               if (shell == BOURNE) {
-                       fputc('=', *spoolfile);
-               }
-               fputs((shell == CSHELL) ? " \"" : "'" , *spoolfile);
+               fputc('=', *spoolfile);
+               fputc('\'' , *spoolfile);
                ++tmp;
 
                /*
                ++tmp;
 
                /*
@@ -514,30 +491,18 @@ FILE **spoolfile;
                                fputc(*tmp, *spoolfile);
                        ++tmp;
                }
                                fputc(*tmp, *spoolfile);
                        ++tmp;
                }
-               fputc((shell == CSHELL) ? '"' : '\'' , *spoolfile);
+               fputc('\'' , *spoolfile);
 
                /*
 
                /*
-                * If it's the Bourne shell, we need to "export" environment
-                * settings.
+                * We need to "export" environment settings.
                 */
                 */
-               if (shell == BOURNE) {
-                       fprintf(*spoolfile, "\nexport ");
-                       tmp = *environptr;
-                       while (*tmp != '=')
-                               fputc(*tmp++,*spoolfile);
-               }
+               fprintf(*spoolfile, "\nexport ");
+               tmp = *environptr;
+               while (*tmp != '=')
+                       fputc(*tmp++,*spoolfile);
                fputc('\n',*spoolfile);
                ++environptr;
        }
                fputc('\n',*spoolfile);
                ++environptr;
        }
-       if (shell == CSHELL) {
-               fprintf(*spoolfile, "unset noglob\n");
-               fprintf(*spoolfile, "if ($?xxhist) then\n");
-               fprintf(*spoolfile, "set histchars=$xxhist\nelse\n");
-               fprintf(*spoolfile, "unset histchars\nendif\n");
-       }
-       /*
-        * My god, it worked! (I hope)
-        */
        return;
 }
 
        return;
 }
 
@@ -598,12 +563,15 @@ printit()
 
 /*
  * Calculate the day of year that the job will be executed.
 
 /*
  * Calculate the day of year that the job will be executed.
+ * The av,ac arguments are ptrs to argv,argc; updated as necessary.
  */
  */
-makedayofyear(dateindex,argv)
-char **argv;
+makedayofyear(dateindex, av, ac)
 int dateindex;
 int dateindex;
+char ***av;
+int *ac;
 {
 {
-       
+       char **argv = *av;      /* imitate argc,argv and update args at end */
+       int argc = *ac;
        char *ptr;                              /* scratch pointer */
        struct datetypes *daterequested;        /* pointer to information about
                                                   the type of date option
        char *ptr;                              /* scratch pointer */
        struct datetypes *daterequested;        /* pointer to information about
                                                   the type of date option
@@ -634,7 +602,7 @@ int dateindex;
                 * If a day of month isn't specified, print a message
                 * and exit.
                 */
                 * If a day of month isn't specified, print a message
                 * and exit.
                 */
-               if (!*argv) {
+               if (argc <= 0) {
                        fprintf(stderr,"day of month not specified.\n");
                        exit(1);
                }
                        fprintf(stderr,"day of month not specified.\n");
                        exit(1);
                }
@@ -675,14 +643,16 @@ int dateindex;
                 * Finally, we determine the day of year.
                 */
                attime.yday = (countdays());
                 * Finally, we determine the day of year.
                 */
                attime.yday = (countdays());
-               ++argv;
+               ++argv; --argc;
        }
 
        /*
         * If 'week' is specified, add 7 to the day of year.
         */
        }
 
        /*
         * If 'week' is specified, add 7 to the day of year.
         */
-       if (strncmp(*argv,"week",4) == 0)
+       if ((argc > 0) && (strcmp(*argv,"week") == 0)) {
                attime.yday += 7;
                attime.yday += 7;
+               ++argv; --argc;
+       }
 
        /*
         * Now that all that is done, see if the requested execution time
 
        /*
         * Now that all that is done, see if the requested execution time
@@ -691,6 +661,12 @@ int dateindex;
         */
        if (isnextyear())
                ++attime.year;
         */
        if (isnextyear())
                ++attime.year;
+       
+       /*
+        * Finally, reflect the updated argc,argv to the caller
+        */
+       *av = argv;
+       *ac = argc;
 }
 
 /*
 }
 
 /*
@@ -775,7 +751,7 @@ char *date;
                if (isprefix(date, ptr->name))
                        return(i);
        }
                if (isprefix(date, ptr->name))
                        return(i);
        }
-       return(-1);
+       return(NODATEFOUND);
 }
 
 isprefix(prefix, fullname)
 }
 
 isprefix(prefix, fullname)
@@ -877,12 +853,18 @@ struct times *attime;
 
                case 'n':
                case 'N':
 
                case 'n':
                case 'N':
-                       val = HALFDAY;
+                       if ((val == 0) || (val == HALFDAY))
+                               val = HALFDAY;
+                       else
+                               val = FULLDAY+1;  /* illegal */
                        break;
 
                case 'M':
                case 'm':
                        break;
 
                case 'M':
                case 'm':
-                       val = 0;
+                       if ((val == 0) || (val == HALFDAY))
+                               val = 0;
+                       else
+                               val = FULLDAY+1;  /* illegal */
                        break;
 
 
                        break;
 
 
@@ -908,8 +890,8 @@ struct times *attime;
                fprintf(stderr, "illegal minute field\n");
                exit(1);
        }
                fprintf(stderr, "illegal minute field\n");
                exit(1);
        }
-       attime->hour = val/100;
-       attime->min = val%100;
+       attime->hour = val/HOUR;
+       attime->min = val%HOUR;
 }
 
 /*
 }
 
 /*
@@ -944,8 +926,7 @@ cleanup()
  */
 usage()
 {
  */
 usage()
 {
-       fprintf(stderr,"usage: at [-c] [-s] [-m] ");
-       fprintf(stderr,"time [filename]\n");
+       fprintf(stderr,"usage: at [-csm] time [date] [filename]\n");
        exit(1);
 }
 
        exit(1);
 }
 
index 117382c..c14f7ce 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.2 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -51,7 +51,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 +73,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 +101,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;
        }
@@ -259,17 +259,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 +285,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 +294,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;
@@ -465,7 +466,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 +476,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;
index b60b8d3..9195690 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)atrm.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)atrm.c     5.2 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -75,13 +75,12 @@ char **argv;
 
        /*
         * Process command line flags.
 
        /*
         * Process command line flags.
+        * Special case the "-" option so that others may be grouped.
         */
         */
-       while (**argv == '-') {
-               (*argv)++;
-               switch (**argv) {
-
-                       case '\0':      ++allflag;
-                                       break;
+       while (argc > 0 && **argv == '-') {
+               if (*(++(*argv)) == '\0') {
+                       ++allflag;
+               } else while (**argv) switch (*(*argv)++) {
 
                        case 'f':       ++fflag;
                                        break;
 
                        case 'f':       ++fflag;
                                        break;
@@ -159,7 +158,7 @@ char **argv;
                for (i = 0; i < numjobs; ++i) { 
                        if (user == SUPERUSER || isowner(getname(user),
                                                        namelist[i]->d_name)) 
                for (i = 0; i < numjobs; ++i) { 
                        if (user == SUPERUSER || isowner(getname(user),
                                                        namelist[i]->d_name)) 
-                               removentry(namelist[i]->d_name,
+                               (void) removentry(namelist[i]->d_name,
                                                (int)stbuf[i]->st_ino,
                                                        user);
                }
                                                (int)stbuf[i]->st_ino,
                                                        user);
                }
@@ -186,6 +185,10 @@ char **argv;
                isuname = isusername(*argv);
                for (i = 0; i < numjobs; ++i) {
 
                isuname = isusername(*argv);
                for (i = 0; i < numjobs; ++i) {
 
+                       /* if the inode number is 0, this entry was removed */
+                       if (stbuf[i]->st_ino == 0)
+                               continue;
+
                        /* 
                         * if argv is a username, compare his/her uid to
                         * the uid of the owner of the file......
                        /* 
                         * if argv is a username, compare his/her uid to
                         * the uid of the owner of the file......
@@ -203,15 +206,21 @@ char **argv;
                                        continue;
                        }
                        ++jobexists;
                                        continue;
                        }
                        ++jobexists;
-                       removentry(namelist[i]->d_name, (int)stbuf[i]->st_ino,
-                                       user);
+                       /*
+                        * if the entry is ultimately removed, don't
+                        * try to remove it again later.
+                        */
+                       if (removentry(namelist[i]->d_name,
+                           (int)stbuf[i]->st_ino, user)) {
+                               stbuf[i]->st_ino = 0;
+                       }
                }
 
                /*
                 * If a requested argument doesn't exist, print a message.
                 */
                if (!jobexists && !fflag && !isuname) {
                }
 
                /*
                 * If a requested argument doesn't exist, print a message.
                 */
                if (!jobexists && !fflag && !isuname) {
-                       printf("%6s: no such job number\n", *argv);
+                       fprintf(stderr, "%6s: no such job number\n", *argv);
                }
                ++argv;
        }
                }
                ++argv;
        }
@@ -271,8 +280,9 @@ char *string;
  * check (either "permission denied" or "removed"). If we are running 
  * interactively (iflag), prompt the user before we unlink the file. If 
  * the super-user is removing jobs, inform him/her who owns each file before 
  * check (either "permission denied" or "removed"). If we are running 
  * interactively (iflag), prompt the user before we unlink the file. If 
  * the super-user is removing jobs, inform him/her who owns each file before 
- * it is removed.
+ * it is removed.  Return TRUE if file removed, else FALSE.
  */
  */
+int
 removentry(filename,inode,user)
 char *filename;
 int inode;
 removentry(filename,inode,user)
 char *filename;
 int inode;
@@ -287,28 +297,29 @@ int user;
                if (!fflag) {
                        printf("permission denied\n");
                }
                if (!fflag) {
                        printf("permission denied\n");
                }
+               return (0);
 
        } else {
                if (iflag) {
                        if (user == SUPERUSER) {
                                printf("\t(owned by ");
                                powner(filename);
 
        } else {
                if (iflag) {
                        if (user == SUPERUSER) {
                                printf("\t(owned by ");
                                powner(filename);
-                               printf(")");
+                               printf(") ");
                        }
                        printf("remove it? ");
                        if (!yes())
                        }
                        printf("remove it? ");
                        if (!yes())
-                               return;
+                               return (0);
                }
                if (unlink(filename) < 0) {
                        if (!fflag) {
                }
                if (unlink(filename) < 0) {
                        if (!fflag) {
-                               fputs("FATAL ERROR (unlink fails): ",stdout);
-                               fflush(stdout);
+                               fputs("could not remove\n", stdout);
                                perror(filename);
                        }
                                perror(filename);
                        }
-                       return;
+                       return (0);
                }
                if (!fflag && !iflag)
                        printf("removed\n");
                }
                if (!fflag && !iflag)
                        printf("removed\n");
+               return (1);
        }
 }
 
        }
 }
 
@@ -319,22 +330,22 @@ 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);
        }
 
-       close(infile);
+       fclose(infile);
        return((strcmp(name,buf) == 0) ? 1 : 0);
 }
 
        return((strcmp(name,buf) == 0) ? 1 : 0);
 }
 
@@ -345,7 +356,7 @@ char *job;
 powner(file)
 char *file;
 {
 powner(file)
 char *file;
 {
-       char owner[80];                         /* the owner */
+       char owner[128];                        /* the owner */
        FILE *infile;                           /* I/O stream to spoolfile */
 
        /*
        FILE *infile;                           /* I/O stream to spoolfile */
 
        /*
@@ -358,9 +369,8 @@ char *file;
                return;
        }
 
                return;
        }
 
-       if (fscanf(infile,"# owner: %s",owner) != 1) {
+       if (fscanf(infile,"# owner: %127s%*[^\n]\n",owner) != 1) {
                printf("%s","???");
                printf("%s","???");
-               perror(file);
                fclose(infile);
                return;
        }
                fclose(infile);
                return;
        }
@@ -382,6 +392,8 @@ yes()
        ch = ch1 = getchar();
        while (ch1 != '\n' && ch1 != EOF)
                ch1 = getchar();
        ch = ch1 = getchar();
        while (ch1 != '\n' && ch1 != EOF)
                ch1 = getchar();
+       if (isupper(ch))
+               ch = tolower(ch);
        return(ch == 'y');
 }
 
        return(ch == 'y');
 }
 
index a51d8b5..ecfd557 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)atrun.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)atrun.c    5.4 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -32,7 +32,9 @@ static char sccsid[] = "@(#)atrun.c   5.3 (Berkeley) %G%";
 # include <sys/file.h>
 # include <sys/time.h>
 # include <sys/param.h>
 # include <sys/file.h>
 # include <sys/time.h>
 # include <sys/param.h>
+#ifdef notdef
 # include <sys/quota.h>
 # include <sys/quota.h>
+#endif
 # include <sys/stat.h>
 # include <pwd.h>
 
 # include <sys/stat.h>
 # include <pwd.h>
 
@@ -148,8 +150,8 @@ char *spoolfile;
        char mailvar[4];                /* send mail variable ("yes" or "no") */
        char runfile[100];              /* file sent to forked shell for exec-
                                           ution */
        char mailvar[4];                /* send mail variable ("yes" or "no") */
        char runfile[100];              /* file sent to forked shell for exec-
                                           ution */
-       char owner[16];                 /* owner of job we're going to run */
-       char jobname[100];              /* name of job we're going to run */
+       char owner[128];                /* owner of job we're going to run */
+       char jobname[128];              /* name of job we're going to run */
        char whichshell[100];           /* which shell should we fork off? */
        struct passwd *pwdbuf;          /* password info of the owner of job */
        struct stat errbuf;             /* stats on error file */
        char whichshell[100];           /* which shell should we fork off? */
        struct passwd *pwdbuf;          /* password info of the owner of job */
        struct stat errbuf;             /* stats on error file */
@@ -172,12 +174,17 @@ char *spoolfile;
        }
 
        /*
        }
 
        /*
-        * Grab the 3-line header out of the spoolfile.
+        * Grab the 4-line header out of the spoolfile.
         */
         */
-       fscanf(infile,"# owner: %s\n",owner);
-       fscanf(infile,"# jobname: %s\n",jobname);
-       fscanf(infile,"# shell: %s\n",shell);
-       fscanf(infile,"# notify by mail: %s\n",mailvar);
+       if (
+           (fscanf(infile,"# owner: %127s%*[^\n]\n",owner) != 1) ||
+           (fscanf(infile,"# jobname: %127s%*[^\n]\n",jobname) != 1) ||
+           (fscanf(infile,"# shell: %3s%*[^\n]\n",shell) != 1) ||
+           (fscanf(infile,"# notify by mail: %3s%*[^\n]\n",mailvar) != 1)
+           ) {
+               fprintf(stderr, "%s: bad spool header\n", spoolfile);
+               exit(1);
+       }
 
        /*
         * Check to see if we should send mail to the owner.
 
        /*
         * Check to see if we should send mail to the owner.
@@ -190,6 +197,11 @@ char *spoolfile;
         * of the job.
         */
        pwdbuf = getpwnam(owner);
         * of the job.
         */
        pwdbuf = getpwnam(owner);
+       if (pwdbuf == NULL) {
+               fprintf(stderr, "%s: could not find owner in passwd file\n",
+                   spoolfile);
+               exit(1);
+       }
        if (chown(spoolfile,pwdbuf->pw_uid,pwdbuf->pw_gid) == -1) {
                perror(spoolfile);
                exit(1);
        if (chown(spoolfile,pwdbuf->pw_uid,pwdbuf->pw_gid) == -1) {
                perror(spoolfile);
                exit(1);
@@ -297,7 +309,10 @@ char *spoolfile;
        /*
         * Run the job as the owner of the jobfile
         */
        /*
         * Run the job as the owner of the jobfile
         */
+#ifdef notdef
+       /* This is no longer needed with the new, stripped-down quota system */
        quota(Q_SETUID,jobbuf.st_uid,0,0);
        quota(Q_SETUID,jobbuf.st_uid,0,0);
+#endif
        setgid(jobbuf.st_gid);
        initgroups(getname(jobbuf.st_uid),jobbuf.st_gid);
        setuid(jobbuf.st_uid);
        setgid(jobbuf.st_gid);
        initgroups(getname(jobbuf.st_uid),jobbuf.st_gid);
        setuid(jobbuf.st_uid);