From 6a4c3b38264362ce53f76a740071fac81e8e00f2 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 10 Oct 2018 13:35:00 +1100 Subject: [PATCH 1/4] ctdb-daemon: Return early when refusing to run an event script BUG: https://bugzilla.samba.org/show_bug.cgi?id=13659 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit a3d12252fa8e0a7e900b819dec30bdb9da458254) --- ctdb/server/eventscript.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 157f6535362..1f70ef5addf 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -661,6 +661,7 @@ int ctdb_event_script_run(struct ctdb_context *ctdb, DEBUG(DEBUG_ERR, ("Refusing to run event '%s' while in recovery\n", ctdb_eventscript_call_names[event])); + return -1; } state = talloc_zero(mem_ctx, struct ctdb_event_script_run_state); -- 2.19.1 From 76298a5c2fd1a5ff7226de6c330e6dc1993183a2 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 11 Oct 2018 11:26:06 +1100 Subject: [PATCH 2/4] ctdb-daemon: Exit if eventd goes away ctdbd enters a broken state if eventd goes away. A clean shutdown is not possible because that involves running events. Restarting eventd is possible but this might mask a serious problem and it is possible that eventd might keep on disappearing. Just exit. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13659 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit c9e1603a5d0c1a216439d4a2b0e7cdc05181e898) --- ctdb/server/eventscript.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 1f70ef5addf..4a680044c25 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -370,13 +370,8 @@ static void eventd_dead_handler(struct tevent_context *ev, struct tevent_fd *fde, uint16_t flags, void *private_data) { - struct eventd_context *ectx = talloc_get_type_abort( - private_data, struct eventd_context); - - DEBUG(DEBUG_ERR, ("Eventd went away\n")); - - TALLOC_FREE(ectx->eventd_fde); - ectx->eventd_pid = -1; + D_ERR("Eventd went away - exiting\n"); + exit(1); } void ctdb_stop_eventd(struct ctdb_context *ctdb) -- 2.19.1 From fc22e2d7be9dff53c2fe70ac06a21ac2d9230947 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 10 Oct 2018 18:16:33 +1100 Subject: [PATCH 3/4] ctdb-common: Set close-on-exec for startup fd The startup_fd should not be propagated to the child processes created from a daemon. It should only be used in the daemon code to return the status of the startup. Another use of startup_fd is to notify the parent if the daemon process has exited. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13659 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 80549927bc1741a4b8af8b8e830de4d37fa0c4a8) --- ctdb/common/sock_daemon.c | 8 +++++++- ctdb/common/sock_daemon.h | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ctdb/common/sock_daemon.c b/ctdb/common/sock_daemon.c index 03d3ac1f1ec..86cc2f2e502 100644 --- a/ctdb/common/sock_daemon.c +++ b/ctdb/common/sock_daemon.c @@ -517,9 +517,15 @@ int sock_daemon_add_unix(struct sock_daemon_context *sockd, return 0; } -void sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd) +bool sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd) { + if (! set_close_on_exec(fd)) { + D_ERR("Failed to set close-on-exec on startup fd\n"); + return false; + } + sockd->startup_fd = fd; + return true; } /* diff --git a/ctdb/common/sock_daemon.h b/ctdb/common/sock_daemon.h index a28f8c6f39c..fb0c6865328 100644 --- a/ctdb/common/sock_daemon.h +++ b/ctdb/common/sock_daemon.h @@ -214,8 +214,9 @@ int sock_daemon_add_unix(struct sock_daemon_context *sockd, * * @param[in] sockd Socket daemon context * @param[in] fd File descriptor + * @return true on success, false on error */ -void sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd); +bool sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd); /** * @brief Async computation start to run a socket daemon -- 2.19.1 From b528bcc431136499323f5fcd45906ef93fdd76f5 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 10 Oct 2018 18:19:32 +1100 Subject: [PATCH 4/4] ctdb-event: Check the return status of sock_daemon_set_startup_fd BUG: https://bugzilla.samba.org/show_bug.cgi?id=13659 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit a1909603808b994b7822b697494e39e8da4aaa66) --- ctdb/server/ctdb_eventd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ctdb/server/ctdb_eventd.c b/ctdb/server/ctdb_eventd.c index f79ee9990d1..3876acd4a76 100644 --- a/ctdb/server/ctdb_eventd.c +++ b/ctdb/server/ctdb_eventd.c @@ -990,6 +990,7 @@ int main(int argc, const char **argv) struct sock_socket_funcs socket_funcs; struct stat statbuf; int opt, ret; + bool ok; /* Set default options */ options.pid = -1; @@ -1073,7 +1074,10 @@ int main(int argc, const char **argv) } if (options.startup_fd != -1) { - sock_daemon_set_startup_fd(sockd, options.startup_fd); + ok = sock_daemon_set_startup_fd(sockd, options.startup_fd); + if (!ok) { + goto fail; + } } ret = sock_daemon_run(ev, sockd, -- 2.19.1