From owner-svn-src-all@freebsd.org Sun Mar 8 20:35:01 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 91DE9274D62; Sun, 8 Mar 2020 20:35:01 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48bClT1Qrjz49QJ; Sun, 8 Mar 2020 20:35:01 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1C46027893; Sun, 8 Mar 2020 20:35:01 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 028KZ0Ui095232; Sun, 8 Mar 2020 20:35:00 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 028KZ09w095231; Sun, 8 Mar 2020 20:35:00 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <202003082035.028KZ09w095231@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Sun, 8 Mar 2020 20:35:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r358778 - stable/12/contrib/elftoolchain/readelf X-SVN-Group: stable-12 X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: stable/12/contrib/elftoolchain/readelf X-SVN-Commit-Revision: 358778 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Mar 2020 20:35:01 -0000 Author: emaste Date: Sun Mar 8 20:35:00 2020 New Revision: 358778 URL: https://svnweb.freebsd.org/changeset/base/358778 Log: readelf: hoist file opening out of dump_object Diff reduction with HEAD to facilitate other MFCs. Modified: stable/12/contrib/elftoolchain/readelf/readelf.c Modified: stable/12/contrib/elftoolchain/readelf/readelf.c ============================================================================== --- stable/12/contrib/elftoolchain/readelf/readelf.c Sun Mar 8 20:09:19 2020 (r358777) +++ stable/12/contrib/elftoolchain/readelf/readelf.c Sun Mar 8 20:35:00 2020 (r358778) @@ -7116,15 +7116,8 @@ process_members: } static void -dump_object(struct readelf *re) +dump_object(struct readelf *re, int fd) { - int fd; - - if ((fd = open(re->filename, O_RDONLY)) == -1) { - warn("open %s failed", re->filename); - return; - } - if ((re->flags & DISPLAY_FILENAME) != 0) printf("\nFile: %s\n", re->filename); @@ -7145,13 +7138,10 @@ dump_object(struct readelf *re) break; default: warnx("Internal: libelf returned unknown elf kind."); - goto done; } - elf_end(re->elf); - done: - close(fd); + elf_end(re->elf); } static void @@ -7496,7 +7486,7 @@ main(int argc, char **argv) { struct readelf *re, re_storage; unsigned long si; - int opt, i; + int fd, opt, i; char *ep; re = &re_storage; @@ -7621,7 +7611,13 @@ main(int argc, char **argv) for (i = 0; i < argc; i++) { re->filename = argv[i]; - dump_object(re); + fd = open(re->filename, O_RDONLY); + if (fd < 0) { + warn("open %s failed", re->filename); + } else { + dump_object(re, fd); + close(fd); + } } exit(EXIT_SUCCESS);