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)
| 58 | /// Sets a sysctl, returning the value it held before, or `None` when it was |
| 59 | /// already at `target_value` and nothing was written. |
| 60 | pub(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 | |
| 72 | fn sysctl_read(name: &str) -> Result<i64> { |
| 73 | let output = Command::new("sysctl").arg(name).output()?; |
no test coverage detected