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