about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-11-04 17:10:02 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-11-04 17:10:02 +0100
commita99b4704518369ebf6606b6a1a271c5cfd21bd5e (patch)
tree69eda53ccc66a65afa441d6f29fb5176f8277e54
parent8c8217eebd8bc6f196b493dba4d815b1873478f0 (diff)
downloadsnooze-a99b4704518369ebf6606b6a1a271c5cfd21bd5e.tar.gz
snooze-a99b4704518369ebf6606b6a1a271c5cfd21bd5e.tar.xz
snooze-a99b4704518369ebf6606b6a1a271c5cfd21bd5e.zip
Take slack into account when using -t without -T
-rw-r--r--snooze.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/snooze.c b/snooze.c
index b88db77..a5df967 100644
--- a/snooze.c
+++ b/snooze.c
@@ -31,7 +31,7 @@ static long slack = 60;
 #define SLEEP_PHASE 300
 static int nflag, vflag;
 
-static int timewait = 1;
+static int timewait = -1;
 static int randdelay = 0;
 static char *timefile;
 
@@ -200,6 +200,7 @@ isotime(const struct tm *tm)
 int main(int argc, char *argv[])
 {
 	int c;
+	time_t t;
 	time_t now = time(0);
 
 	/* default: every day at 00:00:00 */
@@ -248,8 +249,16 @@ int main(int argc, char *argv[])
 		if (stat(timefile, &st) < 0) {
 			if (errno != ENOENT)
 				perror("stat");
+			t = start - slack - 1 - timewait;
+		} else {
+			t = st.st_mtime;
+		}
+		if (timewait == -1) {
+			while (t < start - slack)
+				t = find_next(t + 1);
+			start = t;
 		} else {
-			if (st.st_mtime + timewait > start)
+			if (t + timewait > start)
 				start = st.st_mtime + timewait;
 		}
 	}
@@ -271,7 +280,7 @@ int main(int argc, char *argv[])
 		start += delay;
 	}
 
-	time_t t = find_next(start);
+	t = find_next(start);
 	if (t < 0) {
 		fprintf(stderr, "no satisfying date found within a year.\n");
 		exit(2);