about summary refs log tree commit diff
path: root/snooze.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-11-06 22:45:18 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-11-06 22:46:51 +0100
commit2d8e9f30232d555211f02f1ffc78bd58e6c7308c (patch)
tree10b67c9f160cd4741aeacee494800a60f80ee92f /snooze.c
parentc4aba5783f0f7330e57ba14af32b9246cd72cc70 (diff)
downloadsnooze-2d8e9f30232d555211f02f1ffc78bd58e6c7308c.tar.gz
snooze-2d8e9f30232d555211f02f1ffc78bd58e6c7308c.tar.xz
snooze-2d8e9f30232d555211f02f1ffc78bd58e6c7308c.zip
Reschedule when time moved backwards
Diffstat (limited to 'snooze.c')
-rw-r--r--snooze.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/snooze.c b/snooze.c
index 60f7bff..3a5185d 100644
--- a/snooze.c
+++ b/snooze.c
@@ -230,6 +230,7 @@ int main(int argc, char *argv[])
 	int c;
 	time_t t;
 	time_t now = time(0);
+	time_t last = 0;
 
 	/* default: every day at 00:00:00 */
 	memset(weekday, '*', sizeof weekday);
@@ -348,6 +349,11 @@ int main(int argc, char *argv[])
 
 	while (!alarm_rang) {
 		now = time(0);
+		if (now < last) {
+			t = find_next(now);
+			if (vflag)
+				printf("Time moved backwards, rescheduled for %s\n", isotime(tm));
+		}
 		t = mktime(tm);
 		if (t <= now) {
 			if (now - t <= slack)  // still about time
@@ -365,6 +371,7 @@ int main(int argc, char *argv[])
 			struct timespec ts;
 			ts.tv_nsec = 0;
 			ts.tv_sec = t - now > SLEEP_PHASE ? SLEEP_PHASE : t - now;
+			last = now;
 			nanosleep(&ts, 0);
 			// we just iterate again when this exits early
 		}