From 37573022c2ca56480e99bf7515dca1c68254690e Mon Sep 17 00:00:00 2001 From: Crimson Date: Fri, 28 Aug 2026 21:52:29 +0500 Subject: [PATCH] fix: use documented swapon show columns --- traffic_core/src/swap/runtime.rs | 34 ++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/traffic_core/src/swap/runtime.rs b/traffic_core/src/swap/runtime.rs index 2916dc5..b3e31f4 100644 --- a/traffic_core/src/swap/runtime.rs +++ b/traffic_core/src/swap/runtime.rs @@ -11,17 +11,17 @@ use std::os::unix::fs::PermissionsExt; use super::model::ActiveSwap; +fn swapon_show_args() -> [&'static str; 4] { + [ + "--show=NAME,TYPE,SIZE,PRIO", + "--bytes", + "--raw", + "--noheadings", + ] +} + pub(super) fn read_active_swaps() -> anyhow::Result> { - let out = Command::new("swapon") - .args([ - "--show", - "--bytes", - "--raw", - "--noheadings", - "--output", - "NAME,TYPE,SIZE,PRIO", - ]) - .output()?; + let out = Command::new("swapon").args(swapon_show_args()).output()?; if !out.status.success() { anyhow::bail!( "swapon --show failed: {}", @@ -111,6 +111,20 @@ pub(super) fn run(program: &str, args: &[&str]) -> anyhow::Result<()> { #[cfg(test)] mod tests { use super::*; + + #[test] + fn swapon_uses_the_documented_show_columns_form() { + assert_eq!( + swapon_show_args(), + [ + "--show=NAME,TYPE,SIZE,PRIO", + "--bytes", + "--raw", + "--noheadings" + ] + ); + } + #[test] fn parse_swapon_empty() { let got = parse_swapon_output("").expect("parse");