Skip to content

Commit 3121ea2

Browse files
Merge branch 'main' into renovate/nix-0.x
2 parents 0e632a4 + a7412c4 commit 3121ea2

6 files changed

Lines changed: 105 additions & 31 deletions

File tree

Cargo.lock

Lines changed: 51 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ clap = { version = "4.5.4", features = ["wrap_help", "cargo", "env"] }
6161
clap_complete = "4.5.2"
6262
clap_mangen = "0.3.0"
6363
crossterm = "0.29.0"
64-
ctor = "0.8.0"
64+
ctor = "0.10.0"
6565
dirs = "6.0.0"
6666
jiff = "0.2.15"
6767
nix = { version = "0.31", default-features = false, features = ["process"] }

src/uu/ps/src/process_selection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct ProcessSelectionSettings {
7171
impl ProcessSelectionSettings {
7272
pub fn from_matches(matches: &ArgMatches) -> Self {
7373
Self {
74-
select_all: matches.get_flag("A"),
74+
select_all: matches.get_flag("A") || matches.get_flag("e"),
7575
select_non_session_leaders_with_tty: matches.get_flag("a"),
7676
select_non_session_leaders: matches.get_flag("d"),
7777
dont_require_tty: matches.get_flag("x"),

src/uu/ps/src/ps.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ pub fn uu_app() -> Command {
202202
Arg::new("A")
203203
.short('A')
204204
.help("all processes")
205-
.visible_short_alias('e')
205+
.action(ArgAction::SetTrue),
206+
Arg::new("e")
207+
.short('e')
208+
.help("Select all processes. Identical to -A")
206209
.action(ArgAction::SetTrue),
207210
Arg::new("a")
208211
.short('a')

src/uu/vmstat/src/parser.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ pub struct Meminfo {
211211
pub swap_total: bytesize::ByteSize,
212212
pub swap_free: bytesize::ByteSize,
213213
}
214+
215+
#[cfg(target_os = "linux")]
216+
fn kb_to_kib(mut size: bytesize::ByteSize) -> bytesize::ByteSize {
217+
// "kB" means KiB instead of KB
218+
// Convert from 1000-based(parsed by bytesize from "kB" ended string) to 1024-based(which it actually is)
219+
// See more at https://github.com/uutils/procps/issues/667
220+
size.0 = size.0 / 1000 * 1024;
221+
size
222+
}
223+
214224
#[cfg(target_os = "linux")]
215225
impl Meminfo {
216226
pub fn current() -> Self {
@@ -221,20 +231,28 @@ impl Meminfo {
221231
pub fn from_proc_map(proc_map: &HashMap<String, String>) -> Self {
222232
use std::str::FromStr;
223233

224-
let mem_total = bytesize::ByteSize::from_str(proc_map.get("MemTotal").unwrap()).unwrap();
225-
let mem_free = bytesize::ByteSize::from_str(proc_map.get("MemFree").unwrap()).unwrap();
234+
let mem_total =
235+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("MemTotal").unwrap()).unwrap());
236+
let mem_free =
237+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("MemFree").unwrap()).unwrap());
226238
let mem_available =
227-
bytesize::ByteSize::from_str(proc_map.get("MemAvailable").unwrap()).unwrap();
228-
let buffers = bytesize::ByteSize::from_str(proc_map.get("Buffers").unwrap()).unwrap();
229-
let cached = bytesize::ByteSize::from_str(proc_map.get("Cached").unwrap()).unwrap();
239+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("MemAvailable").unwrap()).unwrap());
240+
let buffers =
241+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("Buffers").unwrap()).unwrap());
242+
let cached =
243+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("Cached").unwrap()).unwrap());
230244
let s_reclaimable =
231-
bytesize::ByteSize::from_str(proc_map.get("SReclaimable").unwrap()).unwrap();
245+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("SReclaimable").unwrap()).unwrap());
232246
let swap_cached =
233-
bytesize::ByteSize::from_str(proc_map.get("SwapCached").unwrap()).unwrap();
234-
let active = bytesize::ByteSize::from_str(proc_map.get("Active").unwrap()).unwrap();
235-
let inactive = bytesize::ByteSize::from_str(proc_map.get("Inactive").unwrap()).unwrap();
236-
let swap_total = bytesize::ByteSize::from_str(proc_map.get("SwapTotal").unwrap()).unwrap();
237-
let swap_free = bytesize::ByteSize::from_str(proc_map.get("SwapFree").unwrap()).unwrap();
247+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("SwapCached").unwrap()).unwrap());
248+
let active =
249+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("Active").unwrap()).unwrap());
250+
let inactive =
251+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("Inactive").unwrap()).unwrap());
252+
let swap_total =
253+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("SwapTotal").unwrap()).unwrap());
254+
let swap_free =
255+
kb_to_kib(bytesize::ByteSize::from_str(proc_map.get("SwapFree").unwrap()).unwrap());
238256
Self {
239257
mem_total,
240258
mem_free,
@@ -258,7 +276,7 @@ pub struct DiskStatParseError;
258276
#[cfg(target_os = "linux")]
259277
impl Display for DiskStatParseError {
260278
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
261-
std::fmt::Debug::fmt("Failed to parse diskstat line", f)
279+
Debug::fmt("Failed to parse diskstat line", f)
262280
}
263281
}
264282

tests/by-util/test_ps.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,24 @@ use uucore::process::geteuid;
1313
#[test]
1414
#[cfg(target_os = "linux")]
1515
fn test_select_all_processes() {
16-
for arg in ["-A", "-e"] {
17-
// TODO ensure the output format is correct
18-
new_ucmd!().arg(arg).succeeds();
16+
let expected_headers = ["PID", "TTY", "TIME", "CMD"];
17+
18+
let args_sets = vec![vec!["-A"], vec!["-e"], vec!["-A", "-e"]];
19+
for args in args_sets {
20+
let result = new_ucmd!().args(&args).succeeds();
21+
let lines: Vec<&str> = result.stdout_str().lines().collect();
22+
23+
assert!(
24+
lines.len() >= 2,
25+
"expected at least a header and one process row"
26+
);
27+
28+
let headers: Vec<&str> = lines[0].split_whitespace().collect();
29+
assert_eq!(
30+
headers, expected_headers,
31+
"unexpected header for args: {:?}",
32+
args
33+
);
1934
}
2035
}
2136

0 commit comments

Comments
 (0)