summaryrefslogtreecommitdiff
path: root/usr.sbin/cron/misc.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-02-19 14:33:34 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-02-19 14:33:34 +0000
commit04609c6ee5fd12235dc5fc6072e88a28c7e843d9 (patch)
tree9d0a1c4a333c9b4b93de6b6e11a882ab9743a8c0 /usr.sbin/cron/misc.c
parent3e1b8517b46b8cee2477f082a9a3d883b85ce2fa (diff)
Normalize the time in minutes to GMT so we can really catch DST changes
(since time() does not change during a DST switch). This makes cron correctly detect DST changes. It does not fix the problem of wildcard jobs running multiple times. Also, don't rely on tm_gmtoff since that is non-standard (but use it when we have it).
Diffstat (limited to 'usr.sbin/cron/misc.c')
-rw-r--r--usr.sbin/cron/misc.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c
index 07ca1452e0c..7764aeb9fd2 100644
--- a/usr.sbin/cron/misc.c
+++ b/usr.sbin/cron/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.8 2001/02/18 19:48:35 millert Exp $ */
+/* $OpenBSD: misc.c,v 1.9 2001/02/19 14:33:33 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +21,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: misc.c,v 1.8 2001/02/18 19:48:35 millert Exp $";
+static char rcsid[] = "$OpenBSD: misc.c,v 1.9 2001/02/19 14:33:33 millert Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
@@ -692,8 +692,9 @@ arpadate(clock)
static char ret[64]; /* zone name might be >3 chars */
char *qmark;
size_t len;
- int hours = tm->tm_gmtoff / 3600;
- int minutes = (tm->tm_gmtoff - (hours * 3600)) / 60;
+ long gmtoff = get_gmtoff(&t);
+ int hours = gmtoff / 3600;
+ int minutes = (gmtoff - (hours * 3600)) / 60;
if (minutes < 0)
minutes = -minutes;
@@ -722,3 +723,40 @@ int swap_uids_back() { return (seteuid(save_euid)); }
int swap_uids() { return (setreuid(geteuid(), getuid())); }
int swap_uids_back() { return (swap_uids()); }
#endif /*HAVE_SAVED_UIDS*/
+
+/* Return the offset from GMT in seconds (algorithm taken from sendmail). */
+#ifdef HAVE_TM_GMTOFF
+long get_gmtoff(time_t *clock)
+{
+ struct tm *tm;
+
+ tm = localtime(clock);
+ return (tm->tm_gmtoff);
+}
+#else
+long get_gmtoff(time_t *clock)
+{
+ struct tm local;
+ struct tm *gmt;
+ long offset;
+
+ local = *localtime(clock);
+ gmt = gmtime(clock);
+
+ offset = (local.tm_sec - gmt->tm_sec) +
+ ((local.tm_min - gmt->tm_min) * 60) +
+ ((local.tm_hour - gmt->tm_hour) * 3600);
+
+ /* Timezone may cause year rollover to happen on a different day. */
+ if (local.tm_year < gmt->tm_year)
+ offset -= 24 * 3600;
+ else if (local.tm_year > gmt->tm_year)
+ offset -= 24 * 3600;
+ else if (local.tm_yday < gmt->tm_yday)
+ offset -= 24 * 3600;
+ else if (local.tm_yday > gmt->tm_yday)
+ offset += 24 * 3600;
+
+ return (offset);
+}
+#endif /* HAVE_TM_GMTOFF */