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