diff options
author | kaustubh-d <kaustubh@clogeny.com> | 2014-08-27 22:51:46 +0530 |
---|---|---|
committer | kaustubh-d <kaustubh@clogeny.com> | 2014-08-27 22:51:46 +0530 |
commit | 1a1154e864c6b3e230ae9380c7178bf36a6958ca (patch) | |
tree | c2c0cf9b576b719b1838ba3e60be34d2d3ac766e | |
parent | 8d3f6bc696921b964b8b20c812e1da83714670ca (diff) | |
download | mixlib-shellout-1a1154e864c6b3e230ae9380c7178bf36a6958ca.tar.gz |
fix getpgid issue on aix
-rw-r--r-- | lib/mixlib/shellout/unix.rb | 5 | ||||
-rw-r--r-- | spec/mixlib/shellout_spec.rb | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb index be2e66a..bd9169f 100644 --- a/lib/mixlib/shellout/unix.rb +++ b/lib/mixlib/shellout/unix.rb @@ -305,7 +305,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 ff493c2..3a86c20 100644 --- a/spec/mixlib/shellout_spec.rb +++ b/spec/mixlib/shellout_spec.rb @@ -940,7 +940,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 @@ -1074,7 +1074,9 @@ 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 + 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. + raise "ESRCH error in AIX" if kill_return_val != 0 # Debug the failure: puts "child pgid=#{child_pgid.inspect}" |