Browse code

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

james authored on 2006/11/02 06:10:56
Showing 4 changed files
... ...
@@ -447,6 +447,7 @@ possibly_become_daemon (const struct options *options, const bool first_time)
447 447
       ASSERT (!options->inetd);
448 448
       if (daemon (options->cd_dir != NULL, options->log) < 0)
449 449
 	msg (M_ERR, "daemon() failed");
450
+      restore_signal_state ();
450 451
       if (options->log)
451 452
 	set_std_files_to_null (true);
452 453
 
... ...
@@ -107,6 +107,8 @@ main (int argc, char *argv[])
107 107
   return 1;
108 108
 #endif
109 109
 
110
+  pre_init_signal_catch ();
111
+
110 112
   CLEAR (c);
111 113
 
112 114
   /* signify first time for components which can
... ...
@@ -202,13 +202,23 @@ signal_handler_exit (const int signum)
202 202
 
203 203
 #endif
204 204
 
205
+/* set handlers for unix signals */
206
+
207
+#ifdef HAVE_SIGNAL_H
208
+#define SM_UNDEF     0
209
+#define SM_PRE_INIT  1
210
+#define SM_POST_INIT 2
211
+static int signal_mode; /* GLOBAL */
212
+#endif
213
+
205 214
 void
206 215
 pre_init_signal_catch (void)
207 216
 {
208 217
 #ifdef HAVE_SIGNAL_H
218
+  signal_mode = SM_PRE_INIT;
209 219
   signal (SIGINT, signal_handler);
210 220
   signal (SIGTERM, signal_handler);
211
-  signal (SIGHUP, signal_handler);
221
+  signal (SIGHUP, SIG_IGN);
212 222
   signal (SIGUSR1, SIG_IGN);
213 223
   signal (SIGUSR2, SIG_IGN);
214 224
   signal (SIGPIPE, SIG_IGN);
... ...
@@ -219,6 +229,7 @@ void
219 219
 post_init_signal_catch (void)
220 220
 {
221 221
 #ifdef HAVE_SIGNAL_H
222
+  signal_mode = SM_POST_INIT;
222 223
   signal (SIGINT, signal_handler);
223 224
   signal (SIGTERM, signal_handler);
224 225
   signal (SIGHUP, signal_handler);
... ...
@@ -228,6 +239,18 @@ post_init_signal_catch (void)
228 228
 #endif /* HAVE_SIGNAL_H */
229 229
 }
230 230
 
231
+/* called after daemonization to retain signal settings */
232
+void
233
+restore_signal_state (void)
234
+{
235
+#ifdef HAVE_SIGNAL_H
236
+  if (signal_mode == SM_PRE_INIT)
237
+    pre_init_signal_catch ();
238
+  else if (signal_mode == SM_POST_INIT)
239
+    post_init_signal_catch ();
240
+#endif
241
+}
242
+
231 243
 /*
232 244
  * Print statistics.
233 245
  *
... ...
@@ -53,6 +53,7 @@ void throw_signal_soft (const int signum, const char *signal_text);
53 53
 
54 54
 void pre_init_signal_catch (void);
55 55
 void post_init_signal_catch (void);
56
+void restore_signal_state (void);
56 57
 
57 58
 void print_signal (const struct signal_info *si, const char *title, int msglevel);
58 59
 void print_status (const struct context *c, struct status_output *so);