diff -up at-3.1.16/atd.c.clear-nonjobs at-3.1.16/atd.c
--- at-3.1.16/atd.c.clear-nonjobs 2014-12-11 10:32:24.000000000 +0100
+++ at-3.1.16/atd.c 2015-09-09 11:40:22.544679351 +0200
@@ -414,10 +414,22 @@ run_file(const char *filename, uid_t uid
sprintf(fmt, "#!/bin/sh\n# atrun uid=%%d gid=%%d\n# mail %%%ds %%d",
mailsize );
+ /* Unlink the file unless there was an error reading it (perhaps
+ * temporary).
+ * If the file has a bogus format there is no reason in trying
+ * to run it again and again.
+ */
if (fscanf(stream, fmt,
- &nuid, &ngid, mailname, &send_mail) != 4)
- pabort("File %.500s is in wrong format - aborting",
- filename);
+ &nuid, &ngid, mailname, &send_mail) != 4) {
+ if (ferror(stream))
+ perr("Error reading the job file");
+
+ unlink(filename);
+ pabort("File %.500s is in wrong format - aborting",
+ filename);
+ }
+
+ unlink(filename);
if (mailname[0] == '-')
pabort("illegal mail name %.300s in job %8lu (%.300s)", mailname,
@@ -427,12 +439,6 @@ run_file(const char *filename, uid_t uid
pabort("Job %8lu (%.500s) - userid %d does not match file uid %d",
jobno, filename, nuid, uid);
- /* We are now committed to executing this script. Unlink the
- * original.
- */
-
- unlink(filename);
-
fclose(stream);
if (chdir(ATSPOOL_DIR) < 0)
perr("Cannot chdir to " ATSPOOL_DIR);