diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-04-14 14:01:44 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2024-08-19 15:36:49 +0900 |
commit | 566f2eb501d94d4047a9aad4af0d74c6a96f34a9 (patch) | |
tree | f189fa7f2e700b9009c5e50af7ce11ecc34b2dac /process.c | |
parent | 70613595645fc3ae2bdde8f023728e3f10122ffb (diff) |
Merge `rb_fork_ruby2` into `rb_fork_ruby`
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 42 |
1 files changed, 11 insertions, 31 deletions
@@ -4215,50 +4215,30 @@ rb_fork_async_signal_safe(int *status, return result; } -static rb_pid_t -rb_fork_ruby2(struct rb_process_status *status) +rb_pid_t +rb_fork_ruby(int *status) { + struct rb_process_status child = {.status = 0}; rb_pid_t pid; int try_gc = 1, err; struct child_handler_disabler_state old; - if (status) status->status = 0; - - while (1) { + do { prefork(); before_fork_ruby(); disable_child_handler_before_fork(&old); - { - pid = rb_fork(); - err = errno; - if (status) { - status->pid = pid; - status->error = err; - } - } - disable_child_handler_fork_parent(&old); /* yes, bad name */ - after_fork_ruby(pid); - if (pid >= 0) { /* fork succeed */ - return pid; - } + child.pid = pid = rb_fork(); + child.error = err = errno; - /* fork failed */ - if (handle_fork_error(err, status, NULL, &try_gc)) { - return -1; - } - } -} - -rb_pid_t -rb_fork_ruby(int *status) -{ - struct rb_process_status process_status = {0}; + disable_child_handler_fork_parent(&old); /* yes, bad name */ + after_fork_ruby(pid); - rb_pid_t pid = rb_fork_ruby2(&process_status); + /* repeat while fork failed but retryable */ + } while (pid < 0 && handle_fork_error(err, &child, NULL, &try_gc) == 0); - if (status) *status = process_status.status; + if (status) *status = child.status; return pid; } |