pgrep: warning about 15+ chars name only if zero matches found
This avoids situations where longer regex which matches short-named proc is used. Test for pgrep updated. This is the newlib update of 5d12be1b7e8cc690a4d8778754aae5db4c07db2b Signed-off-by: Craig Small <csmall@enc.com.au>
This commit is contained in:
parent
2598e9f2ce
commit
9252a04eae
11
pgrep.c
11
pgrep.c
@ -591,6 +591,11 @@ static struct el * select_procs (int *num)
|
|||||||
procps_pids_unref(&info);
|
procps_pids_unref(&info);
|
||||||
|
|
||||||
*num = matches;
|
*num = matches;
|
||||||
|
|
||||||
|
if ((!opt_full) && (strlen(opt_pattern) > 15))
|
||||||
|
xwarnx(_("pattern that searches for process name longer than 15 characters will result in zero matches\n"
|
||||||
|
"Try `%s -f' option to match against the complete command line."),
|
||||||
|
program_invocation_short_name);
|
||||||
return list;
|
return list;
|
||||||
#undef PIDS_GETINT
|
#undef PIDS_GETINT
|
||||||
#undef PIDS_GETUNT
|
#undef PIDS_GETUNT
|
||||||
@ -830,13 +835,7 @@ static void parse_opts (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (argc - optind == 1)
|
if (argc - optind == 1)
|
||||||
{
|
|
||||||
opt_pattern = argv[optind];
|
opt_pattern = argv[optind];
|
||||||
if ((!opt_full) && (strlen(opt_pattern) > 15))
|
|
||||||
xwarnx(_("pattern that contains program name longer than 15 characters will result in zero matches\n"
|
|
||||||
"Try `%s -f' option for thorough search."),
|
|
||||||
program_invocation_short_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (argc - optind > 1)
|
else if (argc - optind > 1)
|
||||||
xerrx(EXIT_USAGE, _("only one pattern can be provided\n"
|
xerrx(EXIT_USAGE, _("only one pattern can be provided\n"
|
||||||
|
@ -118,10 +118,9 @@ set test "pgrep does not match substring with exact"
|
|||||||
spawn $pgrep -x $testproc_trim
|
spawn $pgrep -x $testproc_trim
|
||||||
expect_blank $test
|
expect_blank $test
|
||||||
|
|
||||||
set test "pgrep with long match gives warning"
|
set test "pgrep with long non-matching pattern gives warning"
|
||||||
spawn $pgrep gnome-session-bi
|
spawn $pgrep gnome-session-bi
|
||||||
expect_pass "$test" "pattern that contains program name longer than 15 characters will result in zero matches"
|
expect_pass "$test" "pattern that searches for process name longer than 15 characters will result in zero matches"
|
||||||
|
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
kill_testproc
|
kill_testproc
|
||||||
|
Loading…
Reference in New Issue
Block a user