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