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