76a39a
diff -up at-3.1.20/atd.c.aborted at-3.1.20/atd.c
76a39a
--- at-3.1.20/atd.c.aborted	2017-09-14 15:31:47.971486148 +0200
76a39a
+++ at-3.1.20/atd.c	2017-09-14 15:43:53.506567281 +0200
76a39a
@@ -731,12 +731,17 @@ run_loop()
76a39a
 	/* Is the file already locked?
76a39a
 	 */
76a39a
 	if (buf.st_nlink > 1) {
76a39a
+	    if (run_time < buf.st_mtime)
76a39a
+		run_time = buf.st_mtime;
76a39a
 	    if (run_time + CHECK_INTERVAL <= now) {
76a39a
-
76a39a
 		/* Something went wrong the last time this was executed.
76a39a
 		 * Let's remove the lockfile and reschedule.
76a39a
+		 * We also change the timestamp to avoid rerunning the job more
76a39a
+		 * than once every CHECK_INTERVAL.
76a39a
 		 */
76a39a
 		strncpy(lock_name, dirent->d_name, sizeof(lock_name));
76a39a
+		if (utime(lock_name, 0) < 0)
76a39a
+			syslog(LOG_ERR, "utime couldn't be set for lock file %s\n", lock_name);
76a39a
 		lock_name[sizeof(lock_name)-1] = '\0';
76a39a
 		lock_name[0] = '=';
76a39a
 		unlink(lock_name);