ce426f
Add --list-archive FILE support to localedef.
ce426f
ce426f
This feature largely supports the integrated work
ce426f
for InstLang support, and does not explicitly change
ce426f
any help text or behaviour at the API level for these
ce426f
routines. The basic purpose is to allow a file name to
ce426f
propagate to through the internal APIs to be used instead
ce426f
of the default locale archive. Given that build-locale-archive
ce426f
links against copies of the internal API it can use these
ce426f
non-public APIs without problem.
ce426f
ce426f
Author: Carlos O'Donell <carlos@redhat.com>
ce426f
Date:   Mon Feb 24 22:33:35 2014 -0500
ce426f
ce426f
    Fix failure load locale template.
ce426f
    
ce426f
    The call to open_tmpl_archive was being passed a pointer to an
ce426f
    object allocated on the stack. The object on the stack is not
ce426f
    guaranteed to be initialized to zero so we need to minimally
ce426f
    initialize `fname' in the struct locarhandle to ensure that
ce426f
    open_tml_archive loads the default tempalte.
ce426f
    
ce426f
    This error was seen while debugging glibc installs in a qemu
ce426f
    VM where it is more likely the stack pages were dirty. It has
ce426f
    not been reported on non-VM systems.
ce426f
ce426f
Author: Carlos O'Donell <carlos@redhat.com>
ce426f
Date:   Fri Oct 18 23:27:45 2013 -0400
ce426f
ce426f
    Allow fill_archive to be called with NULL fname.
ce426f
    
ce426f
    The fill_archive function should support being
ce426f
    called with a NULL fname argument. A NULL fname
ce426f
    argument indicates that the default archive should
ce426f
    be opened. We enable this by setting ah.fname to
ce426f
    NULL before initializing ah or calling open_archive.
ce426f
    This way if fname is NULL then ah.fname remains NULL
ce426f
    and open_archive opens the default archive.
ce426f
ce426f
Author: Carlos O'Donell <carlos@redhat.com>
ce426f
Date:   Thu Oct 3 05:22:51 2013 -0400
ce426f
ce426f
[snip]
ce426f
    - Support `--list-archive FILE' in localedef utility.
ce426f
51f0aa
This landed upstream in:
51f0aa
51f0aa
commit 484c12fb1e3664fb434291234ea5787c5e3df4f5
51f0aa
Author: Carlos O'Donell <carlos@redhat.com>
51f0aa
Date:   Fri Oct 18 23:41:30 2013 -0400
51f0aa
51f0aa
    Enhance localedef --list-archive option.
51f0aa
    
51f0aa
    The localedef --list-archive option claims that it can
51f0aa
    accept a [file] argument and list the contents of that
51f0aa
    archive. The support was never implemented. This patch
51f0aa
    adds that support and allows --list-archive to work as
51f0aa
    expected. You can now use localedef to list the contents
51f0aa
    of arbitrary locale archives by using:
51f0aa
    ./localedef --list-archive file
51f0aa
51f0aa
The defaultfname flag was removed there, see
51f0aa
<https://sourceware.org/ml/libc-alpha/2013-10/msg00127.html>.
51f0aa
ce426f
Index: glibc-2.17-c758a686/locale/locarchive.h
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/locale/locarchive.h
ce426f
+++ glibc-2.17-c758a686/locale/locarchive.h
ce426f
@@ -80,6 +80,8 @@ struct locrecent
ce426f
 
ce426f
 struct locarhandle
ce426f
 {
ce426f
+  /* Full path to the locale archive file.  */
ce426f
+  const char *fname;
ce426f
   int fd;
ce426f
   void *addr;
ce426f
   size_t mmaped;
ce426f
Index: glibc-2.17-c758a686/locale/programs/localedef.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/locale/programs/localedef.c
ce426f
+++ glibc-2.17-c758a686/locale/programs/localedef.c
ce426f
@@ -202,7 +202,7 @@ main (int argc, char *argv[])
ce426f
 
ce426f
   /* Handle a few special cases.  */
ce426f
   if (list_archive)
ce426f
-    show_archive_content (verbose);
ce426f
+    show_archive_content (remaining > 1 ? argv[remaining] : NULL, verbose);
ce426f
   if (add_to_archive)
ce426f
     return add_locales_to_archive (argc - remaining, &argv[remaining],
ce426f
 				   replace_archive);
ce426f
Index: glibc-2.17-c758a686/locale/programs/localedef.h
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/locale/programs/localedef.h
ce426f
+++ glibc-2.17-c758a686/locale/programs/localedef.h
ce426f
@@ -176,7 +176,8 @@ extern int add_locales_to_archive (size_
ce426f
 /* Removed named locales from archive.  */
ce426f
 extern int delete_locales_from_archive (size_t nlist, char *list[]);
ce426f
 
ce426f
-/* List content of locale archive.  */
ce426f
-extern void show_archive_content (int verbose) __attribute__ ((noreturn));
ce426f
+/* List content of locale archive. If FNAME is non-null use that as
ce426f
+   the locale archive to list, otherwise the default.  */
ce426f
+extern void show_archive_content (char *fname, int verbose) __attribute__ ((noreturn));
ce426f
 
ce426f
 #endif /* localedef.h */
ce426f
Index: glibc-2.17-c758a686/locale/programs/locarchive.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/locale/programs/locarchive.c
ce426f
+++ glibc-2.17-c758a686/locale/programs/locarchive.c
ce426f
@@ -197,6 +197,7 @@ create_archive (const char *archivefname
ce426f
 	     _("cannot change mode of new locale archive"));
ce426f
     }
ce426f
 
ce426f
+  ah->fname = NULL;
ce426f
   ah->fd = fd;
ce426f
   ah->addr = p;
ce426f
   ah->mmaped = total;
ce426f
@@ -519,11 +520,19 @@ open_archive (struct locarhandle *ah, bo
ce426f
   struct locarhead head;
ce426f
   int retry = 0;
ce426f
   size_t prefix_len = output_prefix ? strlen (output_prefix) : 0;
ce426f
-  char archivefname[prefix_len + sizeof (ARCHIVE_NAME)];
ce426f
-
ce426f
-  if (output_prefix)
ce426f
-    memcpy (archivefname, output_prefix, prefix_len);
ce426f
-  strcpy (archivefname + prefix_len, ARCHIVE_NAME);
ce426f
+  char fname[prefix_len + sizeof (ARCHIVE_NAME)];
ce426f
+  char *archivefname = ah->fname;
ce426f
+  bool defaultfname = false;
ce426f
+
ce426f
+  /* If ah has a non-NULL fname open that otherwise open the default.  */
ce426f
+  if (archivefname == NULL)
ce426f
+    {
ce426f
+      defaultfname = true;
ce426f
+      archivefname = fname;
ce426f
+      if (output_prefix)
ce426f
+        memcpy (archivefname, output_prefix, prefix_len);
ce426f
+      strcpy (archivefname + prefix_len, ARCHIVE_NAME);
ce426f
+    }
ce426f
 
ce426f
   while (1)
ce426f
     {
ce426f
@@ -531,8 +540,11 @@ open_archive (struct locarhandle *ah, bo
ce426f
       fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
ce426f
       if (fd == -1)
ce426f
 	{
ce426f
-	  /* Maybe the file does not yet exist.  */
ce426f
-	  if (errno == ENOENT)
ce426f
+	  /* Maybe the file does not yet exist? If we are opening
ce426f
+	     the default locale archive we ignore the failure and
ce426f
+	     list an empty archive, otherwise we print an error
ce426f
+	     and exit.  */
ce426f
+	  if (errno == ENOENT && defaultfname)
ce426f
 	    {
ce426f
 	      if (readonly)
ce426f
 		{
ce426f
@@ -1258,6 +1270,7 @@ add_locales_to_archive (nlist, list, rep
ce426f
 
ce426f
   /* Open the archive.  This call never returns if we cannot
ce426f
      successfully open the archive.  */
ce426f
+  ah.fname = NULL;
ce426f
   open_archive (&ah, false);
ce426f
 
ce426f
   while (nlist-- > 0)
ce426f
@@ -1457,6 +1470,7 @@ delete_locales_from_archive (nlist, list
ce426f
 
ce426f
   /* Open the archive.  This call never returns if we cannot
ce426f
      successfully open the archive.  */
ce426f
+  ah.fname = NULL;
ce426f
   open_archive (&ah, false);
ce426f
 
ce426f
   head = ah.addr;
ce426f
@@ -1545,7 +1559,7 @@ dataentcmp (const void *a, const void *b
ce426f
 
ce426f
 
ce426f
 void
ce426f
-show_archive_content (int verbose)
ce426f
+show_archive_content (char *fname, int verbose)
ce426f
 {
ce426f
   struct locarhandle ah;
ce426f
   struct locarhead *head;
ce426f
@@ -1555,6 +1569,7 @@ show_archive_content (int verbose)
ce426f
 
ce426f
   /* Open the archive.  This call never returns if we cannot
ce426f
      successfully open the archive.  */
ce426f
+  ah.fname = fname;
ce426f
   open_archive (&ah, true);
ce426f
 
ce426f
   head = ah.addr;
ce426f
Index: glibc-2.17-c758a686/locale/programs/locfile.c
ce426f
===================================================================
ce426f
--- glibc-2.17-c758a686.orig/locale/programs/locfile.c
ce426f
+++ glibc-2.17-c758a686/locale/programs/locfile.c
ce426f
@@ -337,6 +337,7 @@ write_all_categories (struct localedef_t
ce426f
 
ce426f
       /* Open the archive.  This call never returns if we cannot
ce426f
 	 successfully open the archive.  */
ce426f
+      ah.fname = NULL;
ce426f
       open_archive (&ah, false);
ce426f
 
ce426f
       if (add_locale_to_archive (&ah, locname, to_archive, true) != 0)