summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-05-22 17:19:16 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-05-22 17:19:16 +0000
commit8c5c7d6f0c315918d641d69ec5272ed62356689f (patch)
treef65ba0dec749aaa9904368a2ab8b2652fa869de1
parentc48412a4904299c5c9ee02f0c3d01a69fea0c6f5 (diff)
Remove pid file if sent SIGINT or SIGTERM before exiting.
-rw-r--r--usr.sbin/cron/cron.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index 1ae01bf981d..a7703051157 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cron.c,v 1.22 2002/05/21 20:57:32 millert Exp $ */
+/* $OpenBSD: cron.c,v 1.23 2002/05/22 17:19:15 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.22 2002/05/21 20:57:32 millert Exp $";
+static char rcsid[] = "$OpenBSD: cron.c,v 1.23 2002/05/22 17:19:15 millert Exp $";
#endif
#define MAIN_PROGRAM
@@ -39,6 +39,7 @@ static void usage(void),
sighup_handler(int),
sigchld_reaper(void),
check_sigs(int),
+ quit(int),
parse_args(int c, char *v[]);
static volatile sig_atomic_t got_sighup, got_sigchld;
@@ -86,6 +87,9 @@ main(int argc, char *argv[]) {
sact.sa_handler = SIG_IGN;
(void) sigaction(SIGPIPE, &sact, NULL);
(void) sigaction(SIGUSR1, &sact, NULL); /* XXX */
+ sact.sa_handler = quit;
+ (void) sigaction(SIGINT, &sact, NULL);
+ (void) sigaction(SIGTERM, &sact, NULL);
acquire_daemonlock(0);
set_cron_uid();
@@ -411,6 +415,16 @@ sigchld_handler(int x) {
}
static void
+quit(int x) {
+ char pidfile[MAX_FNAME];
+
+ if (glue_strings(pidfile, sizeof pidfile, PIDDIR, PIDFILE, '/'))
+ (void) unlink(pidfile);
+
+ _exit(0);
+}
+
+static void
sigchld_reaper() {
WAIT_T waiter;
PID_T pid;