s4: process_standard: Add tevent SIGHUP signal handler to standard_accept_connection...
authorJeremy Allison <jra@samba.org>
Fri, 7 Apr 2017 22:31:57 +0000 (15:31 -0700)
committerRalph Boehme <slow@samba.org>
Sat, 8 Apr 2017 10:30:08 +0000 (12:30 +0200)
This makes us independent of parent SIGHUP signal handling.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source4/smbd/process_standard.c

index 39edbfb8f4344e17932fe02c21ab739ac8c17c16..776e497e987297f4924c60917de29a040b5fec46 100644 (file)
@@ -29,6 +29,7 @@
 #include "param/param.h"
 #include "ldb_wrap.h"
 #include "lib/messaging/messaging.h"
+#include "lib/util/debug.h"
 
 struct standard_child_state {
        const char *name;
@@ -58,6 +59,14 @@ static void standard_model_init(void)
        }
 }
 
+static void sighup_signal_handler(struct tevent_context *ev,
+                               struct tevent_signal *se,
+                               int signum, int count, void *siginfo,
+                               void *private_data)
+{
+       debug_schedule_reopen_logs();
+}
+
 /*
   handle EOF on the parent-to-all-children pipe in the child
 */
@@ -213,6 +222,7 @@ static void standard_accept_connection(struct tevent_context *ev,
        struct socket_address *c, *s;
        struct standard_child_state *state;
        struct tevent_fd *fde = NULL;
+       struct tevent_signal *se = NULL;
 
        state = setup_standard_child_pipe(ev, NULL);
        if (state == NULL) {
@@ -290,6 +300,16 @@ static void standard_accept_connection(struct tevent_context *ev,
                child_pipe[1] = -1;
        }
 
+       se = tevent_add_signal(ev,
+                               ev,
+                               SIGHUP,
+                               0,
+                               sighup_signal_handler,
+                               NULL);
+       if (se == NULL) {
+               smb_panic("Failed to add SIGHUP handler after fork");
+       }
+
        /* setup the process title */
        c = socket_get_peer_addr(sock2, ev);
        s = socket_get_my_addr(sock2, ev);
@@ -325,6 +345,7 @@ static void standard_new_task(struct tevent_context *ev,
        NTSTATUS status;
        struct standard_child_state *state;
        struct tevent_fd *fde = NULL;
+       struct tevent_signal *se = NULL;
 
        state = setup_standard_child_pipe(ev, service_name);
        if (state == NULL) {
@@ -377,6 +398,16 @@ static void standard_new_task(struct tevent_context *ev,
                child_pipe[1] = -1;
        }
 
+       se = tevent_add_signal(ev,
+                               ev,
+                               SIGHUP,
+                               0,
+                               sighup_signal_handler,
+                               NULL);
+       if (se == NULL) {
+               smb_panic("Failed to add SIGHUP handler after fork");
+       }
+
        setproctitle("task %s server_id[%d]", service_name, (int)pid);
 
        /* setup this new task.  Cluster ID is PID based for this process model */