ctdb-common: Handle errors on unexpected socket close in sock_daemon
authorAmitay Isaacs <amitay@gmail.com>
Fri, 17 Nov 2017 01:31:16 +0000 (12:31 +1100)
committerMartin Schwenke <martins@samba.org>
Tue, 21 Nov 2017 04:03:17 +0000 (05:03 +0100)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/common/sock_daemon.c

index ae291d773c3881b04048bae2e8c24d069a834ffa..0ef016668831ce877af6763cd3198b5a69777dea 100644 (file)
@@ -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);