From 84d8b2b01324433f7d0861042c53ffcb57dc3ccf Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 6 May 2013 11:23:03 +0200 Subject: [PATCH] smbd: Make "num_children" available by smbcontrol Signed-off-by: Volker Lendecke Reviewed-by: Christof Schmit --- source3/librpc/idl/messaging.idl | 4 ++++ source3/smbd/process.c | 2 ++ source3/smbd/server.c | 16 +++++++++++++ source3/utils/smbcontrol.c | 49 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/source3/librpc/idl/messaging.idl b/source3/librpc/idl/messaging.idl index 583eaf019b9..9405d53133f 100644 --- a/source3/librpc/idl/messaging.idl +++ b/source3/librpc/idl/messaging.idl @@ -92,6 +92,10 @@ interface messaging /* shutdown connection for given client */ MSG_SMB_KILL_CLIENT_IP = 0x0316, + /* Tell number of child processes */ + MSG_SMB_TELL_NUM_CHILDREN = 0x0317, + MSG_SMB_NUM_CHILDREN = 0x0318, + /* winbind messages */ MSG_WINBIND_FINISHED = 0x0401, MSG_WINBIND_FORGET_STATE = 0x0402, diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 8bd1c2e0497..1f4cfe7e65f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -3562,6 +3562,8 @@ void smbd_process(struct tevent_context *ev_ctx, MSG_SMB_KILL_CLIENT_IP, msg_kill_client_ip); + messaging_deregister(sconn->msg_ctx, MSG_SMB_TELL_NUM_CHILDREN, NULL); + /* * Use the default MSG_DEBUG handler to avoid rebroadcasting * MSGs to all child processes diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 99b0a10a821..feb47daf502 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -396,6 +396,20 @@ static void add_child_pid(struct smbd_parent_context *parent, parent->num_children += 1; } +static void smb_tell_num_children(struct messaging_context *ctx, void *data, + uint32_t msg_type, struct server_id srv_id, + DATA_BLOB *msg_data) +{ + uint8_t buf[sizeof(uint32_t)]; + + if (am_parent) { + SIVAL(buf, 0, am_parent->num_children); + messaging_send_buf(ctx, srv_id, MSG_SMB_NUM_CHILDREN, + buf, sizeof(buf)); + } +} + + /* at most every smbd:cleanuptime seconds (default 20), we scan the BRL and locking database for entries to cleanup. As a side effect this @@ -890,6 +904,8 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent, smb_parent_force_tdis); messaging_register(msg_ctx, NULL, MSG_SMB_KILL_CLIENT_IP, smb_parent_kill_client_by_ip); + messaging_register(msg_ctx, NULL, MSG_SMB_TELL_NUM_CHILDREN, + smb_tell_num_children); messaging_register(msg_ctx, NULL, ID_CACHE_DELETE, smbd_parent_id_cache_delete); diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index ea1f60951f8..579aa1027df 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -921,6 +921,53 @@ static bool do_dmalloc_changed(struct tevent_context *ev_ctx, NULL, 0); } +static void print_uint32_cb(struct messaging_context *msg, void *private_data, + uint32_t msg_type, struct server_id pid, + DATA_BLOB *data) +{ + uint32_t num_children; + + if (data->length != sizeof(uint32_t)) { + printf("Invalid response: %d bytes long\n", + (int)data->length); + goto done; + } + num_children = IVAL(data->data, 0); + printf("%u children\n", (unsigned)num_children); +done: + num_replies++; +} + +static bool do_num_children(struct tevent_context *ev_ctx, + struct messaging_context *msg_ctx, + const struct server_id pid, + const int argc, const char **argv) +{ + if (argc != 1) { + fprintf(stderr, "Usage: smbcontrol num-children\n"); + return False; + } + + messaging_register(msg_ctx, NULL, MSG_SMB_NUM_CHILDREN, + print_uint32_cb); + + /* Send a message and register our interest in a reply */ + + if (!send_message(msg_ctx, pid, MSG_SMB_TELL_NUM_CHILDREN, NULL, 0)) + return false; + + wait_replies(ev_ctx, msg_ctx, procid_to_pid(&pid) == 0); + + /* No replies were received within the timeout period */ + + if (num_replies == 0) + printf("No replies received\n"); + + messaging_deregister(msg_ctx, MSG_SMB_TELL_NUM_CHILDREN, NULL); + + return num_replies; +} + /* Shutdown a server process */ static bool do_shutdown(struct tevent_context *ev_ctx, @@ -1329,6 +1376,8 @@ static const struct { "Validate winbind's credential cache" }, { "dump-domain-list", do_winbind_dump_domain_list, "Dump winbind domain list"}, { "notify-cleanup", do_notify_cleanup }, + { "num-children", do_num_children, + "Print number of smbd child processes" }, { "noop", do_noop, "Do nothing" }, { NULL } }; -- 2.11.4.GIT