From 6b66d221d5be5300e7cdcd35e4ce0dc5ec8ca513 Mon Sep 17 00:00:00 2001 From: cheloha Date: Fri, 9 Feb 2018 23:12:13 +0000 Subject: [PATCH] Schedule alarm for start of minute if departure time is absolute. e.g., "leave 1530" goes off closer to 15:30:00. Timezone-related bug caught by tb@ in review. ok tb@ tedu@ --- usr.bin/leave/leave.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/usr.bin/leave/leave.c b/usr.bin/leave/leave.c index ec11d62735a..78abf8eba8b 100644 --- a/usr.bin/leave/leave.c +++ b/usr.bin/leave/leave.c @@ -1,4 +1,4 @@ -/* $OpenBSD: leave.c,v 1.17 2015/10/09 01:37:08 deraadt Exp $ */ +/* $OpenBSD: leave.c,v 1.18 2018/02/09 23:12:13 cheloha Exp $ */ /* $NetBSD: leave.c,v 1.4 1995/07/03 16:50:13 phil Exp $ */ /* @@ -113,6 +113,7 @@ main(int argc, char *argv[]) secs = (hours - t->tm_hour) * HOUR; secs += (minutes - t->tm_min) * MINUTE; + secs -= t->tm_sec; /* 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."); -- 2.20.1