summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralbert <>2007-05-28 00:16:39 +0000
committeralbert <>2007-05-28 00:16:39 +0000
commite5b2b8614d00bd776f6eec29e9d7e24308b50953 (patch)
treede22615c1b7198d64c76109fe0071489b7b12c36
parent8e4bf3e1156bd250ca14f2908c41463f70d62bf2 (diff)
downloadprocps-ng-e5b2b8614d00bd776f6eec29e9d7e24308b50953.tar.gz
pgrep: usage error should exit with 2
-rw-r--r--NEWS3
-rw-r--r--pgrep.c13
2 files changed, 10 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 699b5a9..1a48e70 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,8 @@ procps-3.2.7 --> procps-3.2.8
ps: document SCHED_BATCH and add "see also" for stime
ps: man page less ambiguous
-top: normal exit code should be 0 #341272
+top: normal exit code should be 0 #341272 #354255
+pgrep: usage error should exit with 2 #413383
procps-3.2.6 --> procps-3.2.7
diff --git a/pgrep.c b/pgrep.c
index e4fda6e..bbb7cd1 100644
--- a/pgrep.c
+++ b/pgrep.c
@@ -70,18 +70,21 @@ static union el *opt_ruid = NULL;
static char *opt_pattern = NULL;
static char *opt_pidfile = NULL;
-
static int usage (int opt) NORETURN;
static int usage (int opt)
{
+ int err = (opt=='?'); /* getopt() uses '?' to mark an error */
+ FILE *fp = err ? stderr : stdout;
+
if (i_am_pkill)
- fprintf (stderr, "Usage: pkill [-SIGNAL] [-fvx] ");
+ fprintf (fp, "Usage: pkill [-SIGNAL] [-fvx] ");
else
- fprintf (stderr, "Usage: pgrep [-flvx] [-d DELIM] ");
- fprintf (stderr, "[-n|-o] [-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]\n"
+ fprintf (fp, "Usage: pgrep [-flvx] [-d DELIM] ");
+ fprintf (fp, "[-n|-o] [-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]\n"
"\t[-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] "
"[PATTERN]\n");
- exit (opt == '?' ? EXIT_SUCCESS : EXIT_USAGE);
+
+ exit(err ? EXIT_USAGE : EXIT_SUCCESS);
}