Skip to content

Commit 8a5f4e1

Browse files
committed
Fix Process.wait2 to return nil when WNOHANG flag is given and the process is still running
1 parent fdabe1f commit 8a5f4e1

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
@@ -12,6 +12,7 @@ Bug fixes:
1212
Compatibility:
1313

1414
* Fix `Marshal.dump` to raise an error when an object has singleton methods (@bjfish).
15+
* Fix `Process.wait2` to return `nil` when the `WNOHANG` flag is given and the child process is still running (@bjfish).
1516

1617
Performance:
1718

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)