From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 14/14] process.c (rb_waitpid): reimplement non-SIGCHLD code path
Date: Tue, 26 Jun 2018 09:38:17 +0000 [thread overview]
Message-ID: <20180626093817.1533-15-e@80x24.org> (raw)
In-Reply-To: <20180626093817.1533-1-e@80x24.org>
This is only compile-tested, but should work the same way
it did for platforms without SIGCHLD (I don't know which...)
---
process.c | 42 +++++++++++++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 7 deletions(-)
diff --git a/process.c b/process.c
index 12a6d9b7b7..4f23bb5469 100644
--- a/process.c
+++ b/process.c
@@ -1085,23 +1085,51 @@ waitpid_wait(struct waitpid_state *w)
}
}
+static void *
+waitpid_blocking_no_SIGCHLD(void *x)
+{
+ struct waitpid_state *w = x;
+
+ w->ret = do_waitpid(w->pid, &w->status, w->options);
+
+ return 0;
+}
+
+static void
+waitpid_no_SIGCHLD(struct waitpid_state *w)
+{
+ if (w->options & WNOHANG) {
+ w->ret = do_waitpid(w->pid, &w->status, w->options);
+ }
+ else {
+ do {
+ rb_thread_call_without_gvl(waitpid_blocking_no_SIGCHLD, &w,
+ RUBY_UBF_PROCESS, 0);
+ } while (w->ret < 0 && errno == EINTR && (RUBY_VM_CHECK_INTS(w->ec),1));
+ }
+}
+
rb_pid_t
rb_waitpid(rb_pid_t pid, int *st, int flags)
{
- rb_pid_t result;
struct waitpid_state w;
waitpid_state_init(&w, pid, flags);
w.ec = GET_EC();
- waitpid_wait(&w);
- if (st) *st = w.status;
- result = w.ret;
- if (result > 0) {
- rb_last_status_set(*st, result);
+ if (RUBY_SIGCHLD) {
+ waitpid_wait(&w);
+ }
+ else {
+ waitpid_no_SIGCHLD(&w);
+ }
+
+ if (st) *st = w.status;
+ if (w.ret > 0) {
+ rb_last_status_set(w.status, w.ret);
}
if (w.ret == -1) errno = w.errnum;
- return result;
+ return w.ret;
}
--
EW
next prev parent reply other threads:[~2018-06-26 9:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-26 9:38 [PATCH 00/14] SIGCHLD hijack for waitpid Eric Wong
2018-06-26 9:38 ` [PATCH 01/14] hijack SIGCHLD handler for internal use Eric Wong
2018-06-26 9:38 ` [PATCH 02/14] fix SIGCHLD hijacking race conditions Eric Wong
2018-06-26 9:38 ` [PATCH 03/14] mjit.c: allow working on platforms without SIGCHLD Eric Wong
2018-06-26 9:38 ` [PATCH 04/14] cleanups Eric Wong
2018-06-26 9:38 ` [PATCH 05/14] handle SIGCHLD in both the timer-thread and main thread Eric Wong
2018-06-26 9:38 ` [PATCH 06/14] Revert "test_process.rb: skip tests for Bug 14867" Eric Wong
2018-06-26 9:38 ` [PATCH 07/14] Revert "spec: skip Process wait specs on MJIT" Eric Wong
2018-06-26 9:38 ` [PATCH 08/14] wip testing Eric Wong
2018-06-26 9:38 ` [PATCH 09/14] pgrp list Eric Wong
2018-06-26 9:38 ` [PATCH 10/14] grantpt Eric Wong
2018-06-26 9:38 ` [PATCH 11/14] blocking mjit_finish Eric Wong
2018-06-26 9:38 ` [PATCH 12/14] reinitialize waitpid_lock Eric Wong
2018-06-26 9:38 ` [PATCH 13/14] signal.c: prevent spurious wakeup of main thread for SIGCHLD Eric Wong
2018-06-26 9:38 ` Eric Wong [this message]
2018-06-26 10:51 ` [PATCH 15/14] force SIGCHLD to the timer-thread Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180626093817.1533-15-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).