b1dca6
commit b7176cc2aff4a8883e4834ddf65f8a6fdb1f160e
b1dca6
Author: DJ Delorie <dj@redhat.com>
b1dca6
Date:   Wed Feb 19 12:31:38 2020 -0500
b1dca6
b1dca6
    ldconfig: trace origin paths with -v
b1dca6
    
b1dca6
    With this patch, -v turns on a "from" trace for each directory
b1dca6
    searched, that tells you WHY that directory is being searched -
b1dca6
    is it a builtin, from the command line, or from some config file?
b1dca6
b1dca6
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
b1dca6
index ed7d9ab0412d93fd..5e6516688a1c192a 100644
b1dca6
--- a/elf/ldconfig.c
b1dca6
+++ b/elf/ldconfig.c
b1dca6
@@ -79,6 +79,8 @@ struct dir_entry
b1dca6
   int flag;
b1dca6
   ino64_t ino;
b1dca6
   dev_t dev;
b1dca6
+  const char *from_file;
b1dca6
+  int from_line;
b1dca6
   struct dir_entry *next;
b1dca6
 };
b1dca6
 
b1dca6
@@ -344,7 +346,12 @@ add_single_dir (struct dir_entry *entry, int verbose)
b1dca6
       if (ptr->ino == entry->ino && ptr->dev == entry->dev)
b1dca6
 	{
b1dca6
 	  if (opt_verbose && verbose)
b1dca6
-	    error (0, 0, _("Path `%s' given more than once"), entry->path);
b1dca6
+	    {
b1dca6
+	      error (0, 0, _("Path `%s' given more than once"), entry->path);
b1dca6
+	      fprintf (stderr, _("(from %s:%d and %s:%d)\n"),
b1dca6
+		       entry->from_file, entry->from_line,
b1dca6
+		       ptr->from_file, ptr->from_line);
b1dca6
+	    }
b1dca6
 	  /* Use the newer information.  */
b1dca6
 	  ptr->flag = entry->flag;
b1dca6
 	  free (entry->path);
b1dca6
@@ -363,12 +370,15 @@ add_single_dir (struct dir_entry *entry, int verbose)
b1dca6
 
b1dca6
 /* Add one directory to the list of directories to process.  */
b1dca6
 static void
b1dca6
-add_dir (const char *line)
b1dca6
+add_dir_1 (const char *line, const char *from_file, int from_line)
b1dca6
 {
b1dca6
   unsigned int i;
b1dca6
   struct dir_entry *entry = xmalloc (sizeof (struct dir_entry));
b1dca6
   entry->next = NULL;
b1dca6
 
b1dca6
+  entry->from_file = strdup (from_file);
b1dca6
+  entry->from_line = from_line;
b1dca6
+
b1dca6
   /* Search for an '=' sign.  */
b1dca6
   entry->path = xstrdup (line);
b1dca6
   char *equal_sign = strchr (entry->path, '=');
b1dca6
@@ -428,6 +438,11 @@ add_dir (const char *line)
b1dca6
     free (path);
b1dca6
 }
b1dca6
 
b1dca6
+static void
b1dca6
+add_dir (const char *line)
b1dca6
+{
b1dca6
+  add_dir_1 (line, "<builtin>", 0);
b1dca6
+}
b1dca6
 
b1dca6
 static int
b1dca6
 chroot_stat (const char *real_path, const char *path, struct stat64 *st)
b1dca6
@@ -672,9 +687,10 @@ search_dir (const struct dir_entry *entry)
b1dca6
   if (opt_verbose)
b1dca6
     {
b1dca6
       if (hwcap != 0)
b1dca6
-	printf ("%s: (hwcap: %#.16" PRIx64 ")\n", entry->path, hwcap);
b1dca6
+	printf ("%s: (hwcap: %#.16" PRIx64 ")", entry->path, hwcap);
b1dca6
       else
b1dca6
-	printf ("%s:\n", entry->path);
b1dca6
+	printf ("%s:", entry->path);
b1dca6
+      printf (_(" (from %s:%d)\n"), entry->from_file, entry->from_line);
b1dca6
     }
b1dca6
 
b1dca6
   char *dir_name;
b1dca6
@@ -815,6 +831,8 @@ search_dir (const struct dir_entry *entry)
b1dca6
 	  struct dir_entry *new_entry;
b1dca6
 
b1dca6
 	  new_entry = xmalloc (sizeof (struct dir_entry));
b1dca6
+	  new_entry->from_file = entry->from_file;
b1dca6
+	  new_entry->from_line = entry->from_line;
b1dca6
 	  new_entry->path = xstrdup (file_name);
b1dca6
 	  new_entry->flag = entry->flag;
b1dca6
 	  new_entry->next = NULL;
b1dca6
@@ -1174,7 +1192,7 @@ Warning: ignoring configuration file that cannot be opened: %s"),
b1dca6
 	    }
b1dca6
 	}
b1dca6
       else
b1dca6
-	add_dir (cp);
b1dca6
+	add_dir_1 (cp, filename, lineno);
b1dca6
     }
b1dca6
   while (!feof_unlocked (file));
b1dca6
 
b1dca6
@@ -1282,7 +1300,7 @@ main (int argc, char **argv)
b1dca6
 		 _("relative path `%s' used to build cache"),
b1dca6
 		 argv[i]);
b1dca6
 	else
b1dca6
-	  add_dir (argv[i]);
b1dca6
+	  add_dir_1 (argv[i], "<cmdline>", 0);
b1dca6
     }
b1dca6
 
b1dca6
   /* The last entry in hwcap_extra is reserved for the "tls" pseudo-hwcap which