def spawn(command)
fork do
File.umask self.umask if self.umask
uid_num = Etc.getpwnam(self.uid).uid if self.uid
gid_num = Etc.getgrnam(self.gid).gid if self.gid
::Dir.chroot(self.chroot) if self.chroot
::Process.setsid
::Process.groups = [gid_num] if self.gid
::Process::Sys.setgid(gid_num) if self.gid
::Process::Sys.setuid(uid_num) if self.uid
self.dir ||= '/'
Dir.chdir self.dir
$0 = command
STDIN.reopen "/dev/null"
if self.log_cmd
STDOUT.reopen IO.popen(self.log_cmd, "a")
else
STDOUT.reopen file_in_chroot(self.log), "a"
end
if err_log_cmd
STDERR.reopen IO.popen(err_log_cmd, "a")
elsif err_log && (log_cmd || err_log != log)
STDERR.reopen file_in_chroot(err_log), "a"
else
STDERR.reopen STDOUT
end
3.upto(256){|fd| IO::new(fd).close rescue nil}
if self.env && self.env.is_a?(Hash)
self.env.each do |(key, value)|
ENV[key] = value.to_s
end
end
exec command unless command.empty?
end
end