lib/puppet/util.rb in puppet-0.23.0 vs lib/puppet/util.rb in puppet-0.23.1
- old
+ new
@@ -304,16 +304,20 @@
if ! arguments[:squelch]
require "tempfile"
output_file = Tempfile.new("puppet")
end
+ oldverb = $VERBOSE
+ $VERBOSE = false
child_pid = Kernel.fork
+ $VERBOSE = oldverb
if child_pid
# Parent process executes this
child_status = Process.waitpid2(child_pid)[1]
else
# Child process executes this
+ Process.setsid
begin
$stdin.reopen("/dev/null")
$stdout.reopen(output_file)
$stderr.reopen(output_file)
if arguments[:gid]
@@ -336,13 +340,34 @@
end # begin; rescue
end # if child_pid
# read output in if required
if ! arguments[:squelch]
- output = output_file.open.read
- output_file.close
- output_file.delete
+
+ # Make sure the file's actually there. This is
+ # basically a race condition, and is probably a horrible
+ # way to handle it, but, well, oh well.
+ unless FileTest.exists?(output_file.path)
+ Puppet.warning "sleeping"
+ sleep 0.5
+ unless FileTest.exists?(output_file.path)
+ Puppet.warning "sleeping 2"
+ sleep 1
+ unless FileTest.exists?(output_file.path)
+ Puppet.warning "Could not get output"
+ output = ""
+ end
+ end
+ end
+ unless output
+ # We have to explicitly open here, so that it reopens
+ # after the child writes.
+ output = output_file.open.read
+
+ # The 'true' causes the file to get unlinked right away.
+ output_file.close(true)
+ end
end
if arguments[:failonfail]
unless child_status == 0
raise ExecutionFailure, "Execution of '%s' returned %s: %s" % [str, child_status, output]
@@ -434,6 +459,6 @@
require 'puppet/util/execution'
require 'puppet/util/logging'
require 'puppet/util/package'
require 'puppet/util/warnings'
-# $Id: util.rb 2605 2007-06-18 18:13:23Z luke $
+# $Id: util.rb 2717 2007-07-19 20:02:26Z luke $