From 9742c74e7c522fe0a08473a9599def465b35a4d0 Mon Sep 17 00:00:00 2001 From: William Orr Date: Sun, 10 May 2015 17:42:09 +1000 Subject: [PATCH] pgrep: Enable case-insensitive process matching FreeBSD has case-insensitive matching of processes in pgrep and pkill, which can be super-useful. This patch uncomments and documents the code needed to make this work. Signed-off-by: Craig Small --- pgrep.1 | 3 +++ pgrep.c | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pgrep.1 b/pgrep.1 index cd0962f9..a571450f 100644 --- a/pgrep.1 +++ b/pgrep.1 @@ -76,6 +76,9 @@ own process group. Only match processes whose real group ID is listed. Either the numerical or symbolical value may be used. .TP +\fB\-i\fR, \fB\-\-ignore\-case\fR +Match processes case-insensitively. +.TP \fB\-l\fR, \fB\-\-list\-name\fR List the process name as well as the process ID. .RB ( pgrep diff --git a/pgrep.c b/pgrep.c index e24e09d7..27b7e893 100644 --- a/pgrep.c +++ b/pgrep.c @@ -118,6 +118,7 @@ static int __attribute__ ((__noreturn__)) usage(int opt) fputs(_(" -f, --full use full process name to match\n"), fp); fputs(_(" -g, --pgroup match listed process group IDs\n"), fp); fputs(_(" -G, --group match real group IDs\n"), fp); + fputs(_(" -i, --ignore-case match case insensitively\n"), fp); fputs(_(" -n, --newest select most recently started\n"), fp); fputs(_(" -o, --oldest select least recently started\n"), fp); fputs(_(" -P, --parent match only child processes of the given parent\n"), fp); @@ -694,6 +695,7 @@ static void parse_opts (int argc, char **argv) {"full", no_argument, NULL, 'f'}, {"pgroup", required_argument, NULL, 'g'}, {"group", required_argument, NULL, 'G'}, + {"ignore-case", no_argument, NULL, 'i'}, {"newest", no_argument, NULL, 'n'}, {"oldest", no_argument, NULL, 'o'}, {"parent", required_argument, NULL, 'P'}, @@ -727,7 +729,7 @@ static void parse_opts (int argc, char **argv) strcat (opts, "lad:vw"); } - strcat (opts, "LF:cfnoxP:g:s:u:U:G:t:?Vh"); + strcat (opts, "LF:cfinoxP:g:s:u:U:G:t:?Vh"); while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != -1) { switch (opt) { @@ -798,11 +800,11 @@ static void parse_opts (int argc, char **argv) usage ('?'); ++criteria_count; break; -/* case 'i': / * FreeBSD: ignore case. OpenBSD: withdrawn. See -I. This sucks. * / - * if (opt_case) - * usage (opt); - * opt_case = REG_ICASE; - * break; */ + case 'i': /* FreeBSD: ignore case. OpenBSD: withdrawn. See -I. This sucks. */ + if (opt_case) + usage (opt); + opt_case = REG_ICASE; + break; /* case 'j': / * FreeBSD: restricted to the given jail ID * / * break; */ case 'l': /* Solaris: long output format (pgrep only) Should require -f for beyond argv[0] maybe? */