Class: CurrentProcess

### Home Classes Methods

### In Files

- lib/daemons/change_privilege.rb

### Parent

Object

### Methods

- ::change_privilege

### Class/Module Index

Quicksearch

- Daemons
- Daemons::Application
- Daemons::ApplicationGroup
- Daemons::CmdException
- Daemons::Controller
- Daemons::Error
- Daemons::Exception
- Daemons::Monitor
- Daemons::Optparse
- Daemons::Pid
- Daemons::PidFile
- Daemons::PidMem
- Daemons::RuntimeException
- Daemons::SystemError
- Daemons::TimeoutError
- CurrentProcess
- Daemonize
- Object

No matching classes.

# CurrentProcess

### Public Class Methods

change_privilege(user, group = user) click to toggle source

    # File lib/daemons/change_privilege.rb, line 4
    def self.change_privilege(user, group = user)
      puts "Changing process privilege to #{user}:#{group}"

      uid, gid = Process.euid, Process.egid
      target_uid = Etc.getpwnam(user).uid
      target_gid = Etc.getgrnam(group).gid

      if uid != target_uid || gid != target_gid
        Process.initgroups(user, target_gid)
        Process::GID.change_privilege(target_gid)
        Process::UID.change_privilege(target_uid)
      end
    rescue Errno::EPERM => e
      raise "Couldn't change user and group to #{user}:#{group}: #{e}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.