public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@altlinux.org>
To: debugedit@sourceware.org
Subject: [PATCH] debugedit: fix exit status in case of wrong number of arguments
Date: Mon, 22 Mar 2021 20:00:00 +0000	[thread overview]
Message-ID: <20210322200000.GA2781@altlinux.org> (raw)

Print error diagnostics to stderr and exit with status EXIT_FAILURE
when the number of arguments is not equal to 1.

* tools/debugedit.c (usage): Add "error" argument, print usageText
to stderr and exit with status EXIT_FAILURE if error is set to true.
All callers updated.
* tests/debugedit.at: Check debugedit usage.

Fixes: 5200953d5a65 ("Initial build system. Remove rpm and popt dependencies.")
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 tests/debugedit.at | 10 ++++++++++
 tools/debugedit.c  | 12 ++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/tests/debugedit.at b/tests/debugedit.at
index a78180e..fb55574 100644
--- a/tests/debugedit.at
+++ b/tests/debugedit.at
@@ -60,6 +60,16 @@ AT_KEYWORDS([debuginfo] [debugedit])
 AT_CHECK([debugedit --help],[0],[ignore],[ignore])
 AT_CLEANUP
 
+# ===
+# Check debugedit usage.
+# ===
+AT_SETUP([debugedit usage])
+AT_KEYWORDS([debuginfo] [debugedit])
+AT_CHECK([debugedit --usage],[0],[ignore],[])
+AT_CHECK([debugedit],[1],[],[ignore])
+AT_CHECK([debugedit . ..],[1],[],[ignore])
+AT_CLEANUP
+
 # ===
 # Make sure that an executable still runs after debugedit munged it.
 # ===
diff --git a/tools/debugedit.c b/tools/debugedit.c
index 68e85df..7c57e16 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -3061,10 +3061,11 @@ help (const char *progname, bool error)
 }
 
 static void
-usage (const char *progname)
+usage (const char *progname, bool error)
 {
-  printf (usageText, progname);
-  exit (EXIT_SUCCESS);
+  FILE *f = error ? stderr : stdout;
+  fprintf (f, usageText, progname);
+  exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 static DSO *
@@ -3326,7 +3327,7 @@ main (int argc, char *argv[])
 	  break;
 
 	case 'u':
-	  usage (argv[0]);
+	  usage (argv[0], false);
 	  break;
 
 	case 'b':
@@ -3368,8 +3369,7 @@ main (int argc, char *argv[])
   if (optind != argc - 1)
     {
       fprintf (stderr, "Need one FILE as input\n");
-      usage (argv[0]);
-      exit(EXIT_FAILURE);
+      usage (argv[0], true);
     }
 
   if (dest_dir != NULL)
-- 
ldv

             reply	other threads:[~2021-03-22 20:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 20:00 Dmitry V. Levin [this message]
2021-03-23 13:56 ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210322200000.GA2781@altlinux.org \
    --to=ldv@altlinux.org \
    --cc=debugedit@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).