pub fn run_elevated<S: AsRef<OsStr>>(
program_path: S,
args: &str,
) -> Result<ExitStatus>Expand description
Run a program with elevated privileges.
This function attempts to elevate the program’s privileges by setting the effective user ID to root
using the setuid system call, and then spawns a new process to execute the specified program
with the given arguments.
§Arguments
program_path- The path to the program to execute.args- A single str of arguments to pass to the program.
§Errors
Returns an io::Error if setting the effective user ID to root fails, or if spawning the process fails.
§Examples
use elevator_lib::run_elevated;
// Run a program with elevated privileges
if let Err(err) = run_elevated("/usr/bin/some_program", "arg1 arg2") {
eprintln!("Error: {}", err);
}