]> granicus.if.org Git - procps-ng/commitdiff
pgrep: warning about 15+ chars name only if zero matches found
authorJan Rybar <jrybar@redhat.com>
Tue, 22 Nov 2016 16:42:54 +0000 (17:42 +0100)
committerJan Rybar <jrybar@redhat.com>
Mon, 2 Jan 2017 13:50:22 +0000 (14:50 +0100)
This avoids situations where longer regex which matches short-named proc is used.
Test for pgrep updated.

pgrep.c
testsuite/pgrep.test/pgrep.exp

diff --git a/pgrep.c b/pgrep.c
index 6708f87a39e1ce7634c1761df9f700ff034193ed..c973def66513711b0f55765270011922f0ab0da1 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -651,6 +651,11 @@ static struct el * select_procs (int *num)
        }
        closeproc (ptp);
        *num = matches;
+
+       if ((!matches) && (!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;
 }
 
@@ -886,14 +891,7 @@ 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."),
index 493d1a5548d5025f093152948b451ca0f3e396fa..66dd4c7d9ea9a93f60789f92b69e0cb7a9c2205b 100644 (file)
@@ -118,9 +118,9 @@ 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"
+set test "pgrep with long non-matching pattern gives warning"
 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
 kill_testproc