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 00A07384A029 for ; Mon, 26 Apr 2021 20:04:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 00A07384A029 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 8339872C8B0 for ; Mon, 26 Apr 2021 23:04:52 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 577387CC8A7; Mon, 26 Apr 2021 23:04:52 +0300 (MSK) Date: Mon, 26 Apr 2021 20:00:00 +0000 From: "Dmitry V. Levin" To: debugedit@sourceware.org Subject: [PATCH 2/2] debugedit: consistently use error() instead of fprintf(stderr) Message-ID: <20210426200000.GB12328@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-13.0 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, 26 Apr 2021 20:04:54 -0000 The error() function is already used in debugedit for printing some of diagnostic messages, extend this practice to all such messages. The user-visible side of this change is that all diagnostic messages are now consistently prefixed. * tools/debugedit.c (edit_attributes, handle_build_id, main): Replace fprintf(stderr) with error(). --- tools/debugedit.c | 51 ++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/tools/debugedit.c b/tools/debugedit.c index 5d1644f..f84c7ef 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -2220,11 +2220,11 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase) producers will use DW_FORM_strp which is more efficient. */ if (orig_len < new_len) - fprintf (stderr, "Warning, not replacing comp_dir " - "'%s' prefix ('%s' -> '%s') encoded as " - "DW_FORM_string. " - "Replacement too large.\n", - comp_dir, base_dir, dest_dir); + error (0, 0, "Warning, not replacing comp_dir " + "'%s' prefix ('%s' -> '%s') encoded as " + "DW_FORM_string. " + "Replacement too large.", + comp_dir, base_dir, dest_dir); else { /* Add zero (if no file part), one or more @@ -3175,8 +3175,7 @@ handle_build_id (DSO *dso, Elf_Data *build_id, if (build_id_size != 16 && build_id_size != 20) { - fprintf (stderr, "Cannot handle %Zu-byte build ID\n", build_id_size); - exit (1); + error (1, 0, "Cannot handle %Zu-byte build ID", build_id_size); } int i = -1; @@ -3228,9 +3227,8 @@ handle_build_id (DSO *dso, Elf_Data *build_id, if (elf64_xlatetom (&x, &x, dso->ehdr.e_ident[EI_DATA]) == NULL) { bad: - fprintf (stderr, "Failed to compute header checksum: %s\n", - elf_errmsg (elf_errno ())); - exit (1); + error (1, 0, "Failed to compute header checksum: %s", + elf_errmsg (elf_errno ())); } x.d_type = ELF_T_PHDR; @@ -3374,7 +3372,7 @@ main (int argc, char *argv[]) if (optind != argc - 1) { - fprintf (stderr, "Need one FILE as input\n"); + error (0, 0, "Need one FILE as input"); usage (argv[0], true); } @@ -3382,22 +3380,18 @@ main (int argc, char *argv[]) { if (base_dir == NULL) { - fprintf (stderr, "You must specify a base dir if you specify a dest dir\n"); - exit (1); + error (1, 0, "You must specify a base dir if you specify a dest dir"); } } if (build_id_seed != NULL && do_build_id == 0) { - fprintf (stderr, "--build-id-seed (-s) needs --build-id (-i)\n"); - exit (1); + error (1, 0, "--build-id-seed (-s) needs --build-id (-i)"); } if (build_id_seed != NULL && strlen (build_id_seed) < 1) { - fprintf (stderr, - "--build-id-seed (-s) string should be at least 1 char\n"); - exit (1); + error (1, 0, "--build-id-seed (-s) string should be at least 1 char"); } /* Ensure clean paths, users can muck with these. Also removes any @@ -3416,14 +3410,12 @@ main (int argc, char *argv[]) if (elf_version(EV_CURRENT) == EV_NONE) { - fprintf (stderr, "library out of date\n"); - exit (1); + error (1, 0, "library out of date"); } if (stat(file, &stat_buf) < 0) { - fprintf (stderr, "Failed to open input file '%s': %s\n", file, strerror(errno)); - exit (1); + error (1, errno, "Failed to open input file '%s'", file); } /* Make sure we can read and write */ @@ -3432,8 +3424,7 @@ main (int argc, char *argv[]) fd = open (file, O_RDWR); if (fd < 0) { - fprintf (stderr, "Failed to open input file '%s': %s\n", file, strerror(errno)); - exit (1); + error (1, errno, "Failed to open input file '%s'", file); } dso = fdopen_dso (fd, file); @@ -3461,7 +3452,7 @@ main (int argc, char *argv[]) /* TODO: Handle stabs */ if (strcmp (name, ".stab") == 0) { - fprintf (stderr, "Stabs debuginfo not supported: %s\n", file); + error (0, 0, "Stabs debuginfo not supported: %s", file); break; } if (!(do_build_id && no_recompute_build_id && !base_dir && !dest_dir) @@ -3627,9 +3618,7 @@ main (int argc, char *argv[]) if (elf_update (dso->elf, ELF_C_NULL) < 0) { - fprintf (stderr, "Failed to update file: %s\n", - elf_errmsg (elf_errno ())); - exit (1); + error (1, 0, "Failed to update file: %s", elf_errmsg (elf_errno ())); } if (do_build_id && build_id != NULL) @@ -3637,13 +3626,11 @@ main (int argc, char *argv[]) if (elf_update (dso->elf, ELF_C_WRITE) < 0) { - fprintf (stderr, "Failed to write file: %s\n", elf_errmsg (elf_errno())); - exit (1); + error (1, 0, "Failed to write file: %s", elf_errmsg (elf_errno())); } if (elf_end (dso->elf) < 0) { - fprintf (stderr, "elf_end failed: %s\n", elf_errmsg (elf_errno())); - exit (1); + error (1, 0, "elf_end failed: %s", elf_errmsg (elf_errno())); } close (fd); -- ldv