From d21919c8b4abb5151bdac67c373eb5e85f6a84b4 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 19 Nov 2013 16:13:20 +1100 Subject: ctdb-common: Refactor code to keep track of child processes This code can then be used to track child processes created with vfork(). Signed-off-by: Amitay Isaacs Reviewed-by: Michael Adam --- ctdb/common/ctdb_fork.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'ctdb/common') diff --git a/ctdb/common/ctdb_fork.c b/ctdb/common/ctdb_fork.c index d372ae04432..1d7d9aa278d 100644 --- a/ctdb/common/ctdb_fork.c +++ b/ctdb/common/ctdb_fork.c @@ -45,6 +45,19 @@ bool ctdb_is_child_process(void) return is_child; } +void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid) +{ + char *process; + + /* Only CTDB main daemon should track child processes */ + if (getpid() != ctdb->ctdbd_pid) { + return; + } + + process = talloc_asprintf(ctdb->child_processes, "process:%d", (int)pid); + trbt_insert32(ctdb->child_processes, pid, process); +} + /* * This function forks a child process and drops the realtime * scheduler for the child process. @@ -52,7 +65,6 @@ bool ctdb_is_child_process(void) pid_t ctdb_fork_no_free_ringbuffer(struct ctdb_context *ctdb) { pid_t pid; - char *process; pid = fork(); if (pid == -1) { @@ -87,13 +99,7 @@ pid_t ctdb_fork_no_free_ringbuffer(struct ctdb_context *ctdb) return 0; } - if (getpid() != ctdb->ctdbd_pid) { - return pid; - } - - process = talloc_asprintf(ctdb->child_processes, "process:%d", (int)pid); - trbt_insert32(ctdb->child_processes, pid, process); - + ctdb_track_child(ctdb, pid); return pid; } -- cgit