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