summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlamont-granquist <lamont@scriptkiddie.org>2014-09-11 12:32:13 -0700
committerlamont-granquist <lamont@scriptkiddie.org>2014-09-11 12:32:13 -0700
commit9c8f613128cdc14e214c8c2f896b75e507a61a4e (patch)
treed7ef525b8baed7770c8f24f4aa789cc5509e6cb5
parent1a06d383c35db211c682a3077520dcb20cf4e5ef (diff)
parent2d9ec7727d2b3890ecd83c611ce09127a8b1724e (diff)
downloadmixlib-shellout-9c8f613128cdc14e214c8c2f896b75e507a61a4e.tar.gz
Merge pull request #57 from ClogenyTechnologies/kd/processgrp-fix
aix getpgid fails when called from parent and parent and child have different session
-rw-r--r--lib/mixlib/shellout/unix.rb5
-rw-r--r--spec/mixlib/shellout_spec.rb25
2 files changed, 18 insertions, 12 deletions
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb
index cd9790a..2bde64a 100644
--- a/lib/mixlib/shellout/unix.rb
+++ b/lib/mixlib/shellout/unix.rb
@@ -280,7 +280,10 @@ module Mixlib
# support the "ONESHOT" optimization (where sh -c does exec without
# forking). To support cleaning up all the children, we need to
# ensure they're in a unique process group.
- Process.setsid
+ # We cannot use setsid here since getpgid fails on AIX with EPERM
+ # when parent and child have different sessions and the parent tries to get the process group,
+ # hence we just create a new process group, and have the same session.
+ Process.setpgrp
configure_subprocess_file_descriptors
diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb
index f7625e1..cb0a33d 100644
--- a/spec/mixlib/shellout_spec.rb
+++ b/spec/mixlib/shellout_spec.rb
@@ -935,7 +935,7 @@ describe Mixlib::ShellOut do
let(:cmd) { [ 'exit' ] }
it "handles ESRCH from getpgid of a zombie", :unix_only do
- Process.stub(:setsid) { exit!(4) }
+ Process.stub(:setpgrp) { exit!(4) }
# there is a small race condition here if the child doesn't get
# scheduled and call exit! before the parent can call getpgid, so run
@@ -1068,16 +1068,19 @@ describe Mixlib::ShellOut do
shell_cmd.stdout.should include("got term in child")
shell_cmd.stdout.should include("got term in grandchild")
- Process.kill(:INT, child_pgid) # should raise ESRCH
-
- # Debug the failure:
- puts "child pgid=#{child_pgid.inspect}"
- Process.wait
- puts "collected process: #{$?.inspect}"
- puts "initial process listing:\n#{initial_process_listing}"
- puts "current process listing:"
- puts `ps -j`
- raise "Failed to kill all expected processes"
+ kill_return_val = Process.kill(:INT, child_pgid) # should raise ESRCH
+ # AIX - kill returns code > 0 for error, where as other platforms return -1. Ruby code signal.c treats < 0 as error and raises exception and hence fails on AIX. So we check the return code for assertions since ruby wont raise an error here.
+
+ if(kill_return_val == 0)
+ # Debug the failure:
+ puts "child pgid=#{child_pgid.inspect}"
+ Process.wait
+ puts "collected process: #{$?.inspect}"
+ puts "initial process listing:\n#{initial_process_listing}"
+ puts "current process listing:"
+ puts `ps -j`
+ raise "Failed to kill all expected processes"
+ end
rescue Errno::ESRCH
# this is what we want
end