int *fds, size_t num_fds,
void *private_data);
+/* Keep a list of imessaging contexts */
+static struct imessaging_context *msg_ctxs;
+
+static int imessaging_context_destructor(struct imessaging_context *msg)
+{
+ DLIST_REMOVE(msg_ctxs, msg);
+ return 0;
+}
+
+/*
+ * Cleanup messaging dgm contexts
+ *
+ * We must make sure to unref all messaging_dgm_ref's *before* the
+ * tevent context goes away. Only when the last ref is freed, the
+ * refcounted messaging dgm context will be freed.
+ */
+void imessaging_dgm_unref_all(void)
+{
+ struct imessaging_context *msg = NULL;
+
+ for (msg = msg_ctxs; msg != NULL; msg = msg->next) {
+ TALLOC_FREE(msg->msg_dgm_ref);
+ }
+}
+
/*
create the listening socket and setup the dispatcher
*/
return NULL;
}
+ talloc_set_destructor(msg, imessaging_context_destructor);
+
/* create the messaging directory if needed */
lock_dir = lpcfg_lock_directory(lp_ctx);
imessaging_register(msg, NULL, MSG_IRPC, irpc_handler);
IRPC_REGISTER(msg, irpc, IRPC_UPTIME, irpc_uptime, msg);
+ DLIST_ADD(msg_ctxs, msg);
+
return msg;
fail:
talloc_free(msg);
struct loadparm_context *lp_ctx,
struct server_id server_id,
struct tevent_context *ev);
+void imessaging_dgm_unref_all(void);
int imessaging_cleanup(struct imessaging_context *msg);
struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx,
struct loadparm_context *lp_ctx,
exit(0);
}
+static int event_ctx_destructor(struct tevent_context *event_ctx)
+{
+ imessaging_dgm_unref_all();
+ return 0;
+}
+
/*
main server.
*/
exit_daemon("Initializing event context failed", EACCES);
}
+ talloc_set_destructor(event_ctx, event_ctx_destructor);
+
if (opt_interactive) {
/* terminate when stdin goes away */
stdin_event_flags = TEVENT_FD_READ;