Permalink
Browse files

Add multiples groups to process with .gids

  • Loading branch information...
1 parent 59cd9ed commit 45253937ed8a45fa52173620c825eca57c608100 @icy icy committed Jul 20, 2012
Showing with 15 additions and 1 deletion.
  1. +15 −1 lib/god/process.rb
View
@@ -4,7 +4,7 @@ class Process
attr_accessor :name, :uid, :gid, :log, :log_cmd, :err_log, :err_log_cmd,
:start, :stop, :restart, :unix_socket, :chroot, :env, :dir,
- :stop_timeout, :stop_signal, :umask
+ :stop_timeout, :stop_signal, :umask, :gids
def initialize
self.log = '/dev/null'
@@ -80,6 +80,18 @@ def valid?
end
end
+ # if multiple gids is provided
+ if self.gids
+ self.gids.each do |g|
+ begin
+ Etc.getgrnam(g)
+ rescue ArgumentError
+ valid = false
+ applog(self, :error, "GID for '#{g}' does not exist")
+ end
+ end
+ end
+
# dir must exist and be a directory if specified
if self.dir
if !File.exist?(self.dir)
@@ -289,10 +301,12 @@ def spawn(command)
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
+ gids_num = self.gids.map{|g| Etc.getgrnam(g).gid} if self.gids
::Dir.chroot(self.chroot) if self.chroot
::Process.setsid
::Process.groups = [gid_num] if self.gid
+ ::Process.groups |= gids_num unless gids_num.empty?
::Process::Sys.setgid(gid_num) if self.gid
::Process::Sys.setuid(uid_num) if self.uid
self.dir ||= '/'

0 comments on commit 4525393

Please sign in to comment.