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;
}
if (ret != 0) {
DEBUG(10, ("register_with_ctdbd failed: %s\n",
strerror(ret)));
- TALLOC_FREE(result);
return ret;
}
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;
}
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;