From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 71CAC3854835 for ; Tue, 8 Jun 2021 21:46:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 71CAC3854835 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-534-_DQMTeDHM7GQhcaP14BB0A-1; Tue, 08 Jun 2021 17:46:38 -0400 X-MC-Unique: _DQMTeDHM7GQhcaP14BB0A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03E951007B02; Tue, 8 Jun 2021 21:46:38 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-111.rdu2.redhat.com [10.10.112.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4957179E6; Tue, 8 Jun 2021 21:46:37 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 158LkaTe240004; Tue, 8 Jun 2021 17:46:36 -0400 From: DJ Delorie To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 2/5] iconvconfig: Read configuration from gconv-modules.d subdirectory In-Reply-To: <20210607085221.43612-3-siddhesh@sourceware.org> Date: Tue, 08 Jun 2021 17:46:36 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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: Tue, 08 Jun 2021 21:46:41 -0000 Siddhesh Poyarekar via Libc-alpha writes: > 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. > --- > iconv/iconvconfig.c | 50 +++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 44 insertions(+), 6 deletions(-) > diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c > +#include Ok. > +#include Ok. > @@ -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" sizeof includes one for the NUL, so OK. > @@ -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"); max string is "gconv-modules" > - found |= handle_file (dir, infile); > + found |= handle_file (dir, buf); Looks for gconv-modules files, ok. > + /* 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'; buf[] is now "...gconv-modules.d" > + 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. */ But it doesn't go out of scope until the function *exits* although one could assume that the compiler would re-use (overlap) them. Shouldn't be a problem unless there's a stupid number of conf files in a subdir. > + char *conf = alloca (BUF_LEN + len + 1); The byte for NUL in BUF_LEN is reused here, the "1" is for "/". Ok. > + cp = stpcpy (conf, buf); > + sprintf (cp, "/%s", ent->d_name); > + found |= handle_file (dir, conf); > + } > + } > + closedir (confdir); > + } Ok. > 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."); > } Ok. Reviewed-by: DJ Delorie