From 3b8f0cc21dd18e84ee78d0450d6f89435abf8dc1 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 17 Nov 2017 12:31:16 +1100 Subject: [PATCH] ctdb-common: Handle errors on unexpected socket close in sock_daemon Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/common/sock_daemon.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ctdb/common/sock_daemon.c b/ctdb/common/sock_daemon.c index ae291d773c3..0ef01666883 100644 --- a/ctdb/common/sock_daemon.c +++ b/ctdb/common/sock_daemon.c @@ -265,7 +265,11 @@ static int sock_socket_init(TALLOC_CTX *mem_ctx, const char *sockpath, return ENOMEM; } - sock->sockpath = sockpath; + sock->sockpath = talloc_strdup(sock, sockpath); + if (sock->sockpath == NULL) { + talloc_free(sock); + return ENOMEM; + } sock->funcs = funcs; sock->private_data = private_data; sock->fd = -1; @@ -405,7 +409,8 @@ static int sock_socket_start_client_destructor(struct sock_client *client) return 0; } -static bool sock_socket_start_recv(struct tevent_req *req, int *perr) +static bool sock_socket_start_recv(struct tevent_req *req, int *perr, + TALLOC_CTX *mem_ctx, const char **sockpath) { struct sock_socket_start_state *state = tevent_req_data( req, struct sock_socket_start_state); @@ -420,6 +425,10 @@ static bool sock_socket_start_recv(struct tevent_req *req, int *perr) return false; } + if (sockpath != NULL) { + *sockpath = talloc_steal(mem_ctx, state->sock->sockpath); + } + return true; } @@ -735,13 +744,17 @@ static void sock_daemon_run_socket_fail(struct tevent_req *subreq) { struct tevent_req *req = tevent_req_callback_data( subreq, struct tevent_req); + struct sock_daemon_run_state *state = tevent_req_data( + req, struct sock_daemon_run_state); + const char *sockpath = NULL; int ret = 0; bool status; - status = sock_socket_start_recv(subreq, &ret); + status = sock_socket_start_recv(subreq, &ret, state, &sockpath); TALLOC_FREE(subreq); sock_daemon_run_shutdown(req); if (! status) { + D_ERR("socket %s closed unexpectedly\n", sockpath); tevent_req_error(req, ret); } else { tevent_req_done(req); -- 2.47.3