Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions ext/proc/wait3.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <ruby/fiber/scheduler.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

/* Debian */
#ifdef HAVE_SYS_RESOURCE_H
Expand Down Expand Up @@ -281,7 +282,14 @@ static VALUE proc_wait3(int argc, VALUE *argv, VALUE mod){
bzero(&args, sizeof(args));
args.flags = flags;

rb_thread_call_without_gvl(wait3_without_gvl, &args, RUBY_UBF_PROCESS, NULL);
/* Retry on EINTR. The RUBY_UBF_PROCESS unblocking function sends a signal
* to interrupt the blocking call. On macOS (and some other platforms),
* wait3() is not automatically restarted after being interrupted, so we
* must retry manually.
*/
do {
rb_thread_call_without_gvl(wait3_without_gvl, &args, RUBY_UBF_PROCESS, NULL);
} while(args.pid < 0 && errno == EINTR);

if(args.pid < 0){
rb_sys_fail("wait3");
Expand Down Expand Up @@ -383,7 +391,14 @@ static VALUE proc_wait4(int argc, VALUE *argv, VALUE mod){
args.pid = pid;
args.flags = flags;

rb_thread_call_without_gvl(wait4_without_gvl, &args, RUBY_UBF_PROCESS, NULL);
/* Retry on EINTR. The RUBY_UBF_PROCESS unblocking function sends a signal
* to interrupt the blocking call. On macOS (and some other platforms),
* wait4() is not automatically restarted after being interrupted, so we
* must retry manually.
*/
do {
rb_thread_call_without_gvl(wait4_without_gvl, &args, RUBY_UBF_PROCESS, NULL);
} while(args.result < 0 && errno == EINTR);

if(args.result < 0){
rb_sys_fail("wait4");
Expand Down Expand Up @@ -491,7 +506,14 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
args.infop.si_pid = 0;
#endif

rb_thread_call_without_gvl(waitid_without_gvl, &args, RUBY_UBF_PROCESS, NULL);
/* Retry on EINTR. The RUBY_UBF_PROCESS unblocking function sends a signal
* to interrupt the blocking call. On macOS (and some other platforms),
* waitid() is not automatically restarted after being interrupted, so we
* must retry manually.
*/
do {
rb_thread_call_without_gvl(waitid_without_gvl, &args, RUBY_UBF_PROCESS, NULL);
} while(args.result == -1 && errno == EINTR);

if(args.result == -1)
rb_sys_fail("waitid");
Expand Down