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

Function ensure_sysctl

src/executor/helpers/linux_sysctl.rs:60–70  ·  view source on GitHub ↗

Sets a sysctl, returning the value it held before, or `None` when it was already at `target_value` and nothing was written.

(name: &str, target_value: i64)

Source from the content-addressed store, hash-verified

58/// Sets a sysctl, returning the value it held before, or `None` when it was
59/// already at `target_value` and nothing was written.
60pub(crate) fn ensure_sysctl(name: &str, target_value: i64) -> Result<Option<i64>> {
61 let current_value = sysctl_read(name)?;
62 if current_value == target_value {
63 return Ok(None);
64 }
65
66 let assignment = format!("{name}={target_value}");
67 run_with_sudo("sysctl", ["-w", assignment.as_str()])?;
68
69 Ok(Some(current_value))
70}
71
72fn sysctl_read(name: &str) -> Result<i64> {
73 let output = Command::new("sysctl").arg(name).output()?;

Callers 2

setMethod · 0.85
dropMethod · 0.85

Calls 3

sysctl_readFunction · 0.85
run_with_sudoFunction · 0.85
as_strMethod · 0.80

Tested by

no test coverage detected