summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-11-16 21:39:31 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-11-16 21:39:31 +0000
commitd5bd1bc50730a42f16d3ed23a435d219c0bec3a6 (patch)
treef7969ee06f222370e230eb6d279835ad856cd3ba /lib
parenta4562bfba94d18da54ad9560245d0669cc151c76 (diff)
downloadpuppet-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
Diffstat (limited to 'lib')
-rwxr-xr-xlib/puppet/type/exec.rb39
-rw-r--r--lib/puppet/util.rb16
2 files changed, 30 insertions, 25 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.