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