diff options
author | Amitay Isaacs <amitay@gmail.com> | 2013-11-19 16:13:20 +1100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2013-11-27 18:46:16 +0100 |
commit | d21919c8b4abb5151bdac67c373eb5e85f6a84b4 (patch) | |
tree | cc594eb7a23dd2e63d237cbe69183bc8f206102a /ctdb/common | |
parent | 86802b05f62384348084bd1cae166ff8fb72bdbe (diff) | |
download | samba-d21919c8b4abb5151bdac67c373eb5e85f6a84b4.tar.gz samba-d21919c8b4abb5151bdac67c373eb5e85f6a84b4.tar.xz samba-d21919c8b4abb5151bdac67c373eb5e85f6a84b4.zip |
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 <amitay@gmail.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'ctdb/common')
-rw-r--r-- | ctdb/common/ctdb_fork.c | 22 |
1 files changed, 14 insertions, 8 deletions
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; } |