Changeset 756

Show
Ignore:
Timestamp:
10/26/07 01:38:20 (11 months ago)
Author:
evanweaver
Message:

that user/group thing is necessary after all #12662

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tags/rel_1-0-2/lib/mongrel/configurator.rb

    r694 r756  
    5656      begin 
    5757        if group && user 
    58           log "Initializing groups for #{user}:#{group}." 
     58          log "Initializing groups for #{user.inspect}:#{group.inspect}." 
    5959          Process.initgroups(user, Etc.getgrnam(group).gid) 
    6060        end 
    6161         
    6262        if group 
    63           log "Changing group to #{group}." 
    64           Process::GID.change_privilege(Etc.getgrnam(group).gid) 
     63          if group && Etc.getgrnam(group).gid != Process.egid 
     64            log "Changing group to #{group.inspect}." 
     65            Process::GID.change_privilege(Etc.getgrnam(group).gid) 
     66          else 
     67            log "Already running as group #{group.inspect}" 
     68          end 
    6569        end 
    6670 
    6771        if user 
    68           log "Changing user to #{user}."  
    69           Process::UID.change_privilege(Etc.getpwnam(user).uid) 
    70         end 
    71       rescue Errno::EPERM 
    72         log "FAILED to change user:group #{user}:#{group}: #$!" 
     72          if user && Etc.getpwnam(user).uid != Process.euid 
     73            log "Changing user to #{user.inspect}."  
     74            Process::UID.change_privilege(Etc.getpwnam(user).uid) 
     75          else 
     76            log "Already running as user #{user.inspect}" 
     77          end 
     78        end 
     79      rescue Errno::EPERM => e 
     80        log "Couldn't change user and group to #{user.inspect}:#{group.inspect}: #{e.to_s}." 
     81        log "Mongrel failed to start." 
    7382        exit 1 
    7483      end