s4:server: add support for 'smbcontrol samba shutdown'
authorStefan Metzmacher <metze@samba.org>
Thu, 17 Jan 2019 15:27:10 +0000 (16:27 +0100)
committerKarolin Seeger <kseeger@samba.org>
Tue, 5 Feb 2019 19:41:25 +0000 (20:41 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Björn Baumbach <bbaumbach@samba.org>
(cherry picked from commit 832776c0fcf7cc658c128765514755c2d15b06a6)

source4/smbd/server.c

index 0345c6ac7d3e417fd204c414ce6c04018a84f84b..eeb46ffee6ab3fdbee7da3f6ea016e8bcc8924cf 100644 (file)
@@ -45,6 +45,7 @@
 #include "libds/common/roles.h"
 #include "lib/util/tfork.h"
 #include "dsdb/samdb/ldb_modules/util.h"
+#include "lib/util/server_id.h"
 
 #ifdef HAVE_PTHREAD
 #include <pthread.h>
@@ -291,6 +292,31 @@ static int prime_ldb_databases(struct tevent_context *event_ctx, bool *am_backup
        return LDB_SUCCESS;
 }
 
+/*
+  called from 'smbcontrol samba shutdown'
+ */
+static void samba_parent_shutdown(struct imessaging_context *msg,
+                                 void *private_data,
+                                 uint32_t msg_type,
+                                 struct server_id src,
+                                 DATA_BLOB *data)
+{
+       struct server_state *state =
+               talloc_get_type_abort(private_data,
+               struct server_state);
+       struct server_id_buf src_buf;
+       struct server_id dst = imessaging_get_server_id(msg);
+       struct server_id_buf dst_buf;
+
+       DBG_ERR("samba_shutdown of %s %s: from %s\n",
+               state->binary_name,
+               server_id_str_buf(dst, &dst_buf),
+               server_id_str_buf(src, &src_buf));
+
+       TALLOC_FREE(state);
+       exit(0);
+}
+
 /*
   called when a fatal condition occurs in a child task
  */
@@ -325,10 +351,19 @@ static NTSTATUS setup_parent_messaging(struct server_state *state,
                return status;
        }
 
+       status = imessaging_register(msg, state, MSG_SHUTDOWN,
+                                    samba_parent_shutdown);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
        status = IRPC_REGISTER(msg, irpc, SAMBA_TERMINATE,
                               samba_terminate, state);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
 
-       return status;
+       return NT_STATUS_OK;
 }