olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1350733-1.patch

00db10
The functions in locarchive.c cannot create files in non-default
00db10
locations.  Rather than enhancing locarchive.c (and risk regressions
00db10
in localedef), this patch adapts build-locale-archive to use the
00db10
existing output_prefix configuration variable.
00db10
00db10
Index: glibc-2.17-c758a686/releng/build-locale-archive.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/releng/build-locale-archive.c
00db10
+++ glibc-2.17-c758a686/releng/build-locale-archive.c
00db10
@@ -92,23 +92,34 @@ xmalloc (size_t size)
00db10
   return p;
00db10
 }
00db10
 
00db10
+static char *
00db10
+xasprintf (const char *format, ...)
00db10
+{
00db10
+  va_list ap;
00db10
+  va_start (ap, format);
00db10
+  char *result;
00db10
+  if (vasprintf (&result, format, ap) < 0)
00db10
+    error (EXIT_FAILURE, errno, "could not format string");
00db10
+  va_end (ap);
00db10
+  return result;
00db10
+}
00db10
+
00db10
 static void
00db10
 open_tmpl_archive (struct locarhandle *ah)
00db10
 {
00db10
   struct stat64 st;
00db10
   int fd;
00db10
   struct locarhead head;
00db10
-  const char *archivefname = ah->fname == NULL ? tmpl_file : ah->fname;
00db10
 
00db10
   /* Open the archive.  We must have exclusive write access.  */
00db10
-  fd = open64 (archivefname, O_RDONLY);
00db10
+  fd = open64 (tmpl_file, O_RDONLY);
00db10
   if (fd == -1)
00db10
     error (EXIT_FAILURE, errno, "cannot open locale archive template file \"%s\"",
00db10
-	   archivefname);
00db10
+	   tmpl_file);
00db10
 
00db10
   if (fstat64 (fd, &st) < 0)
00db10
     error (EXIT_FAILURE, errno, "cannot stat locale archive template file \"%s\"",
00db10
-	   archivefname);
00db10
+	   tmpl_file);
00db10
 
00db10
   /* Read the header.  */
00db10
   if (TEMP_FAILURE_RETRY (read (fd, &head, sizeof (head))) != sizeof (head))
00db10
@@ -253,12 +264,11 @@ compute_data (struct locarhandle *ah, st
00db10
 
00db10
 static int
00db10
 fill_archive (struct locarhandle *tmpl_ah,
00db10
-	      const char *fname,
00db10
 	      size_t install_langs_count, char *install_langs_list[],
00db10
 	      size_t nlist, char *list[],
00db10
 	      const char *primary)
00db10
 {
00db10
-  struct locarhandle ah;
00db10
+  struct locarhandle ah = {};
00db10
   struct locarhead *head;
00db10
   int result = 0;
00db10
   struct nameent *names;
00db10
@@ -338,9 +348,6 @@ fill_archive (struct locarhandle *tmpl_a
00db10
 
00db10
   /* Open the archive.  This call never returns if we cannot
00db10
      successfully open the archive.  */
00db10
-  ah.fname = NULL;
00db10
-  if (fname != NULL)
00db10
-    ah.fname = fname;
00db10
   open_archive (&ah, false);
00db10
 
00db10
   if (primary != NULL)
00db10
@@ -619,38 +626,39 @@ Usage: build-locale-archive [OPTION]...
00db10
                              \"de\" but also the aliases \"deutsch\"\n\
00db10
                              and and \"german\" although the latter does not\n\
00db10
                              start with \"de\".\n\
00db10
+  --prefix=DIR               Operate under the file system root DIR\n\
00db10
 \n\
00db10
-  If the arguments TEMPLATE-FILE and ARCHIVE-FILE are not given the locations\n\
00db10
-  where the glibc used expects these files are used by default.\n\
00db10
 ");
00db10
 }
00db10
 
00db10
 int main (int argc, char *argv[])
00db10
 {
00db10
-  char path[4096];
00db10
   DIR *dirp;
00db10
   struct dirent64 *d;
00db10
   struct stat64 st;
00db10
   char *list[16384], *primary;
00db10
   char *lang;
00db10
   int install_langs_count = 0;
00db10
-  int i;
00db10
   char *install_langs_arg, *ila_start;
00db10
   char **install_langs_list;
00db10
   unsigned int cnt = 0;
00db10
-  struct locarhandle tmpl_ah;
00db10
-  char *new_locar_fname = NULL;
00db10
-  size_t loc_path_len = strlen (loc_path);
00db10
+  struct locarhandle tmpl_ah = {};
00db10
 
00db10
   while (1)
00db10
     {
00db10
       int c;
00db10
 
00db10
+      enum
00db10
+      {
00db10
+	opt_prefix = 1000,
00db10
+      };
00db10
+
00db10
       static struct option long_options[] =
00db10
         {
00db10
             {"help",            no_argument,       0, 'h'},
00db10
             {"verbose",         no_argument,       0, 'v'},
00db10
             {"install-langs",   required_argument, 0, 'l'},
00db10
+	    {"prefix",          required_argument, 0, opt_prefix},
00db10
             {0, 0, 0, 0}
00db10
         };
00db10
       /* getopt_long stores the option index here. */
00db10
@@ -721,6 +729,10 @@ int main (int argc, char *argv[])
00db10
             }
00db10
           break;
00db10
 
00db10
+	case opt_prefix:
00db10
+	  output_prefix = optarg;
00db10
+	  break;
00db10
+
00db10
         case '?':
00db10
           /* getopt_long already printed an error message. */
00db10
           usage ();
00db10
@@ -730,23 +742,26 @@ int main (int argc, char *argv[])
00db10
           abort ();
00db10
         }
00db10
     }
00db10
-  tmpl_ah.fname = NULL;
00db10
-  if (optind < argc)
00db10
-    tmpl_ah.fname = argv[optind];
00db10
-  if (optind + 1 < argc)
00db10
-    new_locar_fname = argv[optind + 1];
00db10
+  if (optind != argc)
00db10
+    {
00db10
+      usage ();
00db10
+      exit (1);
00db10
+    }
00db10
+  if (output_prefix)
00db10
+    {
00db10
+      tmpl_file = xasprintf ("%s%s", output_prefix, tmpl_file);
00db10
+      alias_file = xasprintf ("%s%s", output_prefix, alias_file);
00db10
+      locar_file = xasprintf ("%s%s", output_prefix, locar_file);
00db10
+      loc_path = xasprintf ("%s%s", output_prefix, loc_path);
00db10
+    }
00db10
   if (verbose)
00db10
     {
00db10
-      if (tmpl_ah.fname)
00db10
-        printf("input archive file specified on command line: %s\n",
00db10
-               tmpl_ah.fname);
00db10
-      else
00db10
-        printf("using default input archive file.\n");
00db10
-      if (new_locar_fname)
00db10
-        printf("output archive file specified on command line: %s\n",
00db10
-               new_locar_fname);
00db10
-      else
00db10
-        printf("using default output archive file.\n");
00db10
+      if (output_prefix != NULL)
00db10
+	printf ("output prefix: %s\n", output_prefix);
00db10
+      printf ("input archive file: %s\n", tmpl_file);
00db10
+      printf ("input alias file: %s\n", alias_file);
00db10
+      printf ("input locale directory prefix: %s\n", loc_path);
00db10
+      printf ("output archive file: %s\n", locar_file);
00db10
     }
00db10
 
00db10
   dirp = opendir (loc_path);
00db10
@@ -754,11 +769,7 @@ int main (int argc, char *argv[])
00db10
     error (EXIT_FAILURE, errno, "cannot open directory \"%s\"", loc_path);
00db10
 
00db10
   open_tmpl_archive (&tmpl_ah);
00db10
-
00db10
-  if (new_locar_fname)
00db10
-    unlink (new_locar_fname);
00db10
-  else
00db10
-    unlink (locar_file);
00db10
+  unlink (locar_file);
00db10
 
00db10
   primary = getenv ("LC_ALL");
00db10
   if (primary == NULL)
00db10
@@ -790,8 +801,6 @@ int main (int argc, char *argv[])
00db10
 	}
00db10
     }
00db10
 
00db10
-  memcpy (path, loc_path, loc_path_len);
00db10
-
00db10
   while ((d = readdir64 (dirp)) != NULL)
00db10
     {
00db10
       if (strcmp (d->d_name, ".") == 0 || strcmp (d->d_name, "..") == 0)
00db10
@@ -799,32 +808,25 @@ int main (int argc, char *argv[])
00db10
       if (strchr (d->d_name, '_') == NULL)
00db10
 	continue;
00db10
 
00db10
-      size_t d_name_len = strlen (d->d_name);
00db10
-      if (loc_path_len + d_name_len + 1 > sizeof (path))
00db10
-	{
00db10
-	  error (0, 0, "too long filename \"%s\"", d->d_name);
00db10
-	  continue;
00db10
-	}
00db10
-
00db10
-      memcpy (path + loc_path_len, d->d_name, d_name_len + 1);
00db10
+      char *path = xasprintf ("%s%s", loc_path, d->d_name);
00db10
       if (stat64 (path, &st) < 0)
00db10
 	{
00db10
 	  error (0, errno, "cannot stat \"%s\"", path);
00db10
+	  free (path);
00db10
 	  continue;
00db10
 	}
00db10
       if (! S_ISDIR (st.st_mode))
00db10
-	continue;
00db10
+	{
00db10
+	  free (path);
00db10
+	  continue;
00db10
+	}
00db10
       if (cnt == 16384)
00db10
 	{
00db10
 	  error (0, 0, "too many directories in \"%s\"", loc_path);
00db10
+	  free (path);
00db10
 	  break;
00db10
 	}
00db10
-      list[cnt] = strdup (path);
00db10
-      if (list[cnt] == NULL)
00db10
-	{
00db10
-	  error (0, errno, "cannot add file to list \"%s\"", path);
00db10
-	  continue;
00db10
-	}
00db10
+      list[cnt] = path;
00db10
       if (primary != NULL && cnt > 0 && strcmp (primary, d->d_name) == 0)
00db10
 	{
00db10
 	  char *p = list[0];
00db10
@@ -836,7 +838,7 @@ int main (int argc, char *argv[])
00db10
   closedir (dirp);
00db10
   /* Store the archive to the file specified as the second argument on the
00db10
      command line or the default locale archive.  */
00db10
-  fill_archive (&tmpl_ah, new_locar_fname,
00db10
+  fill_archive (&tmpl_ah,
00db10
                 install_langs_count, install_langs_list,
00db10
                 cnt, list, primary);
00db10
   close_archive (&tmpl_ah);