From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by sourceware.org (Postfix) with ESMTP id 8B1DD3858D29 for ; Mon, 22 Mar 2021 20:28:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8B1DD3858D29 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=altlinux.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ldv@altlinux.org Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 11E2272C8B2 for ; Mon, 22 Mar 2021 23:28:30 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id F3AC87CC8AA; Mon, 22 Mar 2021 23:28:29 +0300 (MSK) Date: Mon, 22 Mar 2021 20:00:00 +0000 From: "Dmitry V. Levin" To: debugedit@sourceware.org Subject: [PATCH] debugedit: fix exit status in case of wrong number of arguments Message-ID: <20210322200000.GA2781@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: debugedit@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: debugedit development mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Mar 2021 20:28:32 -0000 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 --- 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