Blob Blame History Raw
diff -up at-3.1.13/atd.c.clear-nonjobs at-3.1.13/atd.c
--- at-3.1.13/atd.c.clear-nonjobs	2016-04-20 17:15:00.579327865 +0200
+++ at-3.1.13/atd.c	2016-04-20 17:18:06.215376744 +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);