From c6373aba00dd7a69b2e69c979510e3de04700b2d Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 9 Jul 2016 13:20:01 +0200 Subject: [PATCH] s3-messaging/ctdb: split messaging_ctdbd_init() Split out and internal function from messaging_ctdbd_init() that does the connection setup. Keep the conn object allocation in messaging_ctdbd_init(). This is in preperation of adding messaging_ctdbd_reinit() which will use the new internal function as well. messaging_ctdbd_init_internal() has a new reinit flag, messaging_ctdbd_init() calls with reinit=false resulting in unmodified behaviour. Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke --- source3/lib/messages_ctdbd.c | 79 ++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/source3/lib/messages_ctdbd.c b/source3/lib/messages_ctdbd.c index 1645ccf457e..cdf8fb7ca0f 100644 --- a/source3/lib/messages_ctdbd.c +++ b/source3/lib/messages_ctdbd.c @@ -174,41 +174,40 @@ static void messaging_ctdbd_readable(struct tevent_context *ev, ctdbd_socket_readable(conn); } -int messaging_ctdbd_init(struct messaging_context *msg_ctx, - TALLOC_CTX *mem_ctx, - struct messaging_backend **presult) +static int messaging_ctdbd_init_internal(struct messaging_context *msg_ctx, + TALLOC_CTX *mem_ctx, + struct messaging_ctdbd_context *ctx, + bool reinit) { - struct messaging_backend *result; - struct messaging_ctdbd_context *ctx; struct tevent_context *ev; int ret, ctdb_fd; - if (!(result = talloc(mem_ctx, struct messaging_backend))) { - DEBUG(0, ("talloc failed\n")); - return ENOMEM; - } - - if (!(ctx = talloc(result, struct messaging_ctdbd_context))) { - DEBUG(0, ("talloc failed\n")); - TALLOC_FREE(result); - return ENOMEM; - } - - ret = ctdbd_init_connection(ctx, lp_ctdbd_socket(), - lp_ctdb_timeout(), &ctx->conn); - - if (ret != 0) { - DBG_DEBUG("ctdbd_init_connection failed: %s\n", - strerror(ret)); - TALLOC_FREE(result); - return ret; + if (reinit) { + ret = ctdbd_reinit_connection(ctx, + lp_ctdbd_socket(), + lp_ctdb_timeout(), + ctx->conn); + if (ret != 0) { + DBG_ERR("ctdbd_reinit_connection failed: %s\n", + strerror(ret)); + return ret; + } + } else { + ret = ctdbd_init_connection(ctx, + lp_ctdbd_socket(), + lp_ctdb_timeout(), + &ctx->conn); + if (ret != 0) { + DBG_ERR("ctdbd_init_connection failed: %s\n", + strerror(ret)); + return ret; + } } ret = register_with_ctdbd(ctx->conn, MSG_SRVID_SAMBA, NULL, NULL); if (ret != 0) { DBG_DEBUG("Could not register MSG_SRVID_SAMBA: %s\n", strerror(ret)); - TALLOC_FREE(result); return ret; } @@ -217,7 +216,6 @@ int messaging_ctdbd_init(struct messaging_context *msg_ctx, if (ret != 0) { DEBUG(10, ("register_with_ctdbd failed: %s\n", strerror(ret))); - TALLOC_FREE(result); return ret; } @@ -227,7 +225,6 @@ int messaging_ctdbd_init(struct messaging_context *msg_ctx, ctx->fde = tevent_add_fd(ev, ctx, ctdb_fd, TEVENT_FD_READ, messaging_ctdbd_readable, ctx->conn); if (ctx->fde == NULL) { - TALLOC_FREE(result); return ENOMEM; } @@ -237,6 +234,34 @@ int messaging_ctdbd_init(struct messaging_context *msg_ctx, set_my_vnn(ctdbd_vnn(ctx->conn)); + return 0; +} + +int messaging_ctdbd_init(struct messaging_context *msg_ctx, + TALLOC_CTX *mem_ctx, + struct messaging_backend **presult) +{ + struct messaging_backend *result; + struct messaging_ctdbd_context *ctx; + int ret; + + if (!(result = talloc(mem_ctx, struct messaging_backend))) { + DEBUG(0, ("talloc failed\n")); + return ENOMEM; + } + + if (!(ctx = talloc(result, struct messaging_ctdbd_context))) { + DEBUG(0, ("talloc failed\n")); + TALLOC_FREE(result); + return ENOMEM; + } + + ret = messaging_ctdbd_init_internal(msg_ctx, mem_ctx, ctx, false); + if (ret != 0) { + TALLOC_FREE(result); + return ret; + } + result->send_fn = messaging_ctdb_send; result->private_data = (void *)ctx; -- 2.47.3