Peter@equalit.ie wrote (on gnunet-developers):
authorChristian Grothoff <christian@grothoff.org>
Wed, 25 Oct 2017 11:02:44 +0000 (13:02 +0200)
committerChristian Grothoff <christian@grothoff.org>
Wed, 25 Oct 2017 11:04:04 +0000 (13:04 +0200)
Continuing a small IRC discussion

https://gnunet.org/bot/log/gnunet/2017-10-05#T1521518

Here is a change to optionally disable installing signal handlers in
GNUnet's scheduler:

https://github.com/equalitie/gnunet/commit/72d02205e1f25ec0df3a2d7efe44c8990ffead53?diff=split
(also attached)

=> patch looks fine, checkin in. -C

src/include/gnunet_scheduler_lib.h
src/util/scheduler.c

index 875f5043a48485a066ffbdaa4a5af1064bfd1be2..a855ab8aba9f0468df2722c00fc6b2474dd25084 100644 (file)
@@ -400,6 +400,22 @@ void
 GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
                       void *task_cls);
 
+/**
+ * Initialize and run scheduler.  This function will return when all
+ * tasks have completed.  When @ install_signals is GNUNET_YES, then
+ * this function behaves in the same was as GNUNET_SCHEDULER_run does.
+ * If @ install_signals is GNUNET_NO then no signal handlers are
+ * installed.
+ *
+ * @param install_signals whether to install signals (GNUNET_YES/NO)
+ * @param task task to run first (and immediately)
+ * @param task_cls closure of @a task
+ */
+void
+GNUNET_SCHEDULER_run_with_optional_signals (int install_signals,
+                                            GNUNET_SCHEDULER_TaskCallback task,
+                                            void *task_cls);
+
 
 /**
  * Request the shutdown of a scheduler.  Marks all tasks
index e9c25d68a82f3bf5f4c8a3dd9563d52b9b0fe3e6..540a60557340bf73282a4ccd97f373a1db4c1a46 100644 (file)
@@ -786,6 +786,14 @@ check_lifeness ()
 void
 GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
                       void *task_cls)
+{
+    GNUNET_SCHEDULER_run_with_optional_signals(GNUNET_YES, task, task_cls);
+}
+
+void
+GNUNET_SCHEDULER_run_with_optional_signals (int install_signals,
+                                            GNUNET_SCHEDULER_TaskCallback task,
+                                            void *task_cls)
 {
   struct GNUNET_NETWORK_FDSet *rs;
   struct GNUNET_NETWORK_FDSet *ws;
@@ -820,24 +828,29 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
                                 GNUNET_DISK_PIPE_END_READ);
   GNUNET_assert (NULL != pr);
   my_pid = getpid ();
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Registering signal handlers\n");
-  shc_int = GNUNET_SIGNAL_handler_install (SIGINT,
+
+  if (GNUNET_YES == install_signals)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Registering signal handlers\n");
+    shc_int = GNUNET_SIGNAL_handler_install (SIGINT,
+                                          &sighandler_shutdown);
+    shc_term = GNUNET_SIGNAL_handler_install (SIGTERM,
                                           &sighandler_shutdown);
-  shc_term = GNUNET_SIGNAL_handler_install (SIGTERM,
-                                           &sighandler_shutdown);
 #if (SIGTERM != GNUNET_TERM_SIG)
-  shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG,
+    shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG,
                                             &sighandler_shutdown);
 #endif
 #ifndef MINGW
-  shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE,
+    shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE,
                                            &sighandler_pipe);
-  shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT,
+    shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT,
                                            &sighandler_shutdown);
-  shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP,
+    shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP,
                                           &sighandler_shutdown);
 #endif
+  }
+
   current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
   current_lifeness = GNUNET_YES;
   GNUNET_SCHEDULER_add_with_reason_and_priority (task,
@@ -953,16 +966,21 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
       busy_wait_warning = 0;
     }
   }
-  GNUNET_SIGNAL_handler_uninstall (shc_int);
-  GNUNET_SIGNAL_handler_uninstall (shc_term);
+
+  if (GNUNET_YES == install_signals)
+  {
+    GNUNET_SIGNAL_handler_uninstall (shc_int);
+    GNUNET_SIGNAL_handler_uninstall (shc_term);
 #if (SIGTERM != GNUNET_TERM_SIG)
-  GNUNET_SIGNAL_handler_uninstall (shc_gterm);
+    GNUNET_SIGNAL_handler_uninstall (shc_gterm);
 #endif
 #ifndef MINGW
-  GNUNET_SIGNAL_handler_uninstall (shc_pipe);
-  GNUNET_SIGNAL_handler_uninstall (shc_quit);
-  GNUNET_SIGNAL_handler_uninstall (shc_hup);
+    GNUNET_SIGNAL_handler_uninstall (shc_pipe);
+    GNUNET_SIGNAL_handler_uninstall (shc_quit);
+    GNUNET_SIGNAL_handler_uninstall (shc_hup);
 #endif
+  }
+
   GNUNET_DISK_pipe_close (shutdown_pipe_handle);
   shutdown_pipe_handle = NULL;
   GNUNET_NETWORK_fdset_destroy (rs);