Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/uu/pgrep/src/process_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,20 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
pub fn find_matching_pids(settings: &Settings) -> UResult<Vec<ProcessInformation>> {
let mut pids = collect_matched_pids(settings)?;

let is_long_match = if settings.exact {
settings
.regex
.as_str()
.trim_matches('^')
.trim_matches('$')
.len()
> 15
} else {
settings.regex.as_str().len() > 15
};

if pids.is_empty() {
if !settings.full && settings.regex.as_str().len() > 15 {
if !settings.full && is_long_match {
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));
Expand Down
29 changes: 28 additions & 1 deletion tests/by-util/test_pgrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ fn test_pidfile_fcntl_locked() {

// spawn a flock process that locks the file
let mut flock_process = Command::new("flock")
.arg("--fcntl")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sylvestre Thanks for your reply. When the --fcntl option is present, executing cargo test --all on ubuntu 25.10 will report an error:

failures:

---- test_pgrep::test_pidfile_fcntl_locked stdout ----
bin: "/home/ysq/code/procps/target/debug/procps"
run: /home/ysq/code/procps/target/debug/procps pgrep --logpidfile --pidfile /tmp/.tmpWhyLfW

thread 'test_pgrep::test_pidfile_fcntl_locked' (23065) panicked at tests/by-util/test_pgrep.rs:668:10:
Command was expected to succeed. code: 1
stdout = 
 stderr = pgrep: Pidfile /tmp/.tmpWhyLfW is not locked

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    test_pgrep::test_pidfile_fcntl_locked

test result: FAILED. 197 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 4.92s

error: test failed, to rerun pass `-p procps --test tests`

There is also a note: “CI runner doesn't support flock --fcntl”. Therefore, modifications were made to handle this error.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... this seems like a very strange issue.

There is also a note: “CI runner doesn't support flock --fcntl”.

Where is this note mentioned?

.arg(temp_file.path())
.arg("sleep")
.arg("2")
Expand Down Expand Up @@ -718,3 +717,31 @@ fn test_env_multiple_filters() {
// Multiple filters use OR logic
new_ucmd!().arg("--env=PATH,NONEXISTENT").succeeds();
}

#[test]
#[cfg(target_os = "linux")]
fn test_exact_long_pattern_no_match() {
new_ucmd!()
.arg("-x")
.arg("12345678901234")
.fails()
.code_is(1);
}

#[test]
fn test_pattern_longer_than_15_characters() {
new_ucmd!()
.arg("1234567890123456")
.fails()
.code_is(1)
.stderr_contains("longer than 15 characters");
}

#[test]
#[cfg(target_os = "linux")]
fn test_pool_workqueue_release() {
new_ucmd!()
.arg("pool_workqueue_release")
.succeeds()
.stdout_matches(&Regex::new(MULTIPLE_PIDS).unwrap());
}
Loading