/*
- destroy the messaging context
+ remove our messaging socket and database entry
*/
-static int imessaging_destructor(struct imessaging_context *msg)
+int imessaging_cleanup(struct imessaging_context *msg)
{
+ DEBUG(5,("imessaging: cleaning up %s\n", msg->path));
unlink(msg->path);
while (msg->names && msg->names[0]) {
irpc_remove_name(msg, msg->names[0]);
/*
create the listening socket and setup the dispatcher
+
+ use temporary=true when you want a destructor to remove the
+ associated messaging socket and database entry on talloc free. Don't
+ use this in processes that may fork and a child may talloc free this
+ memory
*/
struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
- const char *dir,
- struct server_id server_id,
- struct tevent_context *ev)
+ const char *dir,
+ struct server_id server_id,
+ struct tevent_context *ev,
+ bool auto_remove)
{
struct imessaging_context *msg;
NTSTATUS status;
EVENT_FD_READ, imessaging_handler, msg);
tevent_fd_set_auto_close(msg->event.fde);
- talloc_set_destructor(msg, imessaging_destructor);
+ if (auto_remove) {
+ talloc_set_destructor(msg, imessaging_cleanup);
+ }
imessaging_register(msg, NULL, MSG_PING, ping_message);
imessaging_register(msg, NULL, MSG_IRPC, irpc_handler);
struct server_id id;
ZERO_STRUCT(id);
id.pid = random() % 0x10000000;
- return imessaging_init(mem_ctx, dir, id, ev);
+ return imessaging_init(mem_ctx, dir, id, ev, true);
}
/*
a list of registered irpc server functions
NTSTATUS imessaging_register_tmp(struct imessaging_context *msg, void *private_data,
msg_callback_t fn, uint32_t *msg_type);
struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
- const char *dir,
- struct server_id server_id,
- struct tevent_context *ev);
+ const char *dir,
+ struct server_id server_id,
+ struct tevent_context *ev,
+ bool auto_remove);
+int imessaging_cleanup(struct imessaging_context *msg);
struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx,
const char *dir,
struct tevent_context *ev);
return NULL;
ret->msg_ctx = imessaging_init(ret->mem_ctx,
- imessaging_path,
- server_id,
- ev);
+ imessaging_path,
+ server_id,
+ ev, true);
} else {
ret->msg_ctx = imessaging_client_init(ret->mem_ctx,
- imessaging_path,
- ev);
+ imessaging_path,
+ ev);
}
if (ret->msg_ctx == NULL) {
imessaging_init(tctx,
lpcfg_imessaging_path(tctx, tctx->lp_ctx),
cluster_id(0, MSG_ID1),
- data->ev),
+ data->ev, true),
"Failed to init first messaging context");
torture_assert(tctx, data->msg_ctx2 =
imessaging_init(tctx,
lpcfg_imessaging_path(tctx, tctx->lp_ctx),
cluster_id(0, MSG_ID2),
- data->ev),
+ data->ev, true),
"Failed to init second messaging context");
/* register the server side function */
ev = tctx->ev;
msg_server_ctx = imessaging_init(tctx,
- lpcfg_imessaging_path(tctx, tctx->lp_ctx), cluster_id(0, 1),
- ev);
+ lpcfg_imessaging_path(tctx, tctx->lp_ctx), cluster_id(0, 1),
+ ev, true);
torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context");
imessaging_register_tmp(msg_server_ctx, tctx, exit_message, &msg_exit);
msg_client_ctx = imessaging_init(tctx,
- lpcfg_imessaging_path(tctx, tctx->lp_ctx),
- cluster_id(0, 2),
- ev);
+ lpcfg_imessaging_path(tctx, tctx->lp_ctx),
+ cluster_id(0, 2),
+ ev, true);
torture_assert(tctx, msg_client_ctx != NULL,
"msg_client_ctx imessaging_init() failed");
NTSTATUS status;
msg = imessaging_init(talloc_autofree_context(),
- lpcfg_imessaging_path(event_ctx, lp_ctx),
- cluster_id(0, SAMBA_PARENT_TASKID), event_ctx);
+ lpcfg_imessaging_path(event_ctx, lp_ctx),
+ cluster_id(0, SAMBA_PARENT_TASKID), event_ctx, false);
NT_STATUS_HAVE_NO_MEMORY(msg);
irpc_add_name(msg, "samba");
talloc_free(srv_conn->event.fde);
srv_conn->event.fde = NULL;
+ imessaging_cleanup(srv_conn->msg_ctx);
model_ops->terminate(event_ctx, srv_conn->lp_ctx, reason);
talloc_free(srv_conn);
}
/* setup to receive internal messages on this connection */
srv_conn->msg_ctx = imessaging_init(srv_conn,
- lpcfg_imessaging_path(srv_conn, lp_ctx),
- srv_conn->server_id, ev);
+ lpcfg_imessaging_path(srv_conn, lp_ctx),
+ srv_conn->server_id, ev, false);
if (!srv_conn->msg_ctx) {
stream_terminate_connection(srv_conn, "imessaging_init() failed");
return;
task->lp_ctx = lp_ctx;
task->msg_ctx = imessaging_init(task,
- lpcfg_imessaging_path(task, task->lp_ctx),
- task->server_id,
- task->event_ctx);
+ lpcfg_imessaging_path(task, task->lp_ctx),
+ task->server_id,
+ task->event_ctx, false);
if (!task->msg_ctx) {
task_server_terminate(task, "imessaging_init() failed", true);
return;