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