Hi,
When I schedule an alarm for an absolute time with minute granularity,
I expect the alarm to go off at the beginning of that minute.
So, this:
leave 1430
should go off at 14:30:00.
The two-second sleep in the child of doalarm() confounds this, but I
have a subsequent diff that refactors that function to obviate it.
ok?
--
Scott Cheloha
Index: usr.bin/leave/leave.c
===================================================================
RCS file: /cvs/src/usr.bin/leave/leave.c,v
retrieving revision 1.17
diff -u -p -r1.17 leave.c
--- usr.bin/leave/leave.c 9 Oct 2015 01:37:08 -0000 1.17
+++ usr.bin/leave/leave.c 6 Feb 2018 16:58:45 -0000
@@ -113,6 +113,7 @@ main(int argc, char *argv[])
secs = (hours - t->tm_hour) * HOUR;
secs += (minutes - t->tm_min) * MINUTE;
+ secs -= now % 60; /* aim for beginning of minute */
}
doalarm(secs);
exit(0);
@@ -155,12 +156,16 @@ doalarm(u_int secs)
sleep(secs - MINUTE);
if (puts("\a\aJust one more minute!") == EOF)
exit(0);
+ secs = MINUTE;
}
+ sleep(secs);
+
for (bother = 10; bother--;) {
- sleep(MINUTE);
if (puts("\a\aTime to leave!") == EOF)
exit(0);
+ if (bother)
+ sleep(MINUTE);
}
puts("\a\aThat was the last time I'll tell you. Bye.");