Skip to main content

execute_with_sudo

Function execute_with_sudo 

Source
pub fn execute_with_sudo(command: &str, args: &[&str]) -> Result<Output>
Expand description

Execute a command with sudo if not already root.

If a password was previously cached via crate::auth::cache_sudo_password (set by crate::auth::authenticate_sudo on success), it is piped directly to sudo -S for this specific command — the same reliable mechanism used to validate it in the first place. This avoids depending on sudo’s own credential cache, which is normally keyed per-TTY/session and is not guaranteed to be reusable across separate child processes spawned by a GUI front-end that has no controlling TTY at all.

Falls back to non-interactive sudo -n (relying on sudo’s own ticket cache) when no password has been cached — e.g. the TUI/CLI, which pre-authenticates via a real interactive sudo -v prompt on an actual terminal and never captures the raw password.