From nobody Wed Nov 24 23:56:19 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 476DD18ADB8A; Wed, 24 Nov 2021 23:56:20 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzyZr05vzz4RBn; Wed, 24 Nov 2021 23:56:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D825313731; Wed, 24 Nov 2021 23:56:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AONuJxq022559; Wed, 24 Nov 2021 23:56:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AONuJwa022558; Wed, 24 Nov 2021 23:56:19 GMT (envelope-from git) Date: Wed, 24 Nov 2021 23:56:19 GMT Message-Id: <202111242356.1AONuJwa022558@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 3f2c6f559841 - main - ldconfig: start of cleanup List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3f2c6f5598410b7233b0acd1c804a0473fa1e9fa Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637798180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GabUQCsdko6Y6PlSZKp/fVc1QkBoID99qNioU3mzmjM=; b=cHI1kN1LYbS/3zogphzi4CAzNeHx4EpLFN+wSgym4aEMALHIFOCX6HYspuYBWywlgv7wGS 35GZXpA3dZzhfpbxHWhL/83iWqM3gASpZbV7zDx9caN/jqCuWfw7lJeOyTAQml3f4K+IL5 EkH5ODOfssOSxFNL9SPQm8eNnA8JGy6KYVC5gzJBrIKgNgOjdO3HPH0uEBskFWh+yv4jUd YSvXRWVA1KkbZB/q4MW0kGu3H2A2VVZ1RGzxLnpNWpe9YXrjimfl/pivFoTMimmirYUgtm CScGT9G88kfZsSKezOWU9gly747rGydT5AY+6WzKZJtGy1i8nRzBqZWiTgXOEg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637798180; a=rsa-sha256; cv=none; b=Z3+TgS9kFsKzkE+7EcG2NFGuEx6hnrb6A/hER2xkaKfQ/neVvT79xs0rHZ453iSYYuqp51 iBjGrETk0wyHi4TJMf1k0qHkqspQ8SDHPWPKzLzrlapx0eWsjx7SbGtCp/5mtc8dpSmXrH +3m50nMHVeiYEufIe8s6VN9zDY7X0KWxHXxBLUdTcHDFBntgwxEYoE5HTaGqAdeDKpSz1N PmYbuy1S2iay5FtJ5FAqFgIYYPE/YEhuZUKmGqn6VeKik/50Lbbd1gU4FGO/gVf3BN/zma 6Q8wnHO6gP/08y7rnMzMpivYhlufX7xKs2IfZf/26WgzyntYx0rUVehVDrXBYw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=3f2c6f5598410b7233b0acd1c804a0473fa1e9fa commit 3f2c6f5598410b7233b0acd1c804a0473fa1e9fa Author: Konstantin Belousov AuthorDate: 2021-11-19 03:35:50 +0000 Commit: Konstantin Belousov CommitDate: 2021-11-24 23:55:03 +0000 ldconfig: start of cleanup Use bool. Use local variables instead of static. Remove non-functional debugging override of hints file path. Use explicit exit() instead of return from main. Minor style tweaks. Reviewed by: emaste Tested by: jbeich Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33058 --- sbin/ldconfig/elfhints.c | 19 ++++++++--------- sbin/ldconfig/ldconfig.c | 55 +++++++++++++++++------------------------------- sbin/ldconfig/ldconfig.h | 5 +++-- 3 files changed, 31 insertions(+), 48 deletions(-) diff --git a/sbin/ldconfig/elfhints.c b/sbin/ldconfig/elfhints.c index bbedac64b3ff..81236feec5ca 100644 --- a/sbin/ldconfig/elfhints.c +++ b/sbin/ldconfig/elfhints.c @@ -48,17 +48,17 @@ #define MAXDIRS 1024 /* Maximum directories in path */ #define MAXFILESIZE (16*1024) /* Maximum hints file size */ -static void add_dir(const char *, const char *, int); +static void add_dir(const char *, const char *, bool); static void read_dirs_from_file(const char *, const char *); -static void read_elf_hints(const char *, int); +static void read_elf_hints(const char *, bool); static void write_elf_hints(const char *); static const char *dirs[MAXDIRS]; static int ndirs; -int insecure; +bool insecure; static void -add_dir(const char *hintsfile, const char *name, int trusted) +add_dir(const char *hintsfile, const char *name, bool trusted) { struct stat stbuf; int i; @@ -186,7 +186,7 @@ read_dirs_from_file(const char *hintsfile, const char *listfile) } static void -read_elf_hints(const char *hintsfile, int must_exist) +read_elf_hints(const char *hintsfile, bool must_exist) { int fd; struct stat s; @@ -231,15 +231,14 @@ read_elf_hints(const char *hintsfile, int must_exist) } void -update_elf_hints(const char *hintsfile, int argc, char **argv, int merge) +update_elf_hints(const char *hintsfile, int argc, char **argv, bool merge) { - int i; + struct stat s; + int i; if (merge) - read_elf_hints(hintsfile, 0); + read_elf_hints(hintsfile, false); for (i = 0; i < argc; i++) { - struct stat s; - if (stat(argv[i], &s) == -1) warn("warning: %s", argv[i]); else if (S_ISREG(s.st_mode)) diff --git a/sbin/ldconfig/ldconfig.c b/sbin/ldconfig/ldconfig.c index 389cbb6101b5..3f623d6f38b1 100644 --- a/sbin/ldconfig/ldconfig.c +++ b/sbin/ldconfig/ldconfig.c @@ -30,11 +30,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - #include #include #include @@ -46,6 +41,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -53,34 +49,20 @@ static const char rcsid[] = #include "ldconfig.h" -#if DEBUG -/* test */ -#undef _PATH_ELF_HINTS -#define _PATH_ELF_HINTS "./ld-elf.so.hints" -#endif - #define _PATH_LD32_HINTS "/var/run/ld32.so.hints" #define _PATH_ELF32_HINTS "/var/run/ld-elf32.so.hints" #define _PATH_ELFSOFT_HINTS "/var/run/ld-elf-soft.so.hints" -#undef major -#undef minor - -static int verbose; -static int nostd; -static int justread; -static int merge; -static int rescan; -static const char *hints_file; - -static void usage(void); +static void usage(void); int main(int argc, char **argv) { - int c; - int is_32 = 0; - int is_soft = 0; + const char *hints_file; + int c; + bool is_32, is_soft, justread, merge, nostd, rescan, verbose; + + is_32 = is_soft = justread = merge = nostd = rescan = verbose = false; while (argc > 1) { if (strcmp(argv[1], "-aout") == 0) { @@ -89,11 +71,11 @@ main(int argc, char **argv) argc--; argv++; } else if (strcmp(argv[1], "-32") == 0) { - is_32 = 1; + is_32 = true; argc--; argv++; } else if (strcmp(argv[1], "-soft") == 0) { - is_soft = 1; + is_soft = true; argc--; argv++; } else { @@ -108,29 +90,29 @@ main(int argc, char **argv) else hints_file = _PATH_ELF_HINTS; if (argc == 1) - rescan = 1; + rescan = true; else while((c = getopt(argc, argv, "Rf:imrsv")) != -1) { switch (c) { case 'R': - rescan = 1; + rescan = true; break; case 'f': hints_file = optarg; break; case 'i': - insecure = 1; + insecure = true; break; case 'm': - merge = 1; + merge = true; break; case 'r': - justread = 1; + justread = true; break; case 's': - nostd = 1; + nostd = true; break; case 'v': - verbose = 1; + verbose = true; break; default: usage(); @@ -143,13 +125,14 @@ main(int argc, char **argv) else update_elf_hints(hints_file, argc - optind, argv + optind, merge || rescan); - return 0; + exit(0); } static void usage(void) { fprintf(stderr, - "usage: ldconfig [-32] [-elf] [-Rimrsv] [-f hints_file] [directory | file ...]\n"); + "usage: ldconfig [-32] [-elf] [-Rimrsv] [-f hints_file] " + "[directory | file ...]\n"); exit(1); } diff --git a/sbin/ldconfig/ldconfig.h b/sbin/ldconfig/ldconfig.h index 9b278255ac07..8aff4e6a5ef2 100644 --- a/sbin/ldconfig/ldconfig.h +++ b/sbin/ldconfig/ldconfig.h @@ -32,12 +32,13 @@ #define LDCONFIG_H 1 #include +#include -extern int insecure; /* -i flag, needed here for elfhints.c */ +extern bool insecure; /* -i flag, needed here for elfhints.c */ __BEGIN_DECLS void list_elf_hints(const char *); -void update_elf_hints(const char *, int, char **, int); +void update_elf_hints(const char *, int, char **, bool); __END_DECLS #endif