summaryrefslogtreecommitdiff
path: root/usr.sbin/cron
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-12-11 04:14:01 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-12-11 04:14:01 +0000
commit04eb17710586d6b4c0b58260db35c7b704f95da3 (patch)
treecbdfaa9552dbd28540a656c0589fcabad20f27e8 /usr.sbin/cron
parentc4b5da3b3b2aefe4aa5ee00db75afd7cfa6711a4 (diff)
If we receive a signal during the sleep(), run signal handlers as
needed and then go back to sleep. This fixes the issue where processes run by cron could hang around as zombies for a minute (ie: until we were done sleeping).
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r--usr.sbin/cron/cron.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index 5cc8a5458f5..2ed9b52e26f 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cron.c,v 1.16 2001/10/24 17:28:16 millert Exp $ */
+/* $OpenBSD: cron.c,v 1.17 2001/12/11 04:14:00 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.16 2001/10/24 17:28:16 millert Exp $";
+static char rcsid[] = "$OpenBSD: cron.c,v 1.17 2001/12/11 04:14:00 millert Exp $";
#endif
#define MAIN_PROGRAM
@@ -36,6 +36,7 @@ static void usage(void),
sigchld_handler(int),
sighup_handler(int),
sigchld_reaper(void),
+ check_sigs(void),
parse_args(int c, char *v[]);
static volatile sig_atomic_t got_sighup, got_sigchld;
@@ -143,15 +144,7 @@ main(int argc, char *argv[]) {
int timeDiff;
int wakeupKind;
- if (got_sighup) {
- got_sighup = 0;
- log_close();
- }
- if (got_sigchld) {
- got_sigchld = 0;
- sigchld_reaper();
- }
-
+ check_sigs();
load_database(&database);
/* ... wait for the time (in minutes) to change ... */
do {
@@ -345,16 +338,27 @@ set_time(int initialize) {
*/
static void
cron_sleep(int target) {
- time_t t;
+ time_t t1, t2;
int seconds_to_wait;
- t = time(NULL) + GMToff;
- seconds_to_wait = (int)(target * SECONDS_PER_MINUTE - t) + 1;
+ t1 = time(NULL) + GMToff;
+ seconds_to_wait = (int)(target * SECONDS_PER_MINUTE - t1) + 1;
Debug(DSCH, ("[%ld] Target time=%ld, sec-to-wait=%d\n",
(long)getpid(), (long)target*SECONDS_PER_MINUTE, seconds_to_wait))
- if (seconds_to_wait > 0 && seconds_to_wait < 65)
+ while (seconds_to_wait > 0 && seconds_to_wait < 65) {
sleep((unsigned int) seconds_to_wait);
+
+ /*
+ * Check to see if we were interrupted by a signal.
+ * If so, service the signal(s) then continue sleeping
+ * where we left off.
+ */
+ check_sigs();
+ t2 = time(NULL) + GMToff;
+ seconds_to_wait -= (int)(t2 - t1);
+ t1 = t2;
+ }
}
static void
@@ -396,6 +400,18 @@ sigchld_reaper() {
}
static void
+check_sigs() {
+ if (got_sighup) {
+ got_sighup = 0;
+ log_close();
+ }
+ if (got_sigchld) {
+ got_sigchld = 0;
+ sigchld_reaper();
+ }
+}
+
+static void
parse_args(int argc, char *argv[]) {
int argch;