diff options
author | root <root@rcn1.VSOFS1.COM> | 2009-03-23 12:37:30 +1100 |
---|---|---|
committer | root <root@rcn1.VSOFS1.COM> | 2009-03-23 12:37:30 +1100 |
commit | dc05c1b80cad4597c8a900d5cce41c5e7731937e (patch) | |
tree | 67062c026d6fe359fa085652c8436a6527ea3e93 /ctdb/client | |
parent | 4d2195c503c3e47107138bcd02b0222d89312a85 (diff) | |
download | samba-dc05c1b80cad4597c8a900d5cce41c5e7731937e.tar.gz samba-dc05c1b80cad4597c8a900d5cce41c5e7731937e.tar.xz samba-dc05c1b80cad4597c8a900d5cce41c5e7731937e.zip |
create a helper function that converts a ctdb instance in daemon mode to become
a ctdb client instance.
use this from the recovery daemon child process to switch to client mode
and connect back to the main daemon
(This used to be ctdb commit 16f31786a031255ab5b3099a0a3c745de973347a)
Diffstat (limited to 'ctdb/client')
-rw-r--r-- | ctdb/client/ctdb_client.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index 16fc03b48ab..1f68c242a13 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -3472,3 +3472,39 @@ int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb) return 0; } + +/* when forking the main daemon and the child process needs to connect back + * to the daemon as a client process, this function can be used to change + * the ctdb context from daemon into client mode + */ +int switch_from_server_to_client(struct ctdb_context *ctdb) +{ + int ret; + + /* shutdown the transport */ + if (ctdb->methods) { + ctdb->methods->shutdown(ctdb); + } + + /* get a new event context */ + talloc_free(ctdb->ev); + ctdb->ev = event_context_init(ctdb); + + close(ctdb->daemon.sd); + ctdb->daemon.sd = -1; + + /* the client does not need to be realtime */ + if (ctdb->do_setsched) { + ctdb_restore_scheduler(ctdb); + } + + /* initialise ctdb */ + ret = ctdb_socket_connect(ctdb); + if (ret != 0) { + DEBUG(DEBUG_ALERT, (__location__ " Failed to init ctdb client\n")); + return -1; + } + + return 0; +} + |