From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.8 required=3.0 tests=ALL_TRUSTED,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS shortcircuit=no autolearn=no autolearn_force=no version=3.4.1 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0F6C81F83C; Mon, 25 Jun 2018 23:51:00 +0000 (UTC) From: Eric Wong To: spew@80x24.org Cc: Eric Wong Subject: [PATCH 8/8] wip testing Date: Mon, 25 Jun 2018 23:50:51 +0000 Message-Id: <20180625235051.66045-9-e@80x24.org> In-Reply-To: <20180625235051.66045-1-e@80x24.org> References: <20180625235051.66045-1-e@80x24.org> List-Id: --- mjit.c | 5 +++-- process.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mjit.c b/mjit.c index a550d1aabd..2e11395851 100644 --- a/mjit.c +++ b/mjit.c @@ -421,8 +421,9 @@ exec_process(const char *path, char *const argv[]) pid_t r = vm ? ruby_waitpid_locked(vm, pid, &stat, 0, &cond) : waitpid(pid, &stat, 0); if (r == -1) { - if (errno == EINTR) continue; /* should never happen */ - fprintf(stderr, "waitpid: %s\n", strerror(errno)); + if (errno == EINTR) continue; + fprintf(stderr, "[%d] waitpid(%d): %s\n", + getpid(), pid, strerror(errno)); break; } else if (r == pid) { diff --git a/process.c b/process.c index 0b91b30075..ce1445fbaa 100644 --- a/process.c +++ b/process.c @@ -919,7 +919,6 @@ static void waitpid_notify(struct waitpid_state *w, pid_t ret) { w->ret = ret; - if (w->ret == -1) w->errnum = errno; list_del_init(&w->wnode); rb_native_cond_signal(w->cond); } @@ -933,7 +932,9 @@ ruby_waitpid_all(rb_vm_t *vm) rb_native_mutex_lock(&vm->waitpid_lock); list_for_each_safe(&vm->waiting_pids, w, next, wnode) { pid_t ret = do_waitpid(w->pid, &w->status, w->options | WNOHANG); + if (!ret) continue; + if (ret == -1) w->errnum = errno; if (w->ec) { /* rb_waitpid */ rb_thread_t *th = rb_ec_thread_ptr(w->ec); @@ -985,7 +986,7 @@ ruby_waitpid_locked(rb_vm_t *vm, rb_pid_t pid, int *status, int options, if (status) { *status = w.status; } - errno = w.errnum; + if (w.ret == -1) errno = w.errnum; return w.ret; } @@ -1061,7 +1062,11 @@ waitpid_wait(struct waitpid_state *w) } else { w->cond = rb_sleep_cond_get(w->ec); - list_add(&vm->waiting_pids, &w->wnode); + /* order matters, favor specified PIDs rather than -1 or 0 */ + if (w->pid > 0) + list_add(&vm->waiting_pids, &w->wnode); + else + list_add_tail(&vm->waiting_pids, &w->wnode); } rb_native_mutex_unlock(&vm->waitpid_lock); @@ -1086,6 +1091,7 @@ rb_waitpid(rb_pid_t pid, int *st, int flags) if (result > 0) { rb_last_status_set(*st, result); } + if (w.ret == -1) errno = w.errnum; return result; } -- EW