Module: Process::Daemon::Privileges
- Defined in:
- lib/process/daemon/privileges.rb
Overview
Provides functions for changing the current user.
Class Method Summary collapse
-
.change_user(user) ⇒ Object
Set the user of the current process.
-
.current_user ⇒ Object
Get the user of the current process.
Class Method Details
.change_user(user) ⇒ Object
Set the user of the current process. Supply either a user ID or a user name.
29 30 31 32 33 34 35 |
# File 'lib/process/daemon/privileges.rb', line 29 def self.change_user(user) if user.kind_of?(String) user = Etc.getpwnam(user).uid end Process::Sys.setuid(user) end |
.current_user ⇒ Object
Get the user of the current process. Returns the user name.
38 39 40 41 42 |
# File 'lib/process/daemon/privileges.rb', line 38 def self.current_user uid = Process::Sys.getuid Etc.getpwuid(uid).name end |