summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source3/librpc/idl/messaging.idl4
-rw-r--r--source3/smbd/process.c2
-rw-r--r--source3/smbd/server.c16
-rw-r--r--source3/utils/smbcontrol.c49
4 files changed, 71 insertions, 0 deletions
diff --git a/source3/librpc/idl/messaging.idl b/source3/librpc/idl/messaging.idl
index 583eaf019b..9405d53133 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 8bd1c2e049..1f4cfe7e65 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 99b0a10a82..feb47daf50 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 ea1f60951f..579aa1027d 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 <dest> 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 }
};