s3:smbd: pass smbd_server_connection to smbd_setup_sig_term_handler()
[ira/wip.git] / source3 / smbd / server.c
index 4df68f9b45d1c7549a36c53bc5144156ddef64b8..f7edc9996e40e2ae88ee0912308a6138a571ee4f 100644 (file)
@@ -117,20 +117,6 @@ static void  killkids(void)
        if(am_parent) kill(0,SIGTERM);
 }
 
-/****************************************************************************
- Process a sam sync message - not sure whether to do this here or
- somewhere else.
-****************************************************************************/
-
-static void msg_sam_sync(struct messaging_context *msg,
-                        void *private_data,
-                        uint32_t msg_type,
-                        struct server_id server_id,
-                        DATA_BLOB *data)
-{
-        DEBUG(10, ("** sam sync message received, ignoring\n"));
-}
-
 static void msg_exit_server(struct messaging_context *msg,
                            void *private_data,
                            uint32_t msg_type,
@@ -358,6 +344,7 @@ struct smbd_open_socket;
 struct smbd_parent_context {
        bool interactive;
 
+       struct tevent_context *ev_ctx;
        struct messaging_context *msg_ctx;
 
        /* the list of listening sockets */
@@ -473,7 +460,7 @@ static void smbd_accept_connection(struct tevent_context *ev,
                        smb_panic("reinit_after_fork() failed");
                }
 
-               smbd_setup_sig_term_handler();
+               smbd_setup_sig_term_handler(sconn);
                smbd_setup_sig_hup_handler(ev,
                                           msg_ctx);
 
@@ -747,7 +734,6 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
 
         /* Listen to messages */
 
-       messaging_register(msg_ctx, NULL, MSG_SMB_SAM_SYNC, msg_sam_sync);
        messaging_register(msg_ctx, NULL, MSG_SHUTDOWN, msg_exit_server);
        messaging_register(msg_ctx, ev_ctx, MSG_SMB_CONF_UPDATED,
                           smb_conf_updated);
@@ -833,6 +819,34 @@ static bool init_structs(void )
        return True;
 }
 
+static void smbd_parent_sig_term_handler(struct tevent_context *ev,
+                                        struct tevent_signal *se,
+                                        int signum,
+                                        int count,
+                                        void *siginfo,
+                                        void *private_data)
+{
+       exit_server_cleanly("termination signal");
+}
+
+static void smbd_parent_sig_hup_handler(struct tevent_context *ev,
+                                       struct tevent_signal *se,
+                                       int signum,
+                                       int count,
+                                       void *siginfo,
+                                       void *private_data)
+{
+       struct smbd_parent_context *parent =
+               talloc_get_type_abort(private_data,
+               struct smbd_parent_context);
+
+       change_to_root_user();
+       DEBUG(1,("parent: Reloading services after SIGHUP\n"));
+       reload_services(parent->msg_ctx, -1, false);
+
+       printing_subsystem_update(parent->ev_ctx, parent->msg_ctx, true);
+}
+
 /****************************************************************************
  main program.
 ****************************************************************************/
@@ -883,6 +897,7 @@ extern void build_options(bool screen);
        uint64_t unique_id;
        struct tevent_context *ev_ctx;
        struct messaging_context *msg_ctx;
+       struct tevent_signal *se;
 
        /*
         * Do this before any other talloc operation
@@ -1125,9 +1140,30 @@ extern void build_options(bool screen);
 
        smbd_server_conn->msg_ctx = msg_ctx;
 
-       smbd_setup_sig_term_handler();
-       smbd_setup_sig_hup_handler(ev_ctx,
-                                  msg_ctx);
+       parent = talloc_zero(ev_ctx, struct smbd_parent_context);
+       if (!parent) {
+               exit_server("talloc(struct smbd_parent_context) failed");
+       }
+       parent->interactive = interactive;
+       parent->ev_ctx = ev_ctx;
+       parent->msg_ctx = msg_ctx;
+
+       se = tevent_add_signal(parent->ev_ctx,
+                              parent,
+                              SIGTERM, 0,
+                              smbd_parent_sig_term_handler,
+                              parent);
+       if (!se) {
+               exit_server("failed to setup SIGTERM handler");
+       }
+       se = tevent_add_signal(parent->ev_ctx,
+                              parent,
+                              SIGHUP, 0,
+                              smbd_parent_sig_hup_handler,
+                              parent);
+       if (!se) {
+               exit_server("failed to setup SIGHUP handler");
+       }
 
        /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
 
@@ -1283,12 +1319,6 @@ extern void build_options(bool screen);
                return(0);
        }
 
-       parent = talloc_zero(ev_ctx, struct smbd_parent_context);
-       if (!parent) {
-               exit_server("talloc(struct smbd_parent_context) failed");
-       }
-       parent->interactive = interactive;
-       parent->msg_ctx = msg_ctx;
        if (!open_sockets_smbd(parent, ev_ctx, msg_ctx, ports))
                exit_server("open_sockets_smbd() failed");