1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

util: ctdb_fork() closes all sockets opened by the main daemon

Do some other hosuekeeping including stopping tevent.

Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Signed-off-by: Martin Schwenke <martin@meltin.net>

(This used to be ctdb commit 212298279557a2833ef0f81809b4a5cdac72ca02)
This commit is contained in:
Martin Schwenke 2012-10-02 11:51:24 +10:00
parent 2d719e5c84
commit 75347b8668
2 changed files with 24 additions and 18 deletions

View File

@ -4091,9 +4091,11 @@ 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
/* 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. The child
* process must be created using ctdb_fork() and not fork() -
* ctdb_fork() does some necessary housekeeping.
*/
int switch_from_server_to_client(struct ctdb_context *ctdb, const char *fmt, ...)
{
@ -4105,25 +4107,11 @@ int switch_from_server_to_client(struct ctdb_context *ctdb, const char *fmt, ...
debug_extra = talloc_strdup_append(talloc_vasprintf(NULL, fmt, ap), ":");
va_end(ap);
/* 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);
tevent_loop_allow_nesting(ctdb->ev);
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 */
/* Connect to main CTDB daemon */
ret = ctdb_socket_connect(ctdb);
if (ret != 0) {
DEBUG(DEBUG_ALERT, (__location__ " Failed to init ctdb client\n"));

View File

@ -37,6 +37,24 @@ pid_t ctdb_fork(struct ctdb_context *ctdb)
return -1;
}
if (pid == 0) {
/* Close the Unix Domain socket and the TCP socket.
* This ensures that none of the child processes will
* look like the main daemon when it is not running.
* tevent needs to be stopped before closing sockets.
*/
if (ctdb->ev != NULL) {
talloc_free(ctdb->ev);
ctdb->ev = NULL;
}
if (ctdb->daemon.sd != -1) {
close(ctdb->daemon.sd);
ctdb->daemon.sd = -1;
}
if (ctdb->methods != NULL) {
ctdb->methods->shutdown(ctdb);
}
/* The child does not need to be realtime */
if (ctdb->do_setsched) {
ctdb_restore_scheduler(ctdb);
}