|
|
179894 |
commit 3979c3e1bae20459d9b6d424bdb49927d9cd6fec
|
|
|
179894 |
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
|
179894 |
Date: Mon Jun 7 14:22:18 2021 +0530
|
|
|
179894 |
|
|
|
179894 |
iconvconfig: Read configuration from gconv-modules.d subdirectory
|
|
|
179894 |
|
|
|
179894 |
In addition to GCONV_PATH/gconv-modules, also read module
|
|
|
179894 |
configuration from *.conf files in GCONV_PATH/gconv-modules.d. This
|
|
|
179894 |
allows a single gconv directory to have multiple sets of gconv modules
|
|
|
179894 |
but at the same time, a single modules cache.
|
|
|
179894 |
|
|
|
179894 |
With this feature, one could separate the glibc supported gconv
|
|
|
179894 |
modules into a minimal essential set (ISO-8859-*, UTF, etc.) from the
|
|
|
179894 |
remaining modules. In future, these could be further segregated into
|
|
|
179894 |
langpack-associated sets with their own
|
|
|
179894 |
gconv-modules.d/someconfig.conf.
|
|
|
179894 |
|
|
|
179894 |
Reviewed-by: DJ Delorie <dj@redhat.com>
|
|
|
179894 |
|
|
|
179894 |
diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c
|
|
|
179894 |
index 2b3c587bc77cfdcd..fafc686ae25fb5c1 100644
|
|
|
179894 |
--- a/iconv/iconvconfig.c
|
|
|
179894 |
+++ b/iconv/iconvconfig.c
|
|
|
179894 |
@@ -18,6 +18,7 @@
|
|
|
179894 |
|
|
|
179894 |
#include <argp.h>
|
|
|
179894 |
#include <assert.h>
|
|
|
179894 |
+#include <dirent.h>
|
|
|
179894 |
#include <error.h>
|
|
|
179894 |
#include <errno.h>
|
|
|
179894 |
#include <fcntl.h>
|
|
|
179894 |
@@ -33,6 +34,7 @@
|
|
|
179894 |
#include <string.h>
|
|
|
179894 |
#include <unistd.h>
|
|
|
179894 |
#include <sys/cdefs.h>
|
|
|
179894 |
+#include <sys/types.h>
|
|
|
179894 |
#include <sys/uio.h>
|
|
|
179894 |
|
|
|
179894 |
#include "iconvconfig.h"
|
|
|
179894 |
@@ -710,6 +712,7 @@ handle_file (const char *dir, const char *infile)
|
|
|
179894 |
static int
|
|
|
179894 |
handle_dir (const char *dir)
|
|
|
179894 |
{
|
|
|
179894 |
+#define BUF_LEN prefix_len + dirlen + sizeof "gconv-modules.d"
|
|
|
179894 |
char *cp;
|
|
|
179894 |
size_t dirlen = strlen (dir);
|
|
|
179894 |
bool found = false;
|
|
|
179894 |
@@ -722,20 +725,55 @@ handle_dir (const char *dir)
|
|
|
179894 |
newp[dirlen] = '\0';
|
|
|
179894 |
}
|
|
|
179894 |
|
|
|
179894 |
- char infile[prefix_len + dirlen + sizeof "gconv-modules"];
|
|
|
179894 |
- cp = infile;
|
|
|
179894 |
+ /* First, look for a gconv-modules file. */
|
|
|
179894 |
+ char buf[BUF_LEN];
|
|
|
179894 |
+ cp = buf;
|
|
|
179894 |
if (dir[0] == '/')
|
|
|
179894 |
cp = mempcpy (cp, prefix, prefix_len);
|
|
|
179894 |
- strcpy (mempcpy (cp, dir, dirlen), "gconv-modules");
|
|
|
179894 |
+ cp = mempcpy (cp, dir, dirlen);
|
|
|
179894 |
+ cp = stpcpy (cp, "gconv-modules");
|
|
|
179894 |
|
|
|
179894 |
- found |= handle_file (dir, infile);
|
|
|
179894 |
+ found |= handle_file (dir, buf);
|
|
|
179894 |
+
|
|
|
179894 |
+ /* Next, see if there is a gconv-modules.d directory containing configuration
|
|
|
179894 |
+ files and if it is non-empty. */
|
|
|
179894 |
+ cp[0] = '.';
|
|
|
179894 |
+ cp[1] = 'd';
|
|
|
179894 |
+ cp[2] = '\0';
|
|
|
179894 |
+
|
|
|
179894 |
+ DIR *confdir = opendir (buf);
|
|
|
179894 |
+ if (confdir != NULL)
|
|
|
179894 |
+ {
|
|
|
179894 |
+ struct dirent *ent;
|
|
|
179894 |
+ while ((ent = readdir (confdir)) != NULL)
|
|
|
179894 |
+ {
|
|
|
179894 |
+ if (ent->d_type != DT_REG)
|
|
|
179894 |
+ continue;
|
|
|
179894 |
+
|
|
|
179894 |
+ size_t len = strlen (ent->d_name);
|
|
|
179894 |
+ const char *suffix = ".conf";
|
|
|
179894 |
+
|
|
|
179894 |
+ if (len > strlen (suffix)
|
|
|
179894 |
+ && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
|
|
|
179894 |
+ {
|
|
|
179894 |
+ /* LEN <= PATH_MAX so this alloca is not unbounded. */
|
|
|
179894 |
+ char *conf = alloca (BUF_LEN + len + 1);
|
|
|
179894 |
+ cp = stpcpy (conf, buf);
|
|
|
179894 |
+ sprintf (cp, "/%s", ent->d_name);
|
|
|
179894 |
+ found |= handle_file (dir, conf);
|
|
|
179894 |
+ }
|
|
|
179894 |
+ }
|
|
|
179894 |
+ closedir (confdir);
|
|
|
179894 |
+ }
|
|
|
179894 |
|
|
|
179894 |
if (!found)
|
|
|
179894 |
{
|
|
|
179894 |
- error (0, errno, "failed to open gconv configuration file in `%s'",
|
|
|
179894 |
+ error (0, errno, "failed to open gconv configuration files in `%s'",
|
|
|
179894 |
dir);
|
|
|
179894 |
error (0, 0,
|
|
|
179894 |
- "ensure that the directory contains a valid gconv-modules file.");
|
|
|
179894 |
+ "ensure that the directory contains either a valid "
|
|
|
179894 |
+ "gconv-modules file or a gconv-modules.d directory with "
|
|
|
179894 |
+ "configuration files with names ending in .conf.");
|
|
|
179894 |
}
|
|
|
179894 |
|
|
|
179894 |
return found ? 0 : 1;
|