Skip to content

Commit

Permalink
Setting :pgroup_kill => true implies :group => true
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Apr 6, 2015
1 parent 1ad6c77 commit 8db38b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions lib/posix/spawn/child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ class Child
# MaximumOutputExceeded exception.
# :pgroup_kill => bool Boolean specifying whether to kill the process
# group (true) or individual process (false, default).
# Note that `:pgroup => true` must also be
# specified when this option is set true so that
# the new process gets its a new process group.
# Setting this option true implies :pgroup => true.
#
# Returns a new Child instance whose underlying process has already
# executed to completion. The out, err, and status attributes are
Expand All @@ -92,7 +90,10 @@ def initialize(*args)
@input = @options.delete(:input)
@timeout = @options.delete(:timeout)
@max = @options.delete(:max)
@pgroup_kill = @options.delete(:pgroup_kill)
if @options.delete(:pgroup_kill)
@pgroup_kill = true
@options[:pgroup] = true
end
@options.delete(:chdir) if @options[:chdir].nil?
exec! if !@options.delete(:noexec)
end
Expand Down
12 changes: 6 additions & 6 deletions test/test_child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_max
end

def test_max_pgroup_kill
child = Child.build('yes', :max => 100_000, :pgroup => true, :pgroup_kill => true)
child = Child.build('yes', :max => 100_000, :pgroup_kill => true)
assert_raises(MaximumOutputExceeded) { child.exec! }
assert_process_reaped child.pid
assert_process_group_reaped child.pid
Expand All @@ -109,7 +109,7 @@ def test_max_with_child_hierarchy
end

def test_max_with_child_hierarchy_pgroup_kill
child = Child.build('/bin/sh', '-c', 'true && yes', :max => 100_000, :pgroup => true, :pgroup_kill => true)
child = Child.build('/bin/sh', '-c', 'true && yes', :max => 100_000, :pgroup_kill => true)
assert_raises(MaximumOutputExceeded) { child.exec! }
assert_process_reaped child.pid
assert_process_group_reaped child.pid
Expand All @@ -123,7 +123,7 @@ def test_max_with_stubborn_child
end

def test_max_with_stubborn_child_pgroup_kill
child = Child.build("trap '' TERM; yes", :max => 100_000, :pgroup => true, :pgroup_kill => true)
child = Child.build("trap '' TERM; yes", :max => 100_000, :pgroup_kill => true)
assert_raises(MaximumOutputExceeded) { child.exec! }
assert_process_reaped child.pid
assert_process_group_reaped child.pid
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_timeout

def test_timeout_pgroup_kill
start = Time.now
child = Child.build('sleep', '1', :timeout => 0.05, :pgroup => true, :pgroup_kill => true)
child = Child.build('sleep', '1', :timeout => 0.05, :pgroup_kill => true)
assert_raises(TimeoutExceeded) { child.exec! }
assert_process_reaped child.pid
assert_process_group_reaped child.pid
Expand All @@ -175,15 +175,15 @@ def test_timeout_with_child_hierarchy
end

def test_timeout_with_child_hierarchy_pgroup_kill
child = Child.build('/bin/sh', '-c', 'true && sleep 1', :timeout => 0.05, :pgroup => true, :pgroup_kill => true)
child = Child.build('/bin/sh', '-c', 'true && sleep 1', :timeout => 0.05, :pgroup_kill => true)
assert_raises(TimeoutExceeded) { child.exec! }
assert_process_reaped child.pid
assert_process_group_reaped child.pid
end

def test_timeout_with_partial_output
start = Time.now
p = Child.build('echo Hello; sleep 1', :timeout => 0.05, :pgroup => true, :pgroup_kill => true)
p = Child.build('echo Hello; sleep 1', :timeout => 0.05, :pgroup_kill => true)
assert_raises(TimeoutExceeded) { p.exec! }
assert_process_reaped p.pid
assert_process_group_reaped Process.pid
Expand Down

0 comments on commit 8db38b3

Please sign in to comment.