diff options
author | 2018-06-25 15:22:30 +0000 | |
---|---|---|
committer | 2018-06-25 15:22:30 +0000 | |
commit | 36de39ea5cd89e3095fc7f46ee95e75a7b641f2f (patch) | |
tree | 339d5e8c27b0203859147ac4806e5bef6a711419 | |
parent | Fix a kernelpanic when using rdomain(4) and enc(4) (diff) | |
download | wireguard-openbsd-36de39ea5cd89e3095fc7f46ee95e75a7b641f2f.tar.xz wireguard-openbsd-36de39ea5cd89e3095fc7f46ee95e75a7b641f2f.zip |
Count $MAILCHECK with the monotonic clock.
So that ksh still looks for new mail every $MAILCHECK seconds,
even if the system clock is rolled backward.
ok anton@
-rw-r--r-- | bin/ksh/mail.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/bin/ksh/mail.c b/bin/ksh/mail.c index 0f38541c5f1..f4b31e0c3bf 100644 --- a/bin/ksh/mail.c +++ b/bin/ksh/mail.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mail.c,v 1.23 2018/04/09 17:53:36 tobias Exp $ */ +/* $OpenBSD: mail.c,v 1.24 2018/06/25 15:22:30 cheloha Exp $ */ /* * Mailbox checking code by Robert J. Gibson, adapted for PD ksh by @@ -6,6 +6,7 @@ */ #include <sys/stat.h> +#include <sys/time.h> #include <string.h> #include <time.h> @@ -30,7 +31,7 @@ typedef struct mbox { static mbox_t *mplist; static mbox_t mbox; -static time_t mlastchkd; /* when mail was last checked */ +static struct timespec mlastchkd; /* when mail was last checked */ static time_t mailcheck_interval; static void munset(mbox_t *); /* free mlist and mval */ @@ -41,14 +42,18 @@ void mcheck(void) { mbox_t *mbp; - time_t now; + struct timespec elapsed, now; struct tbl *vp; struct stat stbuf; + static int first = 1; - now = time(NULL); - if (mlastchkd == 0) + clock_gettime(CLOCK_MONOTONIC, &now); + if (first) { mlastchkd = now; - if (now - mlastchkd >= mailcheck_interval) { + first = 0; + } + timespecsub(&now, &mlastchkd, &elapsed); + if (elapsed.tv_sec >= mailcheck_interval) { mlastchkd = now; if (mplist) |