diff options
Diffstat (limited to 'contrib/tzcode/localtime.c')
-rw-r--r-- | contrib/tzcode/localtime.c | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/contrib/tzcode/localtime.c b/contrib/tzcode/localtime.c index f5814a43da54..a6ec3d8e4e21 100644 --- a/contrib/tzcode/localtime.c +++ b/contrib/tzcode/localtime.c @@ -18,6 +18,7 @@ #ifndef DETECT_TZ_CHANGES_INTERVAL #define DETECT_TZ_CHANGES_INTERVAL 61 #endif +int __tz_change_interval = DETECT_TZ_CHANGES_INTERVAL; #include <sys/stat.h> #endif #include <fcntl.h> @@ -408,10 +409,8 @@ change_in_tz(const char *name) static char old_name[PATH_MAX]; static struct stat old_sb; struct stat sb; - int error; - error = stat(name, &sb); - if (error != 0) + if (stat(name, &sb) != 0) return -1; if (strcmp(name, old_name) != 0) { @@ -510,13 +509,13 @@ tzloadbody(char const *name, struct state *sp, bool doextend, * 'doextend' to ignore TZDEFRULES; the change_in_tz() * function can only keep state for a single file. */ - int ret = change_in_tz(name); - if (ret <= 0) { - /* - * Returns an errno value if there was an error, - * and 0 if the timezone had not changed. - */ + switch (change_in_tz(name)) { + case -1: return errno; + case 0: + return 0; + case 1: + break; } } fid = _open(name, O_RDONLY | O_BINARY); @@ -1376,22 +1375,13 @@ recheck_tzdata() { static time_t last_checked; struct timespec now; - time_t current_time; - int error; - /* - * We want to recheck the timezone file every 61 sec. - */ - error = clock_gettime(CLOCK_MONOTONIC, &now); - if (error < 0) { - /* XXX: Can we somehow report this? */ + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) return 0; - } - current_time = now.tv_sec; - if ((current_time - last_checked > DETECT_TZ_CHANGES_INTERVAL) || - (last_checked > current_time)) { - last_checked = current_time; + if ((now.tv_sec - last_checked >= __tz_change_interval) || + (last_checked > now.tv_sec)) { + last_checked = now.tv_sec; return 1; } |