From patchwork Wed Feb 19 17:50:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 38232 Received: (qmail 40318 invoked by alias); 19 Feb 2020 17:50:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 40143 invoked by uid 89); 19 Feb 2020 17:50:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582134635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bCeOw6Cf64cMoKJIlmxeY6MrfSDigEa6FpWPYDd5qkU=; b=SPxri7W48GaZs10FUydgEmx3HdzTlAjt5MsqQE3tL9U+2sIxNnG0C6+KI2ZPQc/Gep5xa8 h3rXHhOOVk+qSDy8+NfE1TG4rJEA6GwsxyZXPisTFhEBS7ZgpQhFiAq2iQtiUbR7EmoEI/ b9A/g43l6MSv2KIM6WQuGWasND0wrCE= Date: Wed, 19 Feb 2020 12:50:30 -0500 Message-Id: From: DJ Delorie To: libc-alpha@sourceware.org Subject: [patch] ldconfig: trace origin paths with -v X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From 74548bffe27d8c37c78b25164b740dd591f681a9 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Wed, 19 Feb 2020 12:31:38 -0500 Subject: ldconfig: trace origin paths with -v With this patch, -v turns on a "from" trace for each directory searched, that tells you WHY that directory is being searched - is it a builtin, from the command line, or from some config file? Reviewed-by: Carlos O'Donell diff --git a/elf/ldconfig.c b/elf/ldconfig.c index 681ed78496..19ed04cf4d 100644 --- a/elf/ldconfig.c +++ b/elf/ldconfig.c @@ -79,6 +79,8 @@ struct dir_entry int flag; ino64_t ino; dev_t dev; + const char *from_file; + int from_line; struct dir_entry *next; }; @@ -344,7 +346,12 @@ add_single_dir (struct dir_entry *entry, int verbose) if (ptr->ino == entry->ino && ptr->dev == entry->dev) { if (opt_verbose && verbose) - error (0, 0, _("Path `%s' given more than once"), entry->path); + { + error (0, 0, _("Path `%s' given more than once"), entry->path); + fprintf (stderr, "(from %s:%d and %s:%d)\n", + entry->from_file, entry->from_line, + ptr->from_file, ptr->from_line); + } /* Use the newer information. */ ptr->flag = entry->flag; free (entry->path); @@ -363,12 +370,15 @@ add_single_dir (struct dir_entry *entry, int verbose) /* Add one directory to the list of directories to process. */ static void -add_dir (const char *line) +add_dir_1 (const char *line, const char *from_file, int from_line) { unsigned int i; struct dir_entry *entry = xmalloc (sizeof (struct dir_entry)); entry->next = NULL; + entry->from_file = strdup (from_file); + entry->from_line = from_line; + /* Search for an '=' sign. */ entry->path = xstrdup (line); char *equal_sign = strchr (entry->path, '='); @@ -428,6 +438,11 @@ add_dir (const char *line) free (path); } +static void +add_dir (const char *line) +{ + add_dir_1 (line, "", 0); +} static int chroot_stat (const char *real_path, const char *path, struct stat64 *st) @@ -672,9 +687,10 @@ search_dir (const struct dir_entry *entry) if (opt_verbose) { if (hwcap != 0) - printf ("%s: (hwcap: %#.16" PRIx64 ")\n", entry->path, hwcap); + printf ("%s: (hwcap: %#.16" PRIx64 ")", entry->path, hwcap); else - printf ("%s:\n", entry->path); + printf ("%s:", entry->path); + printf (" (from %s:%d)\n", entry->from_file, entry->from_line); } char *dir_name; @@ -815,6 +831,8 @@ search_dir (const struct dir_entry *entry) struct dir_entry *new_entry; new_entry = xmalloc (sizeof (struct dir_entry)); + new_entry->from_file = entry->from_file; + new_entry->from_line = entry->from_line; new_entry->path = xstrdup (file_name); new_entry->flag = entry->flag; new_entry->next = NULL; @@ -1175,7 +1193,7 @@ Warning: ignoring configuration file that cannot be opened: %s"), } } else - add_dir (cp); + add_dir_1 (cp, filename, lineno); } while (!feof_unlocked (file)); @@ -1283,7 +1301,7 @@ main (int argc, char **argv) _("relative path `%s' used to build cache"), argv[i]); else - add_dir (argv[i]); + add_dir_1 (argv[i], "", 0); } /* The last entry in hwcap_extra is reserved for the "tls" pseudo-hwcap which