From 77d8b6762f9fcd6c94e615b4ad3977d8d836ade4 Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Tue, 23 May 2023 12:30:12 +1200 Subject: [PATCH] s4/messaging: Return the number of previously-registered functions that are removed Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- source4/lib/messaging/messaging.c | 13 +++++++++---- source4/lib/messaging/messaging.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 12054477210..7f5dab61b49 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -316,19 +316,21 @@ NTSTATUS imessaging_register_tmp(struct imessaging_context *msg, void *private_d } /* - De-register the function for a particular message type. + De-register the function for a particular message type. Return the number of + functions deregistered. */ -void imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, void *private_data) +size_t imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, void *private_data) { struct dispatch_fn *d, *next; + size_t removed = 0; if (msg_type >= msg->num_types) { d = (struct dispatch_fn *)idr_find(msg->dispatch_tree, msg_type); - if (!d) return; + if (!d) return 0; idr_remove(msg->dispatch_tree, msg_type); talloc_free(d); - return; + return 1; } for (d = msg->dispatch[msg_type]; d; d = next) { @@ -336,8 +338,11 @@ void imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, vo if (d->private_data == private_data) { DLIST_REMOVE(msg->dispatch[msg_type], d); talloc_free(d); + ++removed; } } + + return removed; } /* diff --git a/source4/lib/messaging/messaging.h b/source4/lib/messaging/messaging.h index e7ae9e8cc46..3aa70b3f900 100644 --- a/source4/lib/messaging/messaging.h +++ b/source4/lib/messaging/messaging.h @@ -62,7 +62,7 @@ struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev); NTSTATUS imessaging_send_ptr(struct imessaging_context *msg, struct server_id server, uint32_t msg_type, void *ptr); -void imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, void *private_data); +size_t 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);