summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorGary Lockyer <gary@catalyst.net.nz>2018-09-14 09:43:59 +1200
committerAndrew Bartlett <abartlet@samba.org>2018-11-23 08:25:20 +0100
commit11d424e1999e50f036ce2b33411f6f607c60a487 (patch)
tree93eaad493270e961e741a975f280b421e9c27abf /source4
parent40941e98f8508daf59b83e05461ebeab4bebaacd (diff)
downloadsamba-11d424e1999e50f036ce2b33411f6f607c60a487.tar.gz
source4 messaging: clean up terminated processes
Now that the smbd pre-fork process model restarts failed processes rather than terminating, we end up with names registered to defunct processes. This patch adds a function to clean up all the names registered to a process. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/messaging/messaging.c42
-rw-r--r--source4/lib/messaging/messaging.h2
2 files changed, 44 insertions, 0 deletions
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index 935951f3fba..413a19445eb 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -248,6 +248,48 @@ static void imessaging_dgm_recv(struct tevent_context *ev,
/* Keep a list of imessaging contexts */
static struct imessaging_context *msg_ctxs;
+/*
+ * A process has terminated, clean-up any names it has registered.
+ */
+NTSTATUS imessaging_process_cleanup(
+ struct imessaging_context *msg_ctx,
+ pid_t pid)
+{
+ struct irpc_name_records *names = NULL;
+ int i = 0;
+ int j = 0;
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+
+ if (mem_ctx == NULL) {
+ DBG_ERR("OOM unable to clean up messaging for process (%d)\n",
+ pid);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ names = irpc_all_servers(msg_ctx, mem_ctx);
+ if (names == NULL) {
+ TALLOC_FREE(mem_ctx);
+ return NT_STATUS_OK;
+ }
+ for (i = 0; i < names->num_records; i++) {
+ for (j = 0; j < names->names[i]->count; j++) {
+ if (names->names[i]->ids[j].pid == pid) {
+ int ret = server_id_db_prune_name(
+ msg_ctx->names,
+ names->names[i]->name,
+ names->names[i]->ids[j]);
+ if (ret != 0 && ret != ENOENT) {
+ TALLOC_FREE(mem_ctx);
+ return map_nt_error_from_unix_common(
+ ret);
+ }
+ }
+ }
+ }
+ TALLOC_FREE(mem_ctx);
+ return NT_STATUS_OK;
+}
+
static int imessaging_context_destructor(struct imessaging_context *msg)
{
DLIST_REMOVE(msg_ctxs, msg);
diff --git a/source4/lib/messaging/messaging.h b/source4/lib/messaging/messaging.h
index 668464dc061..8eb195dfb2e 100644
--- a/source4/lib/messaging/messaging.h
+++ b/source4/lib/messaging/messaging.h
@@ -54,5 +54,7 @@ NTSTATUS imessaging_send_ptr(struct imessaging_context *msg, struct server_id se
uint32_t msg_type, void *ptr);
void imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, void *private_data);
struct server_id imessaging_get_server_id(struct imessaging_context *msg_ctx);
+NTSTATUS imessaging_process_cleanup(struct imessaging_context *msg_ctx,
+ pid_t pid);
#endif