aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-03-06 14:34:18 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-03-06 14:34:18 -0800
commit9ee4e4e05c46669ed9c254188fd5aa83aa5374f2 (patch)
tree06dd764559a77312d5ad5864712d80d78d270ef2 /common.cpp
parentea65a0c5197557af04398726d2d14c6dbfe2908d (diff)
Tweak fork guards to use getpid() instead of pthread_atfork
Diffstat (limited to 'common.cpp')
-rw-r--r--common.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/common.cpp b/common.cpp
index f897cf59..f338b901 100644
--- a/common.cpp
+++ b/common.cpp
@@ -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() {