diff options
author | Moritz Jodeit <moritz@cvs.openbsd.org> | 2005-12-20 22:03:54 +0000 |
---|---|---|
committer | Moritz Jodeit <moritz@cvs.openbsd.org> | 2005-12-20 22:03:54 +0000 |
commit | 22a0b2f80b4063ee265465ca1295afddc34f4032 (patch) | |
tree | 4d0692ea10111c9e4d69ca70fbd7ba970853dc8b /sbin/isakmpd | |
parent | 4f534027992d1c99ed7bd2d0a39f727c4762c7ed (diff) |
let isakmpd(8) remove it's pid/fifo file on exit.
rework signal handling in the monitor process to
let this work. testing and ok hshoexer@
Diffstat (limited to 'sbin/isakmpd')
-rw-r--r-- | sbin/isakmpd/isakmpd.c | 14 | ||||
-rw-r--r-- | sbin/isakmpd/monitor.c | 60 |
2 files changed, 25 insertions, 49 deletions
diff --git a/sbin/isakmpd/isakmpd.c b/sbin/isakmpd/isakmpd.c index 2715b53fae4..eef80cd7e93 100644 --- a/sbin/isakmpd/isakmpd.c +++ b/sbin/isakmpd/isakmpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isakmpd.c,v 1.89 2005/06/25 23:20:43 hshoexer Exp $ */ +/* $OpenBSD: isakmpd.c,v 1.90 2005/12/20 22:03:53 moritz Exp $ */ /* $EOM: isakmpd.c,v 1.54 2000/10/05 09:28:22 niklas Exp $ */ /* @@ -99,7 +99,7 @@ void daemon_shutdown_now(int); void set_slave_signals(void); /* The default path of the PID file. */ -static char *pid_file = "/var/run/isakmpd.pid"; +char *pid_file = "/var/run/isakmpd.pid"; /* The path of the IKE packet capture log file. */ static char *pcap_file = 0; @@ -330,9 +330,6 @@ daemon_shutdown(void) */ log_packet_stop(); - /* Remove FIFO and pid files. */ - unlink(ui_fifo); - unlink(pid_file); log_print("isakmpd: exit"); exit(0); } @@ -352,10 +349,9 @@ write_pid_file(void) { FILE *fp; - /* Ignore errors. This fails with privsep. */ unlink(pid_file); - fp = monitor_fopen(pid_file, "w"); + fp = fopen(pid_file, "w"); if (fp != NULL) { if (fprintf(fp, "%ld\n", (long) getpid()) < 0) log_error("write_pid_file: failed to write PID to " @@ -402,6 +398,8 @@ main(int argc, char *argv[]) /* Set timezone before priv'separation */ tzset(); + write_pid_file(); + if (monitor_init(debug)) { /* The parent, with privileges enters infinite monitor loop. */ monitor_loop(debug); @@ -411,8 +409,6 @@ main(int argc, char *argv[]) init(); - write_pid_file(); - /* If we wanted IKE packet capture to file, initialize it now. */ if (pcap_file != 0) log_packet_init(pcap_file); diff --git a/sbin/isakmpd/monitor.c b/sbin/isakmpd/monitor.c index 91c035f7b70..a999f09140a 100644 --- a/sbin/isakmpd/monitor.c +++ b/sbin/isakmpd/monitor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor.c,v 1.61 2005/11/26 22:17:20 hshoexer Exp $ */ +/* $OpenBSD: monitor.c,v 1.62 2005/12/20 22:03:53 moritz Exp $ */ /* * Copyright (c) 2003 Håkan Olsson. All rights reserved. @@ -58,8 +58,7 @@ struct monitor_state { char root[MAXPATHLEN]; } m_state; -volatile sig_atomic_t sigchlded = 0; -extern volatile sig_atomic_t sigtermed; +extern char *pid_file; extern void set_slave_signals(void); @@ -78,7 +77,6 @@ static int m_priv_check_sockopt(int, int); static int m_priv_check_bind(const struct sockaddr *, socklen_t); static void set_monitor_signals(void); -static void monitor_got_sigchld(int); static void sig_pass_to_chld(int); /* @@ -149,8 +147,21 @@ monitor_init(int debug) void monitor_exit(int code) { - if (m_state.pid != 0) - kill(m_state.pid, SIGKILL); + int status; + pid_t pid; + + if (m_state.pid != 0) { + /* When called from the monitor, kill slave and wait for it */ + kill(m_state.pid, SIGTERM); + + do { + pid = waitpid(m_state.pid, &status, 0); + } while (pid == -1 && errno == EINTR); + + /* Remove FIFO and pid files. */ + unlink(ui_fifo); + unlink(pid_file); + } close(m_state.s); exit(code); @@ -414,22 +425,12 @@ set_monitor_signals(void) for (n = 0; n < _NSIG; n++) signal(n, SIG_DFL); - /* If the child dies, we should shutdown also. */ - signal(SIGCHLD, monitor_got_sigchld); - /* Forward some signals to the child. */ signal(SIGTERM, sig_pass_to_chld); signal(SIGHUP, sig_pass_to_chld); signal(SIGUSR1, sig_pass_to_chld); } -/* ARGSUSED */ -static void -monitor_got_sigchld(int sig) -{ - sigchlded = 1; -} - static void sig_pass_to_chld(int sig) { @@ -444,33 +445,12 @@ sig_pass_to_chld(int sig) void monitor_loop(int debug) { - pid_t pid; - int msgcode, status; + int msgcode; if (!debug) log_to(0); for (;;) { - /* - * Currently, there is no need for us to hang around if the - * child is in the process of shutting down. - */ - if (sigtermed) { - kill(m_state.pid, SIGTERM); - break; - } - - if (sigchlded) { - do { - pid = waitpid(m_state.pid, &status, WNOHANG); - } while (pid == -1 && errno == EINTR); - - if (pid == m_state.pid && (WIFEXITED(status) || - WIFSIGNALED(status))) { - break; - } - } - must_read(&msgcode, sizeof msgcode); switch (msgcode) { @@ -737,7 +717,7 @@ must_read(void *buf, size_t n) if (errno == EINTR || errno == EAGAIN) continue; case 0: - _exit(0); + monitor_exit(0); default: pos += res; } @@ -762,7 +742,7 @@ must_write(const void *buf, size_t n) if (errno == EINTR || errno == EAGAIN) continue; case 0: - _exit(0); + monitor_exit(0); default: pos += res; } |