lib/rexec/task.rb in rexec-1.5.2 vs lib/rexec/task.rb in rexec-1.6.0
- old
+ new
@@ -113,10 +113,31 @@
$stderr.puts pipe.readline.chomp
end
end
end
+ def self.prepare_child_environment(command, options)
+ if options[:env!]
+ ENV.clear
+ ENV.update(options[:env!])
+ elsif options[:env]
+ ENV.update(options[:env])
+ end
+
+ if options[:umask]
+ File.umask(options[:umask])
+ end
+
+ if options[:chdir]
+ Dir.chdir(options[:chdir])
+ end
+
+ if options[:preflight]
+ preflight.call(command, options)
+ end
+ end
+
public
# Returns true if the given pid is a current process
def self.running?(pid)
gpid = Process.getpgid(pid) rescue nil
@@ -263,41 +284,25 @@
STDIN.reopen(cin[RD]) if cin[RD]
STDOUT.reopen(cout[WR]) if cout[WR]
STDERR.reopen(cerr[WR]) if cerr[WR]
- if options[:env!]
- ENV.clear
- ENV.update(options[:env!])
- elsif options[:env]
- ENV.update(options[:env])
- end
+ prepare_child_environment(command, options)
- if options[:umask]
- File.umask(options[:umask])
- end
-
- if options[:chdir]
- Dir.chdir(options[:chdir])
- end
-
- if options[:preflight]
- preflight.call(command, options)
- end
-
if command.respond_to? :call
command.call
elsif Array === command
- command = command.dup
-
# If command is a Pathname, we need to convert it to an absolute path if possible,
# otherwise if it is relative it might cause problems.
if command[0].respond_to? :realpath
command[0] = command[0].realpath
end
# exec expects an array of Strings:
command.collect! { |item| item.to_s }
+
+ # Ensure that we DON'T use the shell for execution:
+ command[0] = [command[0], command[0]]
exec *command
else
if command.respond_to? :realpath
command = command.realpath