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