From 8fdd48d69fc41123e99da7761981d3c12eefc8d7 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 10 Jun 2012 06:51:05 +0000 Subject: [PATCH] * process.c (retry_fork): call after_fork except in a child process. (rb_fork_internal): restrict after_fork call condition. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ process.c | 17 +++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 967cb2406b..79d618b254 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Jun 10 15:49:47 2012 Tanaka Akira + + * process.c (retry_fork): call after_fork except in a child process. + (rb_fork_internal): restrict after_fork call condition. + Sun Jun 10 14:19:33 2012 NARUSE, Yui * configure.in: NetBSD 6 adds libexecinfo but it only works on amd64. diff --git a/process.c b/process.c index 451650da0f..1d17ef4f96 100644 --- a/process.c +++ b/process.c @@ -2805,10 +2805,13 @@ retry_fork(int *status, int *ep, int chfunc_is_async_signal_safe) if (!chfunc_is_async_signal_safe) before_fork(); pid = fork(); - if (0 <= pid) - break; + if (pid == 0) /* fork succeed, child process */ + return pid; if (!chfunc_is_async_signal_safe) - after_fork(); + preserving_errno(after_fork()); + if (0 < pid) /* fork succeed, parent process */ + return pid; + /* fork failed */ switch (errno) { case EAGAIN: #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN @@ -2832,7 +2835,6 @@ retry_fork(int *status, int *ep, int chfunc_is_async_signal_safe) return -1; } } - return pid; } static void @@ -2913,9 +2915,10 @@ rb_fork_internal(int *status, int (*chfunc)(void*, char *, size_t), void *charg, pid = retry_fork(status, NULL, FALSE); if (pid < 0) return pid; - if (!pid) + if (!pid) { forked_child = 1; - after_fork(); + after_fork(); + } return pid; } else { @@ -2949,8 +2952,6 @@ rb_fork_internal(int *status, int (*chfunc)(void*, char *, size_t), void *charg, _exit(127); #endif } - if (!chfunc_is_async_signal_safe) - after_fork(); close(ep[1]); error_occured = recv_child_error(ep[0], &state, &exc, &err, errmsg, errmsg_buflen, chfunc_is_async_signal_safe); if (state || error_occured) {