diff options
Diffstat (limited to 'patches/procps-3.2.8/0040-pgrep_c_option.patch')
-rw-r--r-- | patches/procps-3.2.8/0040-pgrep_c_option.patch | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/patches/procps-3.2.8/0040-pgrep_c_option.patch b/patches/procps-3.2.8/0040-pgrep_c_option.patch new file mode 100644 index 000000000..76f2bb601 --- /dev/null +++ b/patches/procps-3.2.8/0040-pgrep_c_option.patch @@ -0,0 +1,96 @@ +From 1eddc716164481ece7fd1c00850e9891b4d55269 Mon Sep 17 00:00:00 2001 +From: http://ftp.de.debian.org/debian/pool/main/p/procps/procps_3.2.8-8.debian.tar.gz <info@debian.org> +Date: Fri, 19 Mar 2010 21:58:46 +0100 +Subject: [PATCH 40/70] pgrep_c_option + +=================================================================== +--- + pgrep.1 | 5 ++++- + pgrep.c | 20 ++++++++++++++------ + 2 files changed, 18 insertions(+), 7 deletions(-) + +diff --git a/pgrep.1 b/pgrep.1 +index ae2edc2..9152799 100644 +--- a/pgrep.1 ++++ b/pgrep.1 +@@ -7,7 +7,7 @@ + pgrep, pkill \- look up or signal processes based on name and other attributes + + .SH SYNOPSIS +-pgrep [\-flvx] [\-d \fIdelimiter\fP] [\-n|\-o] [\-P \fIppid\fP,...] [\-g \fIpgrp\fP,...] ++pgrep [\-cflvx] [\-d \fIdelimiter\fP] [\-n|\-o] [\-P \fIppid\fP,...] [\-g \fIpgrp\fP,...] + .br + [\-s \fIsid\fP,...] [\-u \fIeuid\fP,...] [\-U \fIuid\fP,...] [\-G \fIgid\fP,...] + .br +@@ -38,6 +38,9 @@ to each process instead of listing them on stdout. + + .SH OPTIONS + .TP ++\-c ++Suppress normal output; instead print a count of matching processes. ++.TP + \-d \fIdelimiter\fP + Sets the string used to delimit each process ID in the output (by + default a newline). (\fBpgrep\fP only.) +diff --git a/pgrep.c b/pgrep.c +index 609cabd..33cbed8 100644 +--- a/pgrep.c ++++ b/pgrep.c +@@ -54,6 +54,7 @@ static int opt_oldest = 0; + static int opt_newest = 0; + static int opt_negate = 0; + static int opt_exact = 0; ++static int opt_count = 0; + static int opt_signal = SIGTERM; + static int opt_lock = 0; + static int opt_case = 0; +@@ -79,7 +80,7 @@ static int usage (int opt) + if (i_am_pkill) + fprintf (fp, "Usage: pkill [-SIGNAL] [-fvx] "); + else +- fprintf (fp, "Usage: pgrep [-flvx] [-d DELIM] "); ++ fprintf (fp, "Usage: pgrep [-cflvx] [-d DELIM] "); + fprintf (fp, "[-n|-o] [-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]\n" + "\t[-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] " + "[PATTERN]\n"); +@@ -565,7 +566,7 @@ static void parse_opts (int argc, char **argv) + strcat (opts, "ld:"); + } + +- strcat (opts, "LF:fnovxP:g:s:u:U:G:t:?V"); ++ strcat (opts, "LF:cfnovxP:g:s:u:U:G:t:?V"); + + while ((opt = getopt (argc, argv, opts)) != -1) { + switch (opt) { +@@ -613,6 +614,9 @@ static void parse_opts (int argc, char **argv) + exit(EXIT_SUCCESS); + // case 'c': // Solaris: match by contract ID + // break; ++ case 'c': ++ opt_count = 1; ++ break; + case 'd': // Solaris: change the delimiter + opt_delim = strdup (optarg); + break; +@@ -724,10 +728,14 @@ int main (int argc, char *argv[]) + procs[i].num, strerror (errno)); + } + } else { +- if (opt_long) +- output_strlist(procs,num); +- else +- output_numlist(procs,num); ++ if (opt_count) { ++ fprintf(stdout, "%ld\n", num); ++ } else { ++ if (opt_long) ++ output_strlist (procs,num); ++ else ++ output_numlist (procs,num); ++ } + } + return !num; // exit(EXIT_SUCCESS) if match, otherwise exit(EXIT_FAILURE) + } +-- +1.7.0 + |