diff options
author | Andrew Tridgell <tridge@samba.org> | 2011-07-22 14:55:32 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2011-07-22 08:09:06 +0200 |
commit | 2d21fe079fb57e55d9bac0c69d8527013bf4fbc7 (patch) | |
tree | 87c39ddaa23e90578b9408f31b87b093c1e7cb17 /source4/lib | |
parent | fafd386910ca5f17c42cd0cf0a7c759f0950d518 (diff) | |
download | samba-2d21fe079fb57e55d9bac0c69d8527013bf4fbc7.tar.gz samba-2d21fe079fb57e55d9bac0c69d8527013bf4fbc7.tar.bz2 samba-2d21fe079fb57e55d9bac0c69d8527013bf4fbc7.zip |
s4-messaging: fixed the removal of messaging sockets in child tasks
when a child task exits we were firing a destructor on any inherited
messaging contexts, which could trigger a removal of the parents
message socket and messaging database entry.
This adds a new auto_remove flag to imessaging_init(), and exposes the
cleanup code for use by the stream service.
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Fri Jul 22 08:09:06 CEST 2011 on sn-devel-104
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/messaging/messaging.c | 23 | ||||
-rw-r--r-- | source4/lib/messaging/messaging.h | 8 | ||||
-rw-r--r-- | source4/lib/messaging/pymessaging.c | 10 | ||||
-rw-r--r-- | source4/lib/messaging/tests/irpc.c | 4 | ||||
-rw-r--r-- | source4/lib/messaging/tests/messaging.c | 10 |
5 files changed, 33 insertions, 22 deletions
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 484f22b2ee..ccc60032a6 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -541,10 +541,11 @@ NTSTATUS imessaging_send_ptr(struct imessaging_context *msg, struct server_id se /* - 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]); @@ -554,11 +555,17 @@ static int imessaging_destructor(struct imessaging_context *msg) /* 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; @@ -622,7 +629,9 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx, 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); @@ -641,7 +650,7 @@ struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx, 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 diff --git a/source4/lib/messaging/messaging.h b/source4/lib/messaging/messaging.h index eb8a8abc79..e51590fe74 100644 --- a/source4/lib/messaging/messaging.h +++ b/source4/lib/messaging/messaging.h @@ -54,9 +54,11 @@ NTSTATUS imessaging_register(struct imessaging_context *msg, void *private_data, 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); diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index cafd45beae..4f90db59f2 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -96,13 +96,13 @@ static PyObject *py_imessaging_connect(PyTypeObject *self, PyObject *args, PyObj 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) { diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c index cfa2bcb91e..554a7efa99 100644 --- a/source4/lib/messaging/tests/irpc.c +++ b/source4/lib/messaging/tests/irpc.c @@ -249,14 +249,14 @@ static bool irpc_setup(struct torture_context *tctx, void **_data) 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 */ diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index 38c34fc52e..c5d37953d0 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -72,8 +72,8 @@ static bool test_ping_speed(struct torture_context *tctx) 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"); @@ -81,9 +81,9 @@ static bool test_ping_speed(struct torture_context *tctx) 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"); |