pgrep: The pattern is too long (more than 15 characters) and should be able to match pid correctly. (#617)

* pgrep: The pattern is too long (more than 15 characters) and should be able to match pid correctly.

The PIDs should be obtained in advance. If the PIDs exist, it means the pattern matches, and there should be no length error.

* Placing length error messages in subsequent  could avoid performance penalties.
This commit is contained in:
Franklin-Qi
2026-02-09 16:41:24 +08:00
committed by GitHub
parent 40c3a11417
commit 64be323ce8
+7 -6
View File
@@ -161,18 +161,19 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
));
}
if !settings.full && pattern.len() > 15 {
let msg = format!("pattern that searches for process name longer than 15 characters will result in zero matches\n\
Try `{} -f' option to match against the complete command line.", uucore::util_name());
return Err(USimpleError::new(1, msg));
}
Ok(settings)
}
pub fn find_matching_pids(settings: &Settings) -> UResult<Vec<ProcessInformation>> {
let mut pids = collect_matched_pids(settings)?;
if pids.is_empty() {
if !settings.full && settings.regex.as_str().len() > 15 {
let msg = format!("pattern that searches for process name longer than 15 characters will result in zero matches\n\
Try `{} -f' option to match against the complete command line.", uucore::util_name());
return Err(USimpleError::new(1, msg));
}
uucore::error::set_exit_code(1);
Ok(pids)
} else {