summaryrefslogtreecommitdiff
path: root/ctdb/common
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2018-08-24 14:44:12 +1000
committerAmitay Isaacs <amitay@samba.org>2018-08-30 04:48:56 +0200
commitdc6040c121c65d5551c686f3f1be2891795f48aa (patch)
tree70437c84c98f9c9068a4a35660b23d8b97f59619 /ctdb/common
parent99d6237a63fb59bf851fe846633f2a041d0d9a4d (diff)
downloadsamba-dc6040c121c65d5551c686f3f1be2891795f48aa.tar.gz
ctdb-common: Add support for sock daemon to notify of successful startup
The daemon writes 0 into the specified file descriptor when it is up and listening. This can be used to avoid loops in clients that attempt to connect until they succeed. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13592 Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/common')
-rw-r--r--ctdb/common/sock_daemon.c26
-rw-r--r--ctdb/common/sock_daemon.h10
2 files changed, 36 insertions, 0 deletions
diff --git a/ctdb/common/sock_daemon.c b/ctdb/common/sock_daemon.c
index 3c17519ff89..90f6bce2fd3 100644
--- a/ctdb/common/sock_daemon.c
+++ b/ctdb/common/sock_daemon.c
@@ -31,6 +31,7 @@
#include "lib/util/dlinklist.h"
#include "lib/util/tevent_unix.h"
#include "lib/util/become_daemon.h"
+#include "lib/util/sys_rw.h"
#include "common/logging.h"
#include "common/reqid.h"
@@ -72,6 +73,7 @@ struct sock_daemon_context {
struct pidfile_context *pid_ctx;
struct sock_socket *socket_list;
+ int startup_fd;
};
/*
@@ -489,6 +491,7 @@ int sock_daemon_setup(TALLOC_CTX *mem_ctx, const char *daemon_name,
sockd->funcs = funcs;
sockd->private_data = private_data;
+ sockd->startup_fd = -1;
ret = logging_init(sockd, logging, debug_level, daemon_name);
if (ret != 0) {
@@ -520,6 +523,11 @@ 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)
+{
+ sockd->startup_fd = fd;
+}
+
/*
* Run socket daemon
*/
@@ -549,6 +557,7 @@ static void sock_daemon_run_socket_fail(struct tevent_req *subreq);
static void sock_daemon_run_watch_pid(struct tevent_req *subreq);
static void sock_daemon_run_wait(struct tevent_req *req);
static void sock_daemon_run_wait_done(struct tevent_req *subreq);
+static void sock_daemon_startup_notify(struct sock_daemon_context *sockd);
struct tevent_req *sock_daemon_run_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -675,6 +684,8 @@ static void sock_daemon_run_started(struct tevent_req *subreq)
return;
}
sock_daemon_run_wait(req);
+
+ sock_daemon_startup_notify(sockd);
}
static void sock_daemon_run_startup_done(struct tevent_req *subreq)
@@ -702,6 +713,8 @@ static void sock_daemon_run_startup_done(struct tevent_req *subreq)
return;
}
sock_daemon_run_wait(req);
+
+ sock_daemon_startup_notify(sockd);
}
static void sock_daemon_run_signal_handler(struct tevent_context *ev,
@@ -967,6 +980,19 @@ static void sock_daemon_run_wait_done(struct tevent_req *subreq)
sock_daemon_run_shutdown(req);
}
+static void sock_daemon_startup_notify(struct sock_daemon_context *sockd)
+{
+ if (sockd->startup_fd != -1) {
+ unsigned int zero = 0;
+ ssize_t num;
+
+ num = sys_write(sockd->startup_fd, &zero, sizeof(zero));
+ if (num != sizeof(zero)) {
+ D_WARNING("Failed to write zero to pipe FD\n");
+ }
+ }
+}
+
bool sock_daemon_run_recv(struct tevent_req *req, int *perr)
{
int ret;
diff --git a/ctdb/common/sock_daemon.h b/ctdb/common/sock_daemon.h
index 705c4fab359..972245a9650 100644
--- a/ctdb/common/sock_daemon.h
+++ b/ctdb/common/sock_daemon.h
@@ -210,6 +210,16 @@ int sock_daemon_add_unix(struct sock_daemon_context *sockd,
void *private_data);
/**
+ * @brief Set file descriptor for indicating startup success
+ *
+ * On successful completion, 0 (unsigned int) will be written to the fd.
+ *
+ * @param[in] sockd Socket daemon context
+ * @param[in] fd File descriptor
+ */
+void sock_daemon_set_startup_fd(struct sock_daemon_context *sockd, int fd);
+
+/**
* @brief Async computation start to run a socket daemon
*
* @param[in] mem_ctx Talloc memory context