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