Skip to content

Commit 626a030

Browse files
committed
[GR-20446] Fix Process.wait2 to return nil when WNOHANG flag is given and the process is still running
PullRequest: truffleruby/3286
2 parents 5976f4e + 8a5f4e1 commit 626a030

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Compatibility:
1313

1414
* Fix `Marshal.dump` to raise an error when an object has singleton methods (@bjfish).
1515
* `Exception#full_message` now defaults the order to `:top` like CRuby 3+ (@eregon).
16+
* Fix `Process.wait2` to return `nil` when the `WNOHANG` flag is given and the child process is still running (@bjfish).
1617

1718
Performance:
1819

spec/ruby/core/process/wait2_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@
3333
-> { Process.wait2 }.should raise_error(Errno::ECHILD)
3434
-> { Process.wait2 }.should raise_error(StandardError)
3535
end
36+
37+
it "returns nil if the child process is still running when given the WNOHANG flag" do
38+
IO.popen(ruby_cmd('STDIN.getbyte'), "w") do |io|
39+
pid, status = Process.wait2(io.pid, Process::WNOHANG)
40+
pid.should be_nil
41+
status.should be_nil
42+
io.write('a')
43+
end
44+
end
3645
end

spec/tags/core/process/wait2_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
fails:Process.wait2 returns the pid and status of child process
2+
slow:Process.wait2 returns nil if the child process is still running when given the WNOHANG flag

src/main/ruby/truffleruby/core/process.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,11 @@ def self.last_status
541541
#
542542
def self.wait2(input_pid=-1, flags=nil)
543543
status = Truffle::ProcessOperations.wait(input_pid, flags, true, true)
544-
[status.pid, status]
544+
if status
545+
[status.pid, status]
546+
else
547+
nil
548+
end
545549
end
546550

547551
#

0 commit comments

Comments
 (0)