MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / run_with_sudo

Function run_with_sudo

src/executor/helpers/run_with_sudo.rs:99–121  ·  view source on GitHub ↗

Run a command with sudo after validating sudo access

(program: S, argv: I)

Source from the content-addressed store, hash-verified

97
98/// Run a command with sudo after validating sudo access
99pub fn run_with_sudo<S, I, T>(program: S, argv: I) -> Result<()>
100where
101 S: AsRef<OsStr>,
102 I: IntoIterator<Item = T>,
103 T: AsRef<OsStr>,
104{
105 let mut builder = CommandBuilder::new(program);
106 builder.args(argv);
107 debug!("Running command with sudo: {}", builder.as_command_line());
108 let mut cmd = wrap_with_sudo(builder)?.build();
109 let output = cmd
110 .stdout(Stdio::piped())
111 .output()
112 .map_err(|_| anyhow!("Failed to execute command with sudo: {cmd:?}"))?;
113
114 if !output.status.success() {
115 info!("stdout: {}", String::from_utf8_lossy(&output.stdout));
116 error!("stderr: {}", String::from_utf8_lossy(&output.stderr));
117 bail!("Failed to execute command with sudo: {cmd:?}");
118 }
119
120 Ok(())
121}

Callers 4

ensure_sysctlFunction · 0.85
installFunction · 0.85
restore_from_cacheFunction · 0.85

Calls 3

wrap_with_sudoFunction · 0.85
argsMethod · 0.80
buildMethod · 0.80

Tested by

no test coverage detected