summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHakan Olsson <ho@cvs.openbsd.org>2004-02-19 09:54:53 +0000
committerHakan Olsson <ho@cvs.openbsd.org>2004-02-19 09:54:53 +0000
commit9fa68f96f3cdb48bc170c5e764b64478eec5dad2 (patch)
tree70c1d367542d9d3e17ddd17691c04f4c59a36382
parentdb4804f757157bc2ccbc195891c18b0d2986f492 (diff)
With -d, SIGINT should do a clean shutdown.
Without -d, logs should be sent to syslog, level LOG_INFO.
-rw-r--r--sbin/isakmpd/isakmpd.c26
-rw-r--r--sbin/isakmpd/log.c11
-rw-r--r--sbin/isakmpd/log.h4
3 files changed, 23 insertions, 18 deletions
diff --git a/sbin/isakmpd/isakmpd.c b/sbin/isakmpd/isakmpd.c
index 98c2f506daf..a1762579630 100644
--- a/sbin/isakmpd/isakmpd.c
+++ b/sbin/isakmpd/isakmpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: isakmpd.c,v 1.55 2004/02/19 09:46:19 ho Exp $ */
+/* $OpenBSD: isakmpd.c,v 1.56 2004/02/19 09:54:52 ho Exp $ */
/* $EOM: isakmpd.c,v 1.54 2000/10/05 09:28:22 niklas Exp $ */
/*
@@ -95,6 +95,7 @@ volatile sig_atomic_t sigusr2ed = 0;
/*
* If we receive a TERM signal, perform a "clean shutdown" of the daemon.
* This includes to send DELETE notifications for all our active SAs.
+ * Also on recv of an INT signal (Ctrl-C out of an '-d' session, typically).
*/
volatile sig_atomic_t sigtermed = 0;
void daemon_shutdown_now (int);
@@ -326,7 +327,7 @@ daemon_shutdown (void)
}
}
-/* Called on SIGTERM, or by ui_shutdown_daemon(). */
+/* Called on SIGTERM, SIGINT or by ui_shutdown_daemon(). */
void
daemon_shutdown_now (int sig)
{
@@ -369,10 +370,15 @@ main (int argc, char *argv[])
/* Log cmd line parsing and initialization errors to stderr. */
log_to (stderr);
parse_args (argc, argv);
- log_init ();
+ log_init (debug);
- /* Do a clean daemon shutdown on TERM reception. (Needed by monitor). */
+ /*
+ * Do a clean daemon shutdown on TERM/INT. These signals must be
+ * initialized before monitor_init(). INT is only used with '-d'.
+ */
signal (SIGTERM, daemon_shutdown_now);
+ if (debug == 1) /* i.e '-dd' will skip this. */
+ signal (SIGINT, daemon_shutdown_now);
#if defined (USE_PRIVSEP)
if (monitor_init ())
@@ -393,12 +399,8 @@ main (int argc, char *argv[])
init ();
if (!debug)
- {
- if (daemon (0, 0))
- log_fatal ("main: daemon (0, 0) failed");
- /* Switch to syslog. */
- log_to (0);
- }
+ if (daemon (0, 0))
+ log_fatal ("main: daemon (0, 0) failed");
write_pid_file ();
@@ -452,8 +454,8 @@ main (int argc, char *argv[])
}
/*
- * and if someone set 'sigtermed' (SIGTERM or via the UI), this
- * indicated we should start a shutdown of the daemon.
+ * and if someone set 'sigtermed' (SIGTERM, SIGINT or via the UI),
+ * this indicates we should start a controlled shutdown of the daemon.
*
* Note: Since _one_ message is sent per iteration of this enclosing
* while-loop, and we want to send a number of DELETE notifications,
diff --git a/sbin/isakmpd/log.c b/sbin/isakmpd/log.c
index ef6181576aa..419512709b5 100644
--- a/sbin/isakmpd/log.c
+++ b/sbin/isakmpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.38 2004/01/16 10:51:57 hshoexer Exp $ */
+/* $OpenBSD: log.c,v 1.39 2004/02/19 09:54:52 ho Exp $ */
/* $EOM: log.c,v 1.30 2000/09/29 08:19:23 niklas Exp $ */
/*
@@ -100,9 +100,12 @@ static u_int16_t in_cksum (const u_int16_t *, int);
#endif /* USE_DEBUG */
void
-log_init (void)
+log_init (int debug)
{
- log_output = stderr;
+ if (debug)
+ log_output = stderr;
+ else
+ log_to (0); /* syslog */
}
void
@@ -209,7 +212,7 @@ log_debug (int cls, int level, const char *fmt, ...)
if (cls >= 0 && (log_level[cls] == 0 || level > log_level[cls]))
return;
va_start (ap, fmt);
- _log_print (0, LOG_DEBUG, fmt, ap, cls, level);
+ _log_print (0, LOG_INFO, fmt, ap, cls, level);
va_end (ap);
}
diff --git a/sbin/isakmpd/log.h b/sbin/isakmpd/log.h
index ba8ab342818..e313eee3f1f 100644
--- a/sbin/isakmpd/log.h
+++ b/sbin/isakmpd/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.17 2004/01/16 10:51:57 hshoexer Exp $ */
+/* $OpenBSD: log.h,v 1.18 2004/02/19 09:54:52 ho Exp $ */
/* $EOM: log.h,v 1.19 2000/03/30 14:27:23 ho Exp $ */
/*
@@ -96,6 +96,6 @@ extern void log_print (const char *, ...)
extern void log_verbose (const char *, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
extern void log_to (FILE *);
-extern void log_init (void);
+extern void log_init (int);
#endif /* _LOG_H_ */