Fix some logic errors when checking whether or not we need sudo

This commit is contained in:
Gerald Pinder 2025-03-21 12:30:46 -04:00
parent db9bf78c94
commit 67817fe26d
5 changed files with 14 additions and 34 deletions

View file

@ -6,7 +6,7 @@ use std::{
thread,
};
use blue_build_utils::{constants::SUDO_ASKPASS, has_env_var};
use blue_build_utils::{constants::SUDO_ASKPASS, has_env_var, running_as_root};
use comlexr::cmd;
use log::{debug, error, trace, warn};
use nix::{
@ -122,17 +122,17 @@ where
debug!("Killing container {id}");
let status = cmd!(
if cid.requires_sudo {
if cid.requires_sudo && !running_as_root() {
"sudo".to_string()
} else {
cid.container_runtime.to_string()
},
if cid.requires_sudo && has_env_var(SUDO_ASKPASS) => [
if cid.requires_sudo && !running_as_root() && has_env_var(SUDO_ASKPASS) => [
"-A",
"-p",
format!("Password needed to kill container {id}"),
],
if cid.requires_sudo => cid.container_runtime.to_string(),
if cid.requires_sudo && !running_as_root() => cid.container_runtime.to_string(),
"stop",
id
)