diff options
author | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2006-11-01 21:10:56 +0000 |
---|---|---|
committer | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2006-11-01 21:10:56 +0000 |
commit | 225d5fe945bb6fc6d7a523b5944e96243a6b5038 (patch) | |
tree | d5c5a5cd7161344d514dbdd50bee42db4d50e376 | |
parent | auth-pam change: link with -lpam rather (diff) | |
download | openvpn-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.c | 1 | ||||
-rw-r--r-- | openvpn.c | 2 | ||||
-rw-r--r-- | sig.c | 25 | ||||
-rw-r--r-- | sig.h | 1 |
4 files changed, 28 insertions, 1 deletions
@@ -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); @@ -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 @@ -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. * @@ -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); |