From 832776c0fcf7cc658c128765514755c2d15b06a6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 17 Jan 2019 16:27:10 +0100 Subject: [PATCH] s4:server: add support for 'smbcontrol samba shutdown' MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752 Signed-off-by: Stefan Metzmacher Reviewed-by: Björn Baumbach --- source4/smbd/server.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/source4/smbd/server.c b/source4/smbd/server.c index 5463f772a1b..cf860491c1a 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -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 @@ -292,6 +293,31 @@ static int prime_ldb_databases(struct tevent_context *event_ctx, bool *am_backup } /* + 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 */ static NTSTATUS samba_terminate(struct irpc_message *msg, @@ -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; } -- 2.11.4.GIT