summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-10 06:51:05 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-10 06:51:05 +0000
commit8fdd48d69fc41123e99da7761981d3c12eefc8d7 (patch)
tree4f166f114a5c4d7e33b7d9e1f001c2deda833334 /process.c
parentd9f3198dd97333e5cf05572b41a73290713789c9 (diff)
* 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
Diffstat (limited to 'process.c')
-rw-r--r--process.c17
1 files changed, 9 insertions, 8 deletions
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) {