diff --git a/io.c b/io.c index 1fafff2c81..8b7e137043 100644 --- a/io.c +++ b/io.c @@ -6871,7 +6871,6 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, # if defined(HAVE_WORKING_FORK) pid = rb_fork_ruby(&status); if (pid == 0) { /* child */ - rb_thread_atfork(); popen_redirect(&arg); rb_io_synchronized(RFILE(orig_stdout)->fptr); rb_io_synchronized(RFILE(orig_stderr)->fptr); diff --git a/process.c b/process.c index e093786600..216aba6750 100644 --- a/process.c +++ b/process.c @@ -4293,8 +4293,10 @@ rb_fork_ruby(int *status) after_fork_ruby(); disable_child_handler_fork_parent(&old); /* yes, bad name */ if (mjit_enabled && pid > 0) mjit_resume(); /* child (pid == 0) is cared by rb_thread_atfork */ - if (pid >= 0) /* fork succeed */ + if (pid >= 0) { /* fork succeed */ + if (pid == 0) rb_thread_atfork(); return pid; + } /* fork failed */ if (handle_fork_error(err, status, NULL, &try_gc)) return -1; @@ -4336,7 +4338,6 @@ rb_f_fork(VALUE obj) switch (pid = rb_fork_ruby(NULL)) { case 0: - rb_thread_atfork(); if (rb_block_given_p()) { int status; rb_protect(rb_yield, Qundef, &status); @@ -7012,7 +7013,7 @@ rb_daemon(int nochdir, int noclose) #define fork_daemon() \ switch (rb_fork_ruby(NULL)) { \ case -1: return -1; \ - case 0: rb_thread_atfork(); break; \ + case 0: break; \ default: _exit(EXIT_SUCCESS); \ }