On Tue, Feb 06, 2018 at 11:22:52AM -0600, Scott Cheloha wrote:
> 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?
I'm fine with your idea but...
>
> --
> 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 */
This doesn't work here, it fires at around :39 seconds in NZDT
secs -= t->tm_sec;
probably works better if you're aiming for the beginning of the minute
in the current timezone.
> }
> 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.");
>