diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-11-16 21:39:31 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-11-16 21:39:31 +0000 |
commit | d5bd1bc50730a42f16d3ed23a435d219c0bec3a6 (patch) | |
tree | f7969ee06f222370e230eb6d279835ad856cd3ba | |
parent | a4562bfba94d18da54ad9560245d0669cc151c76 (diff) | |
download | puppet-d5bd1bc50730a42f16d3ed23a435d219c0bec3a6.tar.gz puppet-d5bd1bc50730a42f16d3ed23a435d219c0bec3a6.tar.xz puppet-d5bd1bc50730a42f16d3ed23a435d219c0bec3a6.zip |
Mostly fixing exec so it either captures stderr or runs as a user; Process.euid was not working correctly
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@743 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-x | lib/puppet/type/exec.rb | 39 | ||||
-rw-r--r-- | lib/puppet/util.rb | 16 | ||||
-rwxr-xr-x | test/puppet/utiltest.rb | 6 |
3 files changed, 31 insertions, 30 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 49f3e8c4c..1c45b7b7f 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -1,7 +1,5 @@ -#!/usr/local/bin/ruby -w - -# $Id$ +require 'open3' require 'puppet/type/state' module Puppet @@ -93,15 +91,30 @@ module Puppet Puppet::Util.asuser(@parent[:user], @parent[:group]) { # capture both stdout and stderr - stderr = Puppet::Util.capture_stderr { + #stdin, stdout, stderr = Open3.popen3(self.parent[:command]) + #@output = stdout.read + #err = stderr.read + + #stderr = Puppet::Util.capture_stderr { + # @output = %x{#{self.parent[:command]}} + #} + if @parent[:user] + unless defined? @@alreadywarned + Puppet.warning( + "Cannot capture STDERR when running as another user" + ) + @@alreadywarned = true + end @output = %x{#{self.parent[:command]}} - } - - if stderr != "" - stderr.split(/\n/).each { |line| - self.send(:err, line) - } + else + @output = %x{#{self.parent[:command]} 2>&1} end + + #if err != "" + # stderr.split(/\n/).each { |line| + # self.send(:err, line) + # } + #end } status = $? @@ -152,7 +165,9 @@ module Puppet @paramdoc[:path] = "The search path used for command execution. Commands must be fully qualified if no path is specified." - @paramdoc[:user] = "The user to run the command as." + @paramdoc[:user] = "The user to run the command as. Note that if you use + this then any error output is not currently captured. This is mostly + because of a bug within Ruby." @paramdoc[:group] = "The group to run the command as." @paramdoc[:cwd] = "The directory from which to run the command. If this directory does not exist, the command will fail." @@ -297,3 +312,5 @@ module Puppet end end end + +# $Id$ diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 6169bde81..e5179a587 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -19,9 +19,9 @@ module Util if group.is_a?(Integer) gid = group else - unless obj = Puppet::Type::Group[user] + unless obj = Puppet::Type::Group[group] obj = Puppet::Type::Group.create( - :name => user, + :name => group, :check => [:gid] ) end @@ -85,18 +85,6 @@ module Util return retval end - # Capture stderr of a block - def self.capture_stderr - require 'stringio' - begin - $stderr = StringIO.new - yield - $stderr.rewind && $stderr.read - ensure - $stderr = STDERR - end - end - # Create instance methods for each of the log levels. This allows # the messages to be a little richer. Most classes will be calling this # method. diff --git a/test/puppet/utiltest.rb b/test/puppet/utiltest.rb index e18971e59..dbcd7e40f 100755 --- a/test/puppet/utiltest.rb +++ b/test/puppet/utiltest.rb @@ -13,6 +13,7 @@ class TestPuppetUtil < Test::Unit::TestCase unless Process.uid == 0 $stderr.puts "Run as root to perform Utility tests" else + def mknverify(file, user, group = nil, id = false) if File.exists?(file) File.unlink(file) @@ -114,11 +115,6 @@ class TestPuppetUtil < Test::Unit::TestCase assert(Process.euid == 0, "UID did not get reset") end end - - def test_capturestderr - str = Puppet::Util.capture_stderr { $stderr.puts("hello world") } - assert_equal("hello world\n", str) - end end # $Id$ |