From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from camel.birch.relay.mailchannels.net (camel.birch.relay.mailchannels.net [23.83.209.29]) by sourceware.org (Postfix) with ESMTPS id 1C934383B42D for ; Mon, 7 Jun 2021 08:52:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C934383B42D 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 AE7A654202C; Mon, 7 Jun 2021 08:52:45 +0000 (UTC) Received: from pdx1-sub0-mail-a36.g.dreamhost.com (100-96-133-111.trex.outbound.svc.cluster.local [100.96.133.111]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E194854266C; Mon, 7 Jun 2021 08:52:44 +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.133.111 (trex/6.3.1); Mon, 07 Jun 2021 08:52:45 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Whimsical-Turn: 25afaa3c08bb0604_1623055965385_2240929141 X-MC-Loop-Signature: 1623055965385:1555199680 X-MC-Ingress-Time: 1623055965385 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 9397382BC8; Mon, 7 Jun 2021 08:52:44 +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 0A2757F257; Mon, 7 Jun 2021 08:52:42 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a36 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH 3/5] gconv_conf: Read configuration files in gconv-modules.d Date: Mon, 7 Jun 2021 14:22:19 +0530 Message-Id: <20210607085221.43612-4-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 Content-Transfer-Encoding: quoted-printable 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-List-Received-Date: Mon, 07 Jun 2021 08:52:51 -0000 Read configuration files with names ending in .conf in GCONV_PATH/gconv-modules.d to mirror configuration flexibility in iconvconfig into the iconv program and function. --- iconv/gconv_conf.c | 49 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index 682f949834..c8ad8099a4 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -19,6 +19,7 @@ =20 #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include =20 #include #include @@ -57,6 +59,7 @@ static const struct path_elem empty_path_elem =3D { NUL= L, 0 }; /* Name of the file containing the module information in the directories along the path. */ static const char gconv_conf_filename[] =3D "gconv-modules"; +static const char gconv_conf_dirname[] =3D "gconv-modules.d"; =20 /* Filename extension for the modules. */ #ifndef MODULE_EXT @@ -556,18 +559,52 @@ __gconv_read_conf (void) =20 for (cnt =3D 0; __gconv_path_elem[cnt].name !=3D NULL; ++cnt) { +#define BUF_LEN elem_len + sizeof (gconv_conf_dirname) + const char *elem =3D __gconv_path_elem[cnt].name; size_t elem_len =3D __gconv_path_elem[cnt].len; - char *filename; + char *buf; =20 /* No slash needs to be inserted between elem and gconv_conf_filen= ame; elem already ends in a slash. */ - filename =3D alloca (elem_len + sizeof (gconv_conf_filename)); - __mempcpy (__mempcpy (filename, elem, elem_len), - gconv_conf_filename, sizeof (gconv_conf_filename)); + buf =3D alloca (BUF_LEN); + char *cp =3D __mempcpy (__mempcpy (buf, elem, elem_len), + gconv_conf_filename, sizeof (gconv_conf_filename)); + + /* Read the gconv-modules configuration file first. */ + read_conf_file (buf, elem, elem_len, &modules, &nmodules); + + /* Next, see if there is a gconv-modules.d directory containing + configuration files and if it is non-empty. */ + cp--; + cp[0] =3D '.'; + cp[1] =3D 'd'; + cp[2] =3D '\0'; + + DIR *confdir =3D __opendir (buf); + if (confdir !=3D NULL) + { + struct dirent *ent; + while ((ent =3D __readdir (confdir)) !=3D NULL) + { + if (ent->d_type !=3D DT_REG) + continue; + + size_t len =3D strlen (ent->d_name); + const char *suffix =3D ".conf"; =20 - /* Read the next configuration file. */ - read_conf_file (filename, elem, elem_len, &modules, &nmodules); + if (len > strlen (suffix) + && strcmp (ent->d_name + len - strlen (suffix), suffix) =3D=3D 0) + { + /* LEN <=3D PATH_MAX so this alloca is not unbounded. */ + char *conf =3D alloca (BUF_LEN + len + 1); + cp =3D stpcpy (conf, buf); + sprintf (cp, "/%s", ent->d_name); + read_conf_file (conf, elem, elem_len, &modules, &nmodules); + } + } + __closedir (confdir); + } } #endif =20 --=20 2.31.1