arrfab / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1350733-1.patch

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