Skip to content

Commit

Permalink
Run rb_syswait on exec failure
Browse files Browse the repository at this point in the history
not only when !w but also when w == WAITPID_LOCK_ONLY.
See also: f7c0cc3 and a226434.
We thought this change was an oversight in the latter commit.

Without this change, the test fails like:

$ make test-all TESTS="../test/ruby/test_process.rb -n test_exec_failure_leaves_no_child" RUN_OPTS="--jit"
...
  1) Failure:
TestProcess#test_exec_failure_leaves_no_child [/home/k0kubun/src/github.com/ruby/ruby/test/ruby/test_process.rb:2493]:
Expected [[26799, #<Process::Status: pid 26799 exit 127>]] to be empty.

Co-Authored-By: Yusuke Endoh <mame@ruby-lang.org>
  • Loading branch information
k0kubun and mame committed May 10, 2020
1 parent 50a6d29 commit 967ae62
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion process.c
Expand Up @@ -4046,7 +4046,7 @@ fork_check_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg,
"only used by extensions");
rb_protect(proc_syswait, (VALUE)pid, status);
}
else if (!w) {
else if (!w || w == WAITPID_LOCK_ONLY) {
rb_syswait(pid);
}
errno = err;
Expand Down
7 changes: 7 additions & 0 deletions test/ruby/test_process.rb
Expand Up @@ -2485,4 +2485,11 @@ def test_last_status
Process.wait spawn(RUBY, "-e", "exit 13")
assert_same(Process.last_status, $?)
end

def test_exec_failure_leaves_no_child
assert_raise(Errno::ENOENT) do
spawn('inexistent_command')
end
assert_empty(Process.waitall)
end
end
8 changes: 0 additions & 8 deletions test/rubygems/test_gem_ext_cmake_builder.rb
Expand Up @@ -14,14 +14,6 @@ def setup
_, status = Open3.capture2e('cmake')
skip 'cmake not present' unless status.success?
rescue Errno::ENOENT
# Open3.capture2e with ENOENT with JIT enabled leaves a zombie process.
# TODO: avoid making the zombie on ENOENT with JIT
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
begin
Process.waitall
rescue Errno::ECHILD
end
end
skip 'cmake not present'
end

Expand Down

0 comments on commit 967ae62

Please sign in to comment.