From patchwork Mon Jun 7 08:52:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1488485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=jr3jkaMe; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fz6cg59f3z9sRN for ; Mon, 7 Jun 2021 18:54:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD259383800C for ; Mon, 7 Jun 2021 08:54:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD259383800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623056065; bh=jDxuJ/S1OY1rdO2icXysvClFKDH31TtcTfxBwQDWQss=; 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=jr3jkaMeqd/sobywyvPHzrZlikN0ovVI9N6UoiU4ZalLUr7M71qYCE5xoIlHfGjsT 3+y+80nITmS2vt69DJZhYTE4KExIHSDc1BXbdb1W9IHRTq+WeAlAFSlHI7AODWMEfV 93c4SSRHrYUnsiUhmnaz80xkPK3btym8wdK7Ska4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 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 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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. Reviewed-by: DJ Delorie --- 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 @@ #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include @@ -57,6 +59,7 @@ static const struct path_elem empty_path_elem = { NULL, 0 }; /* Name of the file containing the module information in the directories along the path. */ static const char gconv_conf_filename[] = "gconv-modules"; +static const char gconv_conf_dirname[] = "gconv-modules.d"; /* Filename extension for the modules. */ #ifndef MODULE_EXT @@ -556,18 +559,52 @@ __gconv_read_conf (void) for (cnt = 0; __gconv_path_elem[cnt].name != NULL; ++cnt) { +#define BUF_LEN elem_len + sizeof (gconv_conf_dirname) + const char *elem = __gconv_path_elem[cnt].name; size_t elem_len = __gconv_path_elem[cnt].len; - char *filename; + char *buf; /* No slash needs to be inserted between elem and gconv_conf_filename; elem already ends in a slash. */ - filename = alloca (elem_len + sizeof (gconv_conf_filename)); - __mempcpy (__mempcpy (filename, elem, elem_len), - gconv_conf_filename, sizeof (gconv_conf_filename)); + buf = alloca (BUF_LEN); + char *cp = __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] = '.'; + 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"; - /* 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) == 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); + read_conf_file (conf, elem, elem_len, &modules, &nmodules); + } + } + __closedir (confdir); + } } #endif