From 34d040a07915cf1d1e60065398db3f89a462c647 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sun, 11 Sep 2016 10:40:47 +1000 Subject: [PATCH] pgrep: add warning that pattern exceeeds 15 chars Add a warning if you specify a command over 15 characters and don't use the -f command. This is a pick of two patches from master: 24fd260 pgrep: Fix off by one error in line check 4a7f9fc pgrep - adds warning that pattern exceeds 15 chars without References: !25 --- pgrep.c | 7 +++++++ testsuite/pgrep.test/pgrep.exp | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/pgrep.c b/pgrep.c index 58d5fd32..e673dd8c 100644 --- a/pgrep.c +++ b/pgrep.c @@ -830,7 +830,14 @@ static void parse_opts (int argc, char **argv) } if (argc - optind == 1) + { 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) xerrx(EXIT_USAGE, _("only one pattern can be provided\n" "Try `%s --help' for more information."), diff --git a/testsuite/pgrep.test/pgrep.exp b/testsuite/pgrep.test/pgrep.exp index ef267835..0e9084ab 100644 --- a/testsuite/pgrep.test/pgrep.exp +++ b/testsuite/pgrep.test/pgrep.exp @@ -118,6 +118,10 @@ set test "pgrep does not match substring with exact" spawn $pgrep -x $testproc_trim expect_blank $test +set test "pgrep with long match gives warning" +spawn $pgrep gnome-session-bi +expect_pass "$test" "pattern that contains program name longer than 15 characters will result in zero matches" + # Cleanup kill_testproc