aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2006-11-01 21:10:56 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2006-11-01 21:10:56 +0000
commit225d5fe945bb6fc6d7a523b5944e96243a6b5038 (patch)
treed5c5a5cd7161344d514dbdd50bee42db4d50e376
parentauth-pam change: link with -lpam rather (diff)
downloadopenvpn-225d5fe945bb6fc6d7a523b5944e96243a6b5038.tar.xz
Prevent SIGUSR1 or SIGHUP from causing program
exit from initial management hold. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@1427 e7ae566f-a301-0410-adde-c780ea21d3b5
-rw-r--r--init.c1
-rw-r--r--openvpn.c2
-rw-r--r--sig.c25
-rw-r--r--sig.h1
4 files changed, 28 insertions, 1 deletions
diff --git a/init.c b/init.c
index d23272c..1712cb2 100644
--- a/init.c
+++ b/init.c
@@ -447,6 +447,7 @@ possibly_become_daemon (const struct options *options, const bool first_time)
ASSERT (!options->inetd);
if (daemon (options->cd_dir != NULL, options->log) < 0)
msg (M_ERR, "daemon() failed");
+ restore_signal_state ();
if (options->log)
set_std_files_to_null (true);
diff --git a/openvpn.c b/openvpn.c
index 496e505..cb6af50 100644
--- a/openvpn.c
+++ b/openvpn.c
@@ -107,6 +107,8 @@ main (int argc, char *argv[])
return 1;
#endif
+ pre_init_signal_catch ();
+
CLEAR (c);
/* signify first time for components which can
diff --git a/sig.c b/sig.c
index 7eb120e..9d8756b 100644
--- a/sig.c
+++ b/sig.c
@@ -202,13 +202,23 @@ signal_handler_exit (const int signum)
#endif
+/* set handlers for unix signals */
+
+#ifdef HAVE_SIGNAL_H
+#define SM_UNDEF 0
+#define SM_PRE_INIT 1
+#define SM_POST_INIT 2
+static int signal_mode; /* GLOBAL */
+#endif
+
void
pre_init_signal_catch (void)
{
#ifdef HAVE_SIGNAL_H
+ signal_mode = SM_PRE_INIT;
signal (SIGINT, signal_handler);
signal (SIGTERM, signal_handler);
- signal (SIGHUP, signal_handler);
+ signal (SIGHUP, SIG_IGN);
signal (SIGUSR1, SIG_IGN);
signal (SIGUSR2, SIG_IGN);
signal (SIGPIPE, SIG_IGN);
@@ -219,6 +229,7 @@ void
post_init_signal_catch (void)
{
#ifdef HAVE_SIGNAL_H
+ signal_mode = SM_POST_INIT;
signal (SIGINT, signal_handler);
signal (SIGTERM, signal_handler);
signal (SIGHUP, signal_handler);
@@ -228,6 +239,18 @@ post_init_signal_catch (void)
#endif /* HAVE_SIGNAL_H */
}
+/* called after daemonization to retain signal settings */
+void
+restore_signal_state (void)
+{
+#ifdef HAVE_SIGNAL_H
+ if (signal_mode == SM_PRE_INIT)
+ pre_init_signal_catch ();
+ else if (signal_mode == SM_POST_INIT)
+ post_init_signal_catch ();
+#endif
+}
+
/*
* Print statistics.
*
diff --git a/sig.h b/sig.h
index 5c32df6..1b85d05 100644
--- a/sig.h
+++ b/sig.h
@@ -53,6 +53,7 @@ void throw_signal_soft (const int signum, const char *signal_text);
void pre_init_signal_catch (void);
void post_init_signal_catch (void);
+void restore_signal_state (void);
void print_signal (const struct signal_info *si, const char *title, int msglevel);
void print_status (const struct context *c, struct status_output *so);