diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-12-20 23:27:48 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-12-20 23:27:48 +0000 |
commit | e80e92555903335e41061ab93155fe9752a124b7 (patch) | |
tree | f1d2fc4dde71b03bf2f1508e312e5917d5474b73 /usr.sbin | |
parent | 875417685ffbf9ef3667e81f8ec081b7b96d87cd (diff) |
Cause crontab to send SIGUSR1 when a user's crontab file has changed.
In cron, this interrupts the sleep() in cron_sleep() and causes cron
to check to see what signal woke it up and act appropriately.
This makes crontab changes take effect more or immediately.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/cron/cron.8 | 26 | ||||
-rw-r--r-- | usr.sbin/cron/cron.c | 40 | ||||
-rw-r--r-- | usr.sbin/cron/crontab.c | 13 |
3 files changed, 62 insertions, 17 deletions
diff --git a/usr.sbin/cron/cron.8 b/usr.sbin/cron/cron.8 index 7c3d2a2ec17..04b06575cfb 100644 --- a/usr.sbin/cron/cron.8 +++ b/usr.sbin/cron/cron.8 @@ -17,7 +17,7 @@ .\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS .\" SOFTWARE. .\" -.\" $OpenBSD: cron.8,v 1.12 2001/12/13 19:38:42 millert Exp $ +.\" $OpenBSD: cron.8,v 1.13 2001/12/20 23:27:47 millert Exp $ .\" .Dd June 6, 1999 .Dt CRON 8 @@ -97,14 +97,28 @@ new time immediately. Clock changes of more than 3 hours are considered to be corrections to the clock, and the new time is used immediately. .Sh SIGNALS -On receipt of a -.Tn SIGHUP , -the cron daemon will close and reopen its log file. -This is useful in scripts which rotate and age log files. -Naturally this is not relevant if cron was built to use +.Bl -tag -width Ds +.It Dv SIGHUP +causes +.Nm +to close and reopen its log file. +This is useful in scripts which rotate and age log files. +On +.Ox +this has no effect because +.Nm cron +logs via .Xr syslog 3 . +.It Dv SIGUSR1 +causes +.Nm +to check its spool directory's modtime (and the modtime of +.Pa /etc/crontab ) +at the next possible moment instead of waiting until the next minute. +.El .Sh SEE ALSO .Xr crontab 1 , +.Xr syslog 3 , .Xr crontab 5 .Sh AUTHORS Paul Vixie <paul@vix.com> diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c index 2ed9b52e26f..07b1075bdaf 100644 --- a/usr.sbin/cron/cron.c +++ b/usr.sbin/cron/cron.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cron.c,v 1.17 2001/12/11 04:14:00 millert Exp $ */ +/* $OpenBSD: cron.c,v 1.18 2001/12/20 23:27:47 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.17 2001/12/11 04:14:00 millert Exp $"; +static char rcsid[] = "$OpenBSD: cron.c,v 1.18 2001/12/20 23:27:47 millert Exp $"; #endif #define MAIN_PROGRAM @@ -35,13 +35,15 @@ static void usage(void), cron_sleep __P((int)), sigchld_handler(int), sighup_handler(int), + sigusr1_handler(int), sigchld_reaper(void), - check_sigs(void), + check_sigs(int), parse_args(int c, char *v[]); -static volatile sig_atomic_t got_sighup, got_sigchld; +static volatile sig_atomic_t got_sighup, got_sigchld, got_sigusr1; static int timeRunning, virtualTime, clockTime; static long GMToff; +static cron_db database; static void usage(void) { @@ -56,7 +58,6 @@ usage(void) { int main(int argc, char *argv[]) { - cron_db database; struct sigaction sact; int fd; @@ -144,8 +145,7 @@ main(int argc, char *argv[]) { int timeDiff; int wakeupKind; - check_sigs(); - load_database(&database); + check_sigs(TRUE); /* ... wait for the time (in minutes) to change ... */ do { cron_sleep(timeRunning + 1); @@ -340,6 +340,16 @@ static void cron_sleep(int target) { time_t t1, t2; int seconds_to_wait; + struct sigaction sact; + + bzero((char *)&sact, sizeof sact); + sigemptyset(&sact.sa_mask); + sact.sa_flags = 0; +#ifdef SA_RESTART + sact.sa_flags |= SA_RESTART; +#endif + sact.sa_handler = sigusr1_handler; + (void) sigaction(SIGUSR1, &sact, NULL); t1 = time(NULL) + GMToff; seconds_to_wait = (int)(target * SECONDS_PER_MINUTE - t1) + 1; @@ -354,11 +364,14 @@ cron_sleep(int target) { * If so, service the signal(s) then continue sleeping * where we left off. */ - check_sigs(); + check_sigs(FALSE); t2 = time(NULL) + GMToff; seconds_to_wait -= (int)(t2 - t1); t1 = t2; } + + sact.sa_handler = SIG_DFL; + (void) sigaction(SIGUSR1, &sact, NULL); } static void @@ -372,6 +385,11 @@ sigchld_handler(int x) { } static void +sigusr1_handler(int x) { + got_sigusr1 = 1; +} + +static void sigchld_reaper() { WAIT_T waiter; PID_T pid; @@ -400,7 +418,7 @@ sigchld_reaper() { } static void -check_sigs() { +check_sigs(int force_dbload) { if (got_sighup) { got_sighup = 0; log_close(); @@ -409,6 +427,10 @@ check_sigs() { got_sigchld = 0; sigchld_reaper(); } + if (got_sigusr1 || force_dbload) { + got_sigusr1 = 0; + load_database(&database); + } } static void diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c index 08f1c0d9238..2fae5876d30 100644 --- a/usr.sbin/cron/crontab.c +++ b/usr.sbin/cron/crontab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crontab.c,v 1.25 2001/12/07 22:33:09 deraadt Exp $ */ +/* $OpenBSD: crontab.c,v 1.26 2001/12/20 23:27:47 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: crontab.c,v 1.25 2001/12/07 22:33:09 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: crontab.c,v 1.26 2001/12/20 23:27:47 millert Exp $"; #endif /* crontab - install and manage per-user crontab files @@ -675,11 +675,20 @@ done: static void poke_daemon() { + char pidfile[MAX_FNAME]; + PID_T pid; + FILE *fp; + if (utime(SPOOL_DIR, NULL) < OK) { fprintf(stderr, "crontab: can't update mtime on spooldir\n"); perror(SPOOL_DIR); return; } + if (glue_strings(pidfile, sizeof pidfile, PIDDIR, PIDFILE, '/')) { + if ((fp = fopen(pidfile, "r")) && + fscanf(fp, "%d", &pid) == 1) + kill(pid, SIGUSR1); + } } static void |