public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] debugedit: fix exit status in case of wrong number of arguments
@ 2021-03-22 20:00 Dmitry V. Levin
  2021-03-23 13:56 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry V. Levin @ 2021-03-22 20:00 UTC (permalink / raw)
  To: debugedit

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] debugedit: fix exit status in case of wrong number of arguments
  2021-03-22 20:00 [PATCH] debugedit: fix exit status in case of wrong number of arguments Dmitry V. Levin
@ 2021-03-23 13:56 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2021-03-23 13:56 UTC (permalink / raw)
  To: Dmitry V. Levin, debugedit

Hi Dmitry,

On Mon, 2021-03-22 at 20:00 +0000, Dmitry V. Levin wrote:
> 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>

Looks good, this makes usage similar to help.
And thanks for the new testcase.

Pushed to main.

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-23 13:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 20:00 [PATCH] debugedit: fix exit status in case of wrong number of arguments Dmitry V. Levin
2021-03-23 13:56 ` Mark Wielaard

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).