From cfb3c482a5c9235a9899e107f2f90873164f7049 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Tue, 13 Jun 2023 16:23:35 +1000 Subject: [PATCH] pgrep: Suppress warning if using regex pgrep gives a warning if the match string is longer than 15 characters and there was no match. That often does not make sense when using regex or at the very least difficult to know when to warn users. e.g "1234567890|123456789X" is a 21 character string but only matching two 10 string words. pgrep has a simple check for regex and will now suppress that warning if that has been used. References: https://bugs.debian.org/1037450 Signed-off-by: Craig Small --- NEWS | 1 + src/pgrep.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 1fa44899..59e51319 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ procps-ng-NEXT restore the proper main thread tics valuations issue #280 * free: -L one line output issue #156 * pgrep: Use only --signal option for signal Debian #1031765 + * pgrep: suppress >15 warning if using regex Debian #1037450 * ps: fixed missing or corrupted fields with -m option Debian #1036631, issue #279 * tests: dont compare floats with == issue #271 * top: bad command line arguments yield EXIT_FAILURE issue #273 diff --git a/src/pgrep.c b/src/pgrep.c index 442dbfcc..838bb2d0 100644 --- a/src/pgrep.c +++ b/src/pgrep.c @@ -636,6 +636,27 @@ static size_t get_arg_max(void) return val; } +/* + * Check if we have a long simple (non-regex) match + * Returns true if the string: + * 1) is longer than 15 characters + * 2) Doesn't have | or [ which are used by regex + * This is not an exhaustive list but catches most instances + * It's only used to suppress the warning + */ +static bool is_long_match(const char *str) +{ + int i, len; + + if (str == NULL) + return FALSE; + if (15 >= (len = strlen(str))) + return FALSE; + for (i=0; i 15)) + if ((!matches) && (!opt_full) && is_long_match(opt_pattern)) 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);