summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2001-02-20 02:03:19 +0000
committermillert <millert@openbsd.org>2001-02-20 02:03:19 +0000
commit40616cea116449c44d725c7f5abb37cd09f73a18 (patch)
tree8b2fb09119a0d14136e2231ef515897ed4ff5d20
parentuse void * consistently in vfs_mount and sys_mount. ok @art (diff)
downloadwireguard-openbsd-40616cea116449c44d725c7f5abb37cd09f73a18.tar.xz
wireguard-openbsd-40616cea116449c44d725c7f5abb37cd09f73a18.zip
Turn get_gmtoff into a macro for OSes with tm_gmtoff (like OpenBSD).
Save the GMT offset in a global so cron_sleep can use it. This means the offset can only change in set_time() which is really what we want.
-rw-r--r--usr.sbin/cron/cron.c15
-rw-r--r--usr.sbin/cron/funcs.h6
-rw-r--r--usr.sbin/cron/macros.h6
-rw-r--r--usr.sbin/cron/misc.c40
4 files changed, 31 insertions, 36 deletions
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index b12cb33fc82..3ada164920a 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cron.c,v 1.11 2001/02/19 14:33:32 millert Exp $ */
+/* $OpenBSD: cron.c,v 1.12 2001/02/20 02:03:19 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: cron.c,v 1.11 2001/02/19 14:33:32 millert Exp $";
+static char rcsid[] = "$OpenBSD: cron.c,v 1.12 2001/02/20 02:03:19 millert Exp $";
#endif
#define MAIN_PROGRAM
@@ -40,6 +40,7 @@ static void usage(void),
static int got_sighup, got_sigchld;
static int timeRunning, virtualTime, clockTime;
+static long GMToff;
static void
usage(void) {
@@ -314,7 +315,6 @@ find_jobs(int vtime, cron_db *db, int doWild, int doNonWild) {
static void
set_time(int initialize) {
struct tm *tm;
- static long gmtoff;
static int isdst;
StartTime = time(NULL);
@@ -323,9 +323,9 @@ set_time(int initialize) {
tm = localtime(&StartTime);
if (initialize || tm->tm_isdst != isdst) {
isdst = tm->tm_isdst;
- gmtoff = get_gmtoff(&StartTime);
+ GMToff = get_gmtoff(&StartTime, tm);
}
- clockTime = (StartTime + gmtoff) / (time_t)SECONDS_PER_MINUTE;
+ clockTime = (StartTime + GMToff) / (time_t)SECONDS_PER_MINUTE;
}
/*
@@ -334,12 +334,9 @@ set_time(int initialize) {
static void
cron_sleep(int target) {
time_t t;
- struct tm *tm;
int seconds_to_wait;
- t = time(NULL);
- tm = localtime(&t);
- t += tm->tm_gmtoff;
+ t = time(NULL) + GMToff;
seconds_to_wait = (int)(target * SECONDS_PER_MINUTE - t) + 1;
Debug(DSCH, ("[%ld] Target time=%ld, sec-to-wait=%d\n",
(long)getpid(), (long)target*SECONDS_PER_MINUTE, seconds_to_wait))
diff --git a/usr.sbin/cron/funcs.h b/usr.sbin/cron/funcs.h
index 20ff142b460..96828b63461 100644
--- a/usr.sbin/cron/funcs.h
+++ b/usr.sbin/cron/funcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: funcs.h,v 1.2 2001/02/19 14:33:32 millert Exp $ */
+/* $OpenBSD: funcs.h,v 1.3 2001/02/20 02:03:19 millert Exp $ */
/*
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
@@ -69,4 +69,6 @@ entry *load_entry(FILE *, void (*)(),
FILE *cron_popen(char *, char *, entry *);
-long get_gmtoff(time_t *clock);
+#ifndef HAVE_TM_GMTOFF
+long get_gmtoff(time_t *, struct tm *);
+#endif
diff --git a/usr.sbin/cron/macros.h b/usr.sbin/cron/macros.h
index 8dfae8772f3..a325d2eed6b 100644
--- a/usr.sbin/cron/macros.h
+++ b/usr.sbin/cron/macros.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: macros.h,v 1.1 2001/02/18 19:48:35 millert Exp $ */
+/* $OpenBSD: macros.h,v 1.2 2001/02/20 02:03:19 millert Exp $ */
/*
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
@@ -95,6 +95,10 @@
LineNumber = ln; \
}
+#ifdef HAVE_TM_GMTOFF
+#define get_gmtoff(c, t) (t->tm_gmtoff)
+#endif
+
#define SECONDS_PER_MINUTE 60
#define FIRST_MINUTE 0
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c
index 7764aeb9fd2..fab3335493b 100644
--- a/usr.sbin/cron/misc.c
+++ b/usr.sbin/cron/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.9 2001/02/19 14:33:33 millert Exp $ */
+/* $OpenBSD: misc.c,v 1.10 2001/02/20 02:03:19 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.9 2001/02/19 14:33:33 millert Exp $";
+static char rcsid[] = "$OpenBSD: misc.c,v 1.10 2001/02/20 02:03:19 millert Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
@@ -692,7 +692,7 @@ arpadate(clock)
static char ret[64]; /* zone name might be >3 chars */
char *qmark;
size_t len;
- long gmtoff = get_gmtoff(&t);
+ long gmtoff = get_gmtoff(&t, tm);
int hours = gmtoff / 3600;
int minutes = (gmtoff - (hours * 3600)) / 60;
@@ -725,36 +725,28 @@ 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)
+#ifndef HAVE_TM_GMTOFF
+long get_gmtoff(time_t *clock, struct tm *local)
{
- struct tm *tm;
-
- tm = localtime(clock);
- return (tm->tm_gmtoff);
-}
-#else
-long get_gmtoff(time_t *clock)
-{
- struct tm local;
- struct tm *gmt;
+ struct tm gmt;
long offset;
- local = *localtime(clock);
- gmt = gmtime(clock);
+ gmt = *gmtime(clock);
+ if (local == NULL)
+ local = localtime(clock);
- offset = (local.tm_sec - gmt->tm_sec) +
- ((local.tm_min - gmt->tm_min) * 60) +
- ((local.tm_hour - gmt->tm_hour) * 3600);
+ 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)
+ if (local->tm_year < gmt.tm_year)
offset -= 24 * 3600;
- else if (local.tm_year > gmt->tm_year)
+ else if (local->tm_year > gmt.tm_year)
offset -= 24 * 3600;
- else if (local.tm_yday < gmt->tm_yday)
+ else if (local->tm_yday < gmt.tm_yday)
offset -= 24 * 3600;
- else if (local.tm_yday > gmt->tm_yday)
+ else if (local->tm_yday > gmt.tm_yday)
offset += 24 * 3600;
return (offset);