mirror of
https://github.com/uutils/procps.git
synced 2026-05-06 06:06:43 -04:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user