diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-03-06 14:34:18 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-03-06 14:34:18 -0800 |
commit | 9ee4e4e05c46669ed9c254188fd5aa83aa5374f2 (patch) | |
tree | 06dd764559a77312d5ad5864712d80d78d270ef2 /common.cpp | |
parent | ea65a0c5197557af04398726d2d14c6dbfe2908d (diff) |
Tweak fork guards to use getpid() instead of pthread_atfork
Diffstat (limited to 'common.cpp')
-rw-r--r-- | common.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -1951,12 +1951,9 @@ void set_main_thread() { /* Notice when we've forked */ -static bool is_child_of_fork = false; -static void child_note_forked(void) { - is_child_of_fork = true; -} - +static pid_t initial_pid; bool is_forked_child(void) { + bool is_child_of_fork = (getpid() != initial_pid); if (is_child_of_fork) { printf("Uh-oh: %d\n", getpid()); while (1) sleep(10000); @@ -1965,8 +1962,8 @@ bool is_forked_child(void) { } void setup_fork_guards(void) { - /* Notice when we fork */ - pthread_atfork(NULL /* prepare */, NULL /* parent */, child_note_forked); + /* Notice when we fork by stashing our pid. This seems simpler than pthread_atfork(). */ + initial_pid = getpid(); } static bool is_main_thread() { |