diff options
author | 2016-01-11 14:23:50 +0000 | |
---|---|---|
committer | 2016-01-11 14:23:50 +0000 | |
commit | 95f2b4e27a8d61b0f9dbd624f26f2fa6fc6bc691 (patch) | |
tree | b774c706165c11d514e0afc33db7592fd59c9819 | |
parent | Only include sdhc_acpi.c if shdc* at acpi? is included in the kernel config. (diff) | |
download | wireguard-openbsd-95f2b4e27a8d61b0f9dbd624f26f2fa6fc6bc691.tar.xz wireguard-openbsd-95f2b4e27a8d61b0f9dbd624f26f2fa6fc6bc691.zip |
When caching the mtime of the spool directory and system crontab files,
stash a struct timespec, not just a time_t. Fixes a bug where cron
could skip re-reading the spool after two consecutive changes.
-rw-r--r-- | usr.sbin/cron/atrun.c | 7 | ||||
-rw-r--r-- | usr.sbin/cron/cron.c | 7 | ||||
-rw-r--r-- | usr.sbin/cron/crontab.c | 3 | ||||
-rw-r--r-- | usr.sbin/cron/database.c | 25 | ||||
-rw-r--r-- | usr.sbin/cron/structs.h | 8 |
5 files changed, 30 insertions, 20 deletions
diff --git a/usr.sbin/cron/atrun.c b/usr.sbin/cron/atrun.c index 95f6fbe70ba..78798b960ff 100644 --- a/usr.sbin/cron/atrun.c +++ b/usr.sbin/cron/atrun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: atrun.c,v 1.42 2015/11/17 22:31:44 millert Exp $ */ +/* $OpenBSD: atrun.c,v 1.43 2016/01/11 14:23:50 millert Exp $ */ /* * Copyright (c) 2002-2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -23,6 +23,7 @@ #include <sys/types.h> #include <sys/resource.h> #include <sys/stat.h> +#include <sys/time.h> #include <sys/wait.h> #include <bitstring.h> /* for structs.h */ @@ -91,7 +92,7 @@ scan_atjobs(at_db **db, struct timespec *ts) close(dfd); return (0); } - if (old_db != NULL && old_db->mtime == sb.st_mtime) { + if (old_db != NULL && timespeccmp(&old_db->mtime, &sb.st_mtim, ==)) { close(dfd); return (0); } @@ -106,7 +107,7 @@ scan_atjobs(at_db **db, struct timespec *ts) closedir(atdir); return (0); } - new_db->mtime = sb.st_mtime; /* stash at dir mtime */ + new_db->mtime = sb.st_mtim; /* stash at dir mtime */ TAILQ_INIT(&new_db->jobs); pending = 0; diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c index ab36fdaefa9..57262e8d296 100644 --- a/usr.sbin/cron/cron.c +++ b/usr.sbin/cron/cron.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cron.c,v 1.73 2015/11/15 23:24:24 millert Exp $ */ +/* $OpenBSD: cron.c,v 1.74 2016/01/11 14:23:50 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -20,6 +20,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> +#include <sys/time.h> #include <sys/un.h> #include <sys/wait.h> @@ -373,7 +374,7 @@ cron_sleep(time_t target, sigset_t *mask) (void) read(fd, &poke, 1); close(fd); if (poke & RELOAD_CRON) { - database->mtime = 0; + timespecclear(&database->mtime); load_database(&database); } if (poke & RELOAD_AT) { @@ -383,7 +384,7 @@ cron_sleep(time_t target, sigset_t *mask) * jobs immediately. */ clock_gettime(CLOCK_REALTIME, &t2); - at_database->mtime = 0; + timespecclear(&at_database->mtime); if (scan_atjobs(&at_database, &t2)) atrun(at_database, batch_maxload, t2.tv_sec); diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c index ce26afc493a..d22aae2538d 100644 --- a/usr.sbin/cron/crontab.c +++ b/usr.sbin/cron/crontab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crontab.c,v 1.91 2015/11/17 21:56:57 millert Exp $ */ +/* $OpenBSD: crontab.c,v 1.92 2016/01/11 14:23:50 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -19,6 +19,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/time.h> #include <sys/wait.h> #include <bitstring.h> /* for structs.h */ diff --git a/usr.sbin/cron/database.c b/usr.sbin/cron/database.c index 7be6df68f9c..6fe1a0d2ee3 100644 --- a/usr.sbin/cron/database.c +++ b/usr.sbin/cron/database.c @@ -1,4 +1,4 @@ -/* $OpenBSD: database.c,v 1.33 2015/11/14 13:09:14 millert Exp $ */ +/* $OpenBSD: database.c,v 1.34 2016/01/11 14:23:50 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -19,6 +19,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/time.h> #include <bitstring.h> /* for structs.h */ #include <dirent.h> @@ -47,6 +48,7 @@ load_database(cron_db **db) { struct stat statbuf, syscron_stat; cron_db *new_db, *old_db = *db; + struct timespec mtime; struct dirent *dp; DIR *dir; user *u; @@ -63,15 +65,20 @@ load_database(cron_db **db) /* track system crontab file */ if (stat(_PATH_SYS_CRONTAB, &syscron_stat) < 0) - syscron_stat.st_mtime = 0; + timespecclear(&syscron_stat.st_mtim); + + /* hash mtime of system crontab file and crontab dir + */ + mtime.tv_sec = + HASH(statbuf.st_mtim.tv_sec, syscron_stat.st_mtim.tv_sec); + mtime.tv_nsec = + HASH(statbuf.st_mtim.tv_nsec, syscron_stat.st_mtim.tv_nsec); /* if spooldir's mtime has not changed, we don't need to fiddle with * the database. */ - if (old_db != NULL && - old_db->mtime == HASH(statbuf.st_mtime, syscron_stat.st_mtime)) { + if (old_db != NULL && timespeccmp(&mtime, &old_db->mtime, ==)) return; - } /* something's different. make a new database, moving unchanged * elements from the old database, reloading elements that have @@ -80,10 +87,10 @@ load_database(cron_db **db) */ if ((new_db = malloc(sizeof(*new_db))) == NULL) return; - new_db->mtime = HASH(statbuf.st_mtime, syscron_stat.st_mtime); + new_db->mtime = mtime; TAILQ_INIT(&new_db->users); - if (syscron_stat.st_mtime) { + if (timespecisset(&syscron_stat.st_mtim)) { process_crontab(AT_FDCWD, "*system*", _PATH_SYS_CRONTAB, &syscron_stat, new_db, old_db); } @@ -212,7 +219,7 @@ process_crontab(int dfd, const char *uname, const char *fname, /* if crontab has not changed since we last read it * in, then we can just use our existing entry. */ - if (u->mtime == statbuf->st_mtime) { + if (timespeccmp(&u->mtime, &statbuf->st_mtim, ==)) { TAILQ_REMOVE(&old_db->users, u, entries); TAILQ_INSERT_TAIL(&new_db->users, u, entries); goto next_crontab; @@ -231,7 +238,7 @@ process_crontab(int dfd, const char *uname, const char *fname, } u = load_user(crontab_fd, pw, fname); if (u != NULL) { - u->mtime = statbuf->st_mtime; + u->mtime = statbuf->st_mtim; TAILQ_INSERT_TAIL(&new_db->users, u, entries); } diff --git a/usr.sbin/cron/structs.h b/usr.sbin/cron/structs.h index e9e73816b00..af0d75c3b55 100644 --- a/usr.sbin/cron/structs.h +++ b/usr.sbin/cron/structs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: structs.h,v 1.7 2015/11/09 01:12:27 millert Exp $ */ +/* $OpenBSD: structs.h,v 1.8 2016/01/11 14:23:50 millert Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -50,13 +50,13 @@ typedef struct _entry { typedef struct _user { TAILQ_ENTRY(_user) entries; /* links */ char *name; - time_t mtime; /* last modtime of crontab */ + struct timespec mtime; /* last modtime of crontab */ SLIST_HEAD(crontab_list, _entry) crontab; /* this person's crontab */ } user; typedef struct _cron_db { TAILQ_HEAD(user_list, _user) users; - time_t mtime; /* last modtime on spooldir */ + struct timespec mtime; /* last modtime on spooldir */ } cron_db; typedef struct _atjob { @@ -69,5 +69,5 @@ typedef struct _atjob { typedef struct _at_db { TAILQ_HEAD(atjob_list, _atjob) jobs; - time_t mtime; /* last modtime on spooldir */ + struct timespec mtime; /* last modtime on spooldir */ } at_db; |