X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=lib%2Fmcollective%2Fshell.rb;h=0f113d51976ba97c71ca7dd0ce3ba8f01d336725;hb=d1f1649ba43c5cbc43c4beb2380096ba051d646a;hp=257fc4b5a951f8c0a6fd7342292bc1cc21183ffc;hpb=b87d2f4e68281062df1913440ca5753ae63314a9;p=packages%2Fprecise%2Fmcollective.git diff --git a/lib/mcollective/shell.rb b/lib/mcollective/shell.rb index 257fc4b..0f113d5 100644 --- a/lib/mcollective/shell.rb +++ b/lib/mcollective/shell.rb @@ -67,16 +67,20 @@ module MCollective opts["stdin"] = @stdin if @stdin - # Running waitpid on the cid here will start a thread - # with the waitpid in it, this way even if the thread - # that started this process gets killed due to agent - # timeout or such there will still be a waitpid waiting - # for the child to exit and not leave zombies. + # Check if the parent thread is alive. If it should die, + # and the process spawned by systemu is still alive, + # fire off a blocking waitpid and wait for the process to + # finish so that we can avoid zombies. + thread = Thread.current @status = systemu(@command, opts) do |cid| begin - sleep 1 - Process::waitpid(cid) + while(thread.alive?) + sleep 0.1 + end + + Process.waitpid(cid) if Process.getpgid(cid) rescue SystemExit + rescue Errno::ESRCH rescue Errno::ECHILD rescue Exception => e Log.info("Unexpected exception received while waiting for child process: #{e.class}: #{e}")