From patchwork Mon Jun 7 08:52:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 43738 X-Patchwork-Delegate: dj@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00DFD3838010 for ; Mon, 7 Jun 2021 08:55:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00DFD3838010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623056117; bh=H8XPjdyVdbFhgmQpp6AnvWD5D9BtMCKwzJ90HSiwCBE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=E33G+yNk+We3ZMDCH/IAKuxa2LxPIrxULZQLwoPb56oq8IwBrhRoy6pODT1i3/Iv7 4cCiQOCjprxwJ8xPpsNyDtCYXmgwVbLB39yJiMi2tEQGC5NoCXcqDhxoWmevIkyC61 XsTzAt5Eg384pU2lmLS7qpd62WGszBQV1ZmTNypU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from quail.birch.relay.mailchannels.net (quail.birch.relay.mailchannels.net [23.83.209.151]) by sourceware.org (Postfix) with ESMTPS id C7BF63838030 for ; Mon, 7 Jun 2021 08:52:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C7BF63838030 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 078E53431DA; Mon, 7 Jun 2021 08:52:43 +0000 (UTC) Received: from pdx1-sub0-mail-a36.g.dreamhost.com (100-96-18-89.trex.outbound.svc.cluster.local [100.96.18.89]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 84DE93431D8; Mon, 7 Jun 2021 08:52:42 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a36.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.18.89 (trex/6.3.1); Mon, 07 Jun 2021 08:52:42 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Language-Befitting: 157d495c22d1ce94_1623055962824_4202136711 X-MC-Loop-Signature: 1623055962823:1032336768 X-MC-Ingress-Time: 1623055962823 Received: from pdx1-sub0-mail-a36.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a36.g.dreamhost.com (Postfix) with ESMTP id 3E8CF82BC8; Mon, 7 Jun 2021 08:52:42 +0000 (UTC) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a36.g.dreamhost.com (Postfix) with ESMTPSA id A72FC7F257; Mon, 7 Jun 2021 08:52:40 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a36 To: libc-alpha@sourceware.org Subject: [PATCH 2/5] iconvconfig: Read configuration from gconv-modules.d subdirectory Date: Mon, 7 Jun 2021 14:22:18 +0530 Message-Id: <20210607085221.43612-3-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210607085221.43612-1-siddhesh@sourceware.org> References: <20210607085221.43612-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" In addition to GCONV_PATH/gconv-modules, also read module configuration from *.conf files in GCONV_PATH/gconv-modules.d. This allows a single gconv directory to have multiple sets of gconv modules but at the same time, a single modules cache. With this feature, one could separate the glibc supported gconv modules into a minimal essential set (ISO-8859-*, UTF, etc.) from the remaining modules. In future, these could be further segregated into langpack-associated sets with their own gconv-modules.d/someconfig.conf. Reviewed-by: DJ Delorie --- iconv/iconvconfig.c | 50 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c index f5aba636d7..b2a868919c 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #include #include +#include #include #include "iconvconfig.h" @@ -710,6 +712,7 @@ handle_file (const char *dir, const char *infile) static int handle_dir (const char *dir) { +#define BUF_LEN prefix_len + dirlen + sizeof "gconv-modules.d" char *cp; size_t dirlen = strlen (dir); bool found = false; @@ -722,20 +725,55 @@ handle_dir (const char *dir) newp[dirlen] = '\0'; } - char infile[prefix_len + dirlen + sizeof "gconv-modules"]; - cp = infile; + /* First, look for a gconv-modules file. */ + char buf[BUF_LEN]; + cp = buf; if (dir[0] == '/') cp = mempcpy (cp, prefix, prefix_len); - strcpy (mempcpy (cp, dir, dirlen), "gconv-modules"); + cp = mempcpy (cp, dir, dirlen); + cp = stpcpy (cp, "gconv-modules"); - found |= handle_file (dir, infile); + found |= handle_file (dir, buf); + + /* Next, see if there is a gconv-modules.d directory containing configuration + files and if it is non-empty. */ + cp[0] = '.'; + cp[1] = 'd'; + cp[2] = '\0'; + + DIR *confdir = opendir (buf); + if (confdir != NULL) + { + struct dirent *ent; + while ((ent = readdir (confdir)) != NULL) + { + if (ent->d_type != DT_REG) + continue; + + size_t len = strlen (ent->d_name); + const char *suffix = ".conf"; + + if (len > strlen (suffix) + && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0) + { + /* LEN <= PATH_MAX so this alloca is not unbounded. */ + char *conf = alloca (BUF_LEN + len + 1); + cp = stpcpy (conf, buf); + sprintf (cp, "/%s", ent->d_name); + found |= handle_file (dir, conf); + } + } + closedir (confdir); + } if (!found) { - error (0, errno, "failed to open gconv configuration file in `%s'", + error (0, errno, "failed to open gconv configuration files in `%s'", dir); error (0, 0, - "ensure that the directory contains a valid gconv-modules file."); + "ensure that the directory contains either a valid " + "gconv-modules file or a gconv-modules.d directory with " + "configuration files with names ending in .conf."); } return found ? 0 : 1;