Hi Austin,

Austin Hook wrote on Mon, Oct 05, 2009 at 12:55:11PM -0700:

[ citations reordered ]

> $ echo echo hello >ee
> $ batch -f ee
> Cannot open input file: No such file or directory

That looks like a bug to me.

The function main() in at.c calls set_cron_cwd(), changing to /var/cron,
before opening the job file.

Unless i'm quite mistaken, batch(1), at(1) and atq(1) read nothing
from stdin(4) except the commands to execute, so i see no point
in first saving the input file name to a variable and deferring
the call to freopen(3).

Actually, the following patch saves one global and one local variable
and simplifies the code, in addition to fixing your problem.

> According to the man pages for "at" (or batch):
> 
>      The working directory, the environment (except for the variables
>      TERM, TERMCAP, DISPLAY, and _), and the umask are retained from the
>      time of invocation.

Right, but that applies to job execution time, not to command line
parsing.  Relative paths on the command line ought to be used
before changing directory in any case.

Any OKs to commit the following patch?
  Ingo


Index: at.c
===================================================================
RCS file: /cvs/src/usr.bin/at/at.c,v
retrieving revision 1.54
diff -u -p -r1.54 at.c
--- at.c        5 Sep 2007 08:02:21 -0000       1.54
+++ at.c        5 Oct 2009 20:02:49 -0000
@@ -55,7 +55,6 @@ char *no_export[] =
 int program = AT;              /* default program mode */
 char atfile[MAX_FNAME];                /* path to the at spool file */
 int fcreated;                  /* whether or not we created the file yet */
-char *atinput = NULL;          /* where to get input from */
 char atqueue = 0;              /* which queue to examine for jobs (atq) */
 char vflag = 0;                        /* show completed but unremoved jobs 
(atq) */
 char force = 0;                        /* suppress errors (atrm) */
@@ -189,7 +188,7 @@ writefile(const char *cwd, time_t runtim
        struct passwd *pass_entry;
        struct tm runtime;
        int fdes, lockdes, fd2;
-       FILE *fp, *fpin;
+       FILE *fp;
        struct sigaction act;
        char **atenv;
        int ch;
@@ -290,11 +289,6 @@ writefile(const char *cwd, time_t runtim
                        shell = _PATH_BSHELL;
        }
 
-       if (atinput != NULL) {
-               fpin = freopen(atinput, "r", stdin);
-               if (fpin == NULL)
-                       perr("Cannot open input file");
-       }
        (void)fprintf(fp, "#!/bin/sh\n# atrun uid=%lu gid=%lu\n# mail %*s %d\n",
            (unsigned long)real_uid, (unsigned long)real_gid,
            MAX_UNAME, mailname, send_mail);
@@ -990,8 +984,8 @@ main(int argc, char **argv)
                        if (program == ATRM) {
                                force = 1;
                                interactive = 0;
-                       } else
-                               atinput = optarg;
+                       } else if (freopen(optarg, "r", stdin) == NULL)
+                               perr("Cannot open input file");
                        break;
 
                case 'q':       /* specify queue */

Reply via email to