From 64e17e6710d26575141ea19e09ffd36eaac118eb Mon Sep 17 00:00:00 2001 From: kaventro <301901286+kaventro@users.noreply.github.com> Date: Mon, 30 Nov 2026 17:51:57 +0100 Subject: [PATCH 1/2] pgrep: accept terminal names without /dev/ prefix The tty of a process is now read from /proc//stat and stored as a full device path like /dev/pts/0. The --terminal value was kept as typed, so "pgrep -t pts/0" or "pgrep -t tty1" never matched anything. Prepend /dev/ to the given name when it is missing. Fixes #179 --- src/uu/pgrep/src/process.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/uu/pgrep/src/process.rs b/src/uu/pgrep/src/process.rs index 8cc62110..11dbefb6 100644 --- a/src/uu/pgrep/src/process.rs +++ b/src/uu/pgrep/src/process.rs @@ -162,7 +162,8 @@ impl TryFrom<&str> for Teletype { type Error = (); fn try_from(value: &str) -> Result { - Self::try_from(PathBuf::from(value)) + let name = value.strip_prefix("/dev/").unwrap_or(value); + Self::try_from(PathBuf::from(format!("/dev/{name}"))) } } @@ -800,6 +801,21 @@ mod tests { #[cfg(target_os = "linux")] use std::collections::HashSet; + #[test] + fn test_teletype_from_name_without_dev_prefix() { + for (input, expected) in [ + ("pts/0", "/dev/pts/0"), + ("tty1", "/dev/tty1"), + ("/dev/pts/0", "/dev/pts/0"), + ("/dev/tty1", "/dev/tty1"), + ] { + assert_eq!( + Teletype::try_from(input), + Ok(Teletype::Known(expected.to_string())) + ); + } + } + #[test] #[cfg(target_os = "linux")] fn test_tty_resolution() { From ef3e374986bda12135df302fc365ebe971fbaf70 Mon Sep 17 00:00:00 2001 From: kaventro <301901286+kaventro@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:02:09 +0100 Subject: [PATCH 2/2] pgrep: build the terminal path directly --- src/uu/pgrep/src/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/pgrep/src/process.rs b/src/uu/pgrep/src/process.rs index 11dbefb6..e3c42029 100644 --- a/src/uu/pgrep/src/process.rs +++ b/src/uu/pgrep/src/process.rs @@ -163,7 +163,7 @@ impl TryFrom<&str> for Teletype { fn try_from(value: &str) -> Result { let name = value.strip_prefix("/dev/").unwrap_or(value); - Self::try_from(PathBuf::from(format!("/dev/{name}"))) + Ok(Self::Known(format!("/dev/{name}"))) } }