summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Warner <james.warner@comcast.net>2023-03-02 00:00:00 -0600
committerCraig Small <csmall@dropbear.xyz>2023-03-08 22:18:39 +1100
commitcbbe8fe324bfc9f59d7dda1e0518c442a90d8462 (patch)
tree75b9d3ff8acd6a4f64abc2cfad8104564a09646b
parentcced1e49ef25eae20773342a23af1e0d3dd27d30 (diff)
downloadprocps-ng-cbbe8fe324bfc9f59d7dda1e0518c442a90d8462.tar.gz
top: ensure an EXIT_FAILURE with bad command line args
When getopt usage was added (plus long options) in the patch shown below, top no longer returned EXIT_FAILURE when the error message was generated by getopt itself. This commit will restore the proper behavior no matter who might issue a command line argument error message. Thanks to Bastian Bittorf for discovering this buglet. Reference(s): https://gitlab.com/procps-ng/procps/-/issues/273 . sep, 2021 - getopt with long form args commit c91b371485b7ffaea3a7c669b080328d141dfb6b Signed-off-by: Jim Warner <james.warner@comcast.net>
-rw-r--r--src/top/top.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/top/top.c b/src/top/top.c
index b09f659..ad86265 100644
--- a/src/top/top.c
+++ b/src/top/top.c
@@ -556,7 +556,7 @@ static void bye_bye (const char *str) {
}
/* we'll only have a 'str' if called by error_exit() |
- not ever from the sig_endpgm() signal handler ... | */
+ and parse_args(), never from a signal handler ... | */
if (str) {
fputs(str, stderr);
exit(EXIT_FAILURE);
@@ -4372,8 +4372,9 @@ static void parse_args (int argc, char **argv) {
Width_mode = (int)tmp;
continue;
default:
- // we'll rely on getopt for any error message ...
- bye_bye(NULL);
+ /* we'll rely on getopt for any error message while
+ forcing an EXIT_FAILURE with an empty string ... */
+ bye_bye("");
} // end: switch (ch)
#ifndef GETOPTFIX_NO
if (cp) error_exit(fmtmk(N_fmt(UNKNOWN_opts_fmt), cp));