Class: RealUser::Resolver
- Inherits:
-
Object
- Object
- RealUser::Resolver
- Defined in:
- lib/realuser.rb
Overview
The `Resolver` class provides methods to resolve the real user ID (RUID) of a process and its parent processes, either through a deep search (resolving the root RUID) or a shallow search.
Class Method Summary collapse
-
.deep(pid) ⇒ Integer?
Resolves the real user ID (RUID) of the root process ancestor of the given `pid`.
-
.shallow(pid, pruid = nil) ⇒ Integer?
Resolves the real user ID (RUID) of the given `pid` or its nearest ancestor where the RUID differs from the process's parent RUID.
Class Method Details
.deep(pid) ⇒ Integer?
Resolves the real user ID (RUID) of the root process ancestor of the given `pid`. It recursively traverses the parent processes until it finds the root process.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/realuser.rb', line 81 def self.deep(pid) ppid = ProcFs.ppid(pid) # has parent and parent is not init if ppid && ppid > 1 deep(ppid) else ProcFs.ruid(pid) end end |
.shallow(pid, pruid = nil) ⇒ Integer?
Resolves the real user ID (RUID) of the given `pid` or its nearest ancestor where the RUID differs from the process's parent RUID.
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/realuser.rb', line 98 def self.shallow(pid, pruid = nil) ruid = ProcFs.ruid(pid) return ruid if pruid && (ruid != pruid || ruid.nil?) ppid = ProcFs.ppid(pid) # has parent and parent is not init if ppid && ppid > 1 shallow(ppid, ruid) else ruid end end |