s4: replace low-level SIGUP handler with a tevent handler
authorRalph Boehme <slow@samba.org>
Fri, 20 Nov 2020 14:21:03 +0000 (15:21 +0100)
committerKarolin Seeger <kseeger@samba.org>
Wed, 9 Dec 2020 07:57:19 +0000 (07:57 +0000)
Replace the low-level signal handler for SIGHUP with a nice tevent signal
handler. The low-level handler sig_hup() installed by setup_signals() remains
being used during early startup before a tevent context is available.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14248

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 9f71e6173ab43a04804ba8061cb0e8ae6c0165bf)

source4/smbd/server.c

index cf3102e305aeda4996f60805734022917dbff51e..1e255b1500d0ab54d1bb7b651ed3b871d352fbfd 100644 (file)
@@ -155,6 +155,19 @@ static void sigterm_signal_handler(struct tevent_context *ev,
        sig_term(SIGTERM);
 }
 
+static void sighup_signal_handler(struct tevent_context *ev,
+                                 struct tevent_signal *se,
+                                 int signum, int count, void *siginfo,
+                                 void *private_data)
+{
+       struct server_state *state = talloc_get_type_abort(
+                private_data, struct server_state);
+
+       DBG_DEBUG("Process %s got SIGHUP\n", state->binary_name);
+
+       reopen_logs_internal();
+}
+
 /*
   setup signal masks
 */
@@ -834,6 +847,22 @@ static int binary_smbd_main(const char *binary_name,
                return 1;
        }
 
+       se = tevent_add_signal(state->event_ctx,
+                               state->event_ctx,
+                               SIGHUP,
+                               0,
+                               sighup_signal_handler,
+                               state);
+       if (se == NULL) {
+               TALLOC_FREE(state);
+               exit_daemon("Initialize SIGHUP handler failed", ENOMEM);
+               /*
+                * return is never reached but is here to satisfy static
+                * checkers
+                */
+               return 1;
+       }
+
        if (lpcfg_server_role(cmdline_lp_ctx) != ROLE_ACTIVE_DIRECTORY_DC
            && !lpcfg_parm_bool(cmdline_lp_ctx, NULL,
                        "server role check", "inhibit", false)