Update version according to OSCI-856
[packages/precise/mcollective.git] / lib / mcollective / shell.rb
index 257fc4b5a951f8c0a6fd7342292bc1cc21183ffc..0f113d51976ba97c71ca7dd0ce3ba8f01d336725 100644 (file)
@@ -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}")