mirror of
https://github.com/uutils/procps.git
synced 2026-06-10 16:14:00 -07:00
pgrep, pkill: Add check for pattern length
pidwait already has a check for this, copy it to the common process_matcher implementation. Some tests need adjustment to not use such long fake names.
This commit is contained in:
@@ -78,6 +78,12 @@ 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ fn test_no_args() {
|
||||
#[test]
|
||||
fn test_non_matching_pattern() {
|
||||
new_ucmd!()
|
||||
.arg("THIS_PATTERN_DOES_NOT_MATCH")
|
||||
.arg("NONMATCHING")
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.no_output();
|
||||
@@ -368,3 +368,13 @@ fn test_invalid_signal() {
|
||||
.fails()
|
||||
.stderr_contains("Unknown signal 'foo'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_too_long_pattern() {
|
||||
new_ucmd!()
|
||||
.arg("THIS_IS_OVER_16_CHARS")
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_contains("pattern that searches for process name longer than 15 characters will result in zero matches");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ fn test_no_args() {
|
||||
#[test]
|
||||
fn test_non_matching_pattern() {
|
||||
new_ucmd!()
|
||||
.arg("THIS_PATTERN_DOES_NOT_MATCH")
|
||||
.arg("NONMATCHING")
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.no_output();
|
||||
@@ -60,3 +60,13 @@ fn test_inverse() {
|
||||
fn test_help() {
|
||||
new_ucmd!().arg("--help").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_too_long_pattern() {
|
||||
new_ucmd!()
|
||||
.arg("THIS_IS_OVER_16_CHARS")
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_contains("pattern that searches for process name longer than 15 characters will result in zero matches");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user