Function ensure_root

Source
pub fn ensure_root() -> Result<(), Error>
Expand description

Checks whether the current process is run by root.

Gets the effective user ID of the current process and checks whether it is 0.

ยงErrors

Returns an error if

  • conversion of PID to usize fails
  • the root user ID can not be converted from "0"
  • no user ID can be retrieved from the current process
  • the process is not run by root