* [PATCH][locale]: Add LOCARCHIVE env variable
@ 2024-06-05 8:36 Mark Goncharov
2024-06-05 12:26 ` Carlos O'Donell
0 siblings, 1 reply; 2+ messages in thread
From: Mark Goncharov @ 2024-06-05 8:36 UTC (permalink / raw)
To: libc-locales
[-- Attachment #1.1: Type: text/plain, Size: 3724 bytes --]
From e0d259c2940efe0a9caf889a60b016f126c197a5 Mon Sep 17 00:00:00 2001
From: mga-sc <mark.goncharov@syntacore.com>
Date: Wed, 5 Jun 2024 09:00:54 +0300
Subject: [PATCH] [locale]: Add LOCARCHIVE env variable
We can search for specific individual locales using LOCPATH.
But there is no opportunity to specify env variable
to search for locale-archive file.
---
locale/loadarchive.c | 14 +++++++++++---
locale/programs/locale.c | 12 +++++++++++-
locale/programs/locarchive.c | 12 +++++++++++-
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
index 5b857d5d24..b9c55e1091 100644
--- a/locale/loadarchive.c
+++ b/locale/loadarchive.c
@@ -123,6 +123,15 @@ calculate_head_size (const struct locarhead *h)
return MAX (namehash_end, MAX (string_end, locrectab_end));
}
+static int
+open_locale_archive (void)
+{
+ char *path = getenv ("LOCARCHIVE");
+ if (path)
+ return __open_nocancel (path, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
+ return __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
+}
+
/* Find the locale *NAMEP in the locale archive, and return the
internalized data structure for its CATEGORY data. If this locale has
@@ -202,7 +211,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
archmapped = &headmap;
/* The archive has never been opened. */
- fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
+ fd = open_locale_archive ();
if (fd < 0)
/* Cannot open the archive, for whatever reason. */
return NULL;
@@ -397,8 +406,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
if (fd == -1)
{
struct __stat64_t64 st;
- fd = __open_nocancel (archfname,
- O_RDONLY|O_LARGEFILE|O_CLOEXEC);
+ fd = open_locale_archive();
if (fd == -1)
/* Cannot open the archive, for whatever reason. */
return NULL;
diff --git a/locale/programs/locale.c b/locale/programs/locale.c
index 1d1a9b2f00..663692b862 100644
--- a/locale/programs/locale.c
+++ b/locale/programs/locale.c
@@ -632,6 +632,16 @@ nameentcmp (const void *a, const void *b)
}
+static int
+open_locale_archive (void)
+{
+ char *path = getenv ("LOCARCHIVE");
+ if (path)
+ return open64 (path, O_RDONLY);
+ return open64 (ARCHIVE_NAME, O_RDONLY);
+}
+
+
static int
write_archive_locales (void **all_datap, char *linebuf)
{
@@ -644,7 +654,7 @@ write_archive_locales (void **all_datap, char *linebuf)
int fd, ret = 0;
uint32_t cnt;
- fd = open64 (ARCHIVE_NAME, O_RDONLY);
+ fd = open_locale_archive ();
if (fd < 0)
return 0;
diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
index 71fd9f34fa..5a67fae4b6 100644
--- a/locale/programs/locarchive.c
+++ b/locale/programs/locarchive.c
@@ -116,6 +116,16 @@ prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags,
}
+static int
+open_locale_archive (const char * archivefname, int flags)
+{
+ char *path = getenv ("LOCARCHIVE");
+ if (path)
+ return open64 (path, flags);
+ return open64 (archivefname, flags);
+}
+
+
static void
create_archive (const char *archivefname, struct locarhandle *ah)
{
@@ -577,7 +587,7 @@ open_archive (struct locarhandle *ah, bool readonly)
while (1)
{
/* Open the archive. We must have exclusive write access. */
- fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
+ fd = open_locale_archive (archivefname, readonly ? O_RDONLY : O_RDWR);
if (fd == -1)
{
/* Maybe the file does not yet exist? If we are opening
--
2.39.2
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-locale-Add-LOCARCHIVE-env-variable.patch --]
[-- Type: text/x-patch; name="0001-locale-Add-LOCARCHIVE-env-variable.patch", Size: 3625 bytes --]
From e0d259c2940efe0a9caf889a60b016f126c197a5 Mon Sep 17 00:00:00 2001
From: mga-sc <mark.goncharov@syntacore.com>
Date: Wed, 5 Jun 2024 09:00:54 +0300
Subject: [PATCH] [locale]: Add LOCARCHIVE env variable
We can search for specific individual locales using LOCPATH.
But there is no opportunity to specify env variable
to search for locale-archive file.
---
locale/loadarchive.c | 14 +++++++++++---
locale/programs/locale.c | 12 +++++++++++-
locale/programs/locarchive.c | 12 +++++++++++-
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
index 5b857d5d24..b9c55e1091 100644
--- a/locale/loadarchive.c
+++ b/locale/loadarchive.c
@@ -123,6 +123,15 @@ calculate_head_size (const struct locarhead *h)
return MAX (namehash_end, MAX (string_end, locrectab_end));
}
+static int
+open_locale_archive (void)
+{
+ char *path = getenv ("LOCARCHIVE");
+ if (path)
+ return __open_nocancel (path, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
+ return __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
+}
+
/* Find the locale *NAMEP in the locale archive, and return the
internalized data structure for its CATEGORY data. If this locale has
@@ -202,7 +211,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
archmapped = &headmap;
/* The archive has never been opened. */
- fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
+ fd = open_locale_archive ();
if (fd < 0)
/* Cannot open the archive, for whatever reason. */
return NULL;
@@ -397,8 +406,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
if (fd == -1)
{
struct __stat64_t64 st;
- fd = __open_nocancel (archfname,
- O_RDONLY|O_LARGEFILE|O_CLOEXEC);
+ fd = open_locale_archive();
if (fd == -1)
/* Cannot open the archive, for whatever reason. */
return NULL;
diff --git a/locale/programs/locale.c b/locale/programs/locale.c
index 1d1a9b2f00..663692b862 100644
--- a/locale/programs/locale.c
+++ b/locale/programs/locale.c
@@ -632,6 +632,16 @@ nameentcmp (const void *a, const void *b)
}
+static int
+open_locale_archive (void)
+{
+ char *path = getenv ("LOCARCHIVE");
+ if (path)
+ return open64 (path, O_RDONLY);
+ return open64 (ARCHIVE_NAME, O_RDONLY);
+}
+
+
static int
write_archive_locales (void **all_datap, char *linebuf)
{
@@ -644,7 +654,7 @@ write_archive_locales (void **all_datap, char *linebuf)
int fd, ret = 0;
uint32_t cnt;
- fd = open64 (ARCHIVE_NAME, O_RDONLY);
+ fd = open_locale_archive ();
if (fd < 0)
return 0;
diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
index 71fd9f34fa..5a67fae4b6 100644
--- a/locale/programs/locarchive.c
+++ b/locale/programs/locarchive.c
@@ -116,6 +116,16 @@ prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags,
}
+static int
+open_locale_archive (const char * archivefname, int flags)
+{
+ char *path = getenv ("LOCARCHIVE");
+ if (path)
+ return open64 (path, flags);
+ return open64 (archivefname, flags);
+}
+
+
static void
create_archive (const char *archivefname, struct locarhandle *ah)
{
@@ -577,7 +587,7 @@ open_archive (struct locarhandle *ah, bool readonly)
while (1)
{
/* Open the archive. We must have exclusive write access. */
- fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
+ fd = open_locale_archive (archivefname, readonly ? O_RDONLY : O_RDWR);
if (fd == -1)
{
/* Maybe the file does not yet exist? If we are opening
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH][locale]: Add LOCARCHIVE env variable
2024-06-05 8:36 [PATCH][locale]: Add LOCARCHIVE env variable Mark Goncharov
@ 2024-06-05 12:26 ` Carlos O'Donell
0 siblings, 0 replies; 2+ messages in thread
From: Carlos O'Donell @ 2024-06-05 12:26 UTC (permalink / raw)
To: Mark Goncharov, libc-locales
On 6/5/24 4:36 AM, Mark Goncharov via Libc-locales wrote:
> From e0d259c2940efe0a9caf889a60b016f126c197a5 Mon Sep 17 00:00:00 2001
> From: mga-sc <mark.goncharov@syntacore.com>
> Date: Wed, 5 Jun 2024 09:00:54 +0300
> Subject: [PATCH] [locale]: Add LOCARCHIVE env variable
Thanks for posting this!
I'm going to provide a high level review here, not about any individual details.
>
> We can search for specific individual locales using LOCPATH.
> But there is no opportunity to specify env variable
> to search for locale-archive file.
In general from a design perspective I want to avoid adding new environment
variables to glibc that change behaviour.
Instead we have switched largely to using the glibc tunables infrastructure
which allows environment variables to be cleaned cleanly and clearly for
setxid processes.
Please have a look at existing tunable infrastructure and documenting the
new tunable in manual/tunables.texi. A tunable can have an environment
variable fallback if you want.
Feel free to post here or libc-alpha@sourceware.org for wider developer
review.
> ---
> locale/loadarchive.c | 14 +++++++++++---
> locale/programs/locale.c | 12 +++++++++++-
> locale/programs/locarchive.c | 12 +++++++++++-
> 3 files changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/locale/loadarchive.c b/locale/loadarchive.c
> index 5b857d5d24..b9c55e1091 100644
> --- a/locale/loadarchive.c
> +++ b/locale/loadarchive.c
> @@ -123,6 +123,15 @@ calculate_head_size (const struct locarhead *h)
> return MAX (namehash_end, MAX (string_end, locrectab_end));
> }
>
> +static int
> +open_locale_archive (void)
> +{
> + char *path = getenv ("LOCARCHIVE");
> + if (path)
> + return __open_nocancel (path, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
> + return __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
> +}
> +
>
> /* Find the locale *NAMEP in the locale archive, and return the
> internalized data structure for its CATEGORY data. If this locale has
> @@ -202,7 +211,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
> archmapped = &headmap;
>
> /* The archive has never been opened. */
> - fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
This happens today for all processes even setuid root ones and so we
are careful not to load an arbitrary file that a local user can change.
> + fd = open_locale_archive ();> if (fd < 0)
> /* Cannot open the archive, for whatever reason. */
> return NULL;
> @@ -397,8 +406,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
> if (fd == -1)
> {
> struct __stat64_t64 st;
> - fd = __open_nocancel (archfname,
> - O_RDONLY|O_LARGEFILE|O_CLOEXEC);
> + fd = open_locale_archive();
> if (fd == -1)
> /* Cannot open the archive, for whatever reason. */
> return NULL;
> diff --git a/locale/programs/locale.c b/locale/programs/locale.c
> index 1d1a9b2f00..663692b862 100644
> --- a/locale/programs/locale.c
> +++ b/locale/programs/locale.c
> @@ -632,6 +632,16 @@ nameentcmp (const void *a, const void *b)
> }
>
>
> +static int
> +open_locale_archive (void)
> +{
> + char *path = getenv ("LOCARCHIVE");
> + if (path)
> + return open64 (path, O_RDONLY);
> + return open64 (ARCHIVE_NAME, O_RDONLY);
> +}
> +
> +
> static int
> write_archive_locales (void **all_datap, char *linebuf)
> {
> @@ -644,7 +654,7 @@ write_archive_locales (void **all_datap, char *linebuf)
> int fd, ret = 0;
> uint32_t cnt;
>
> - fd = open64 (ARCHIVE_NAME, O_RDONLY);
> + fd = open_locale_archive ();
> if (fd < 0)
> return 0;
>
> diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
> index 71fd9f34fa..5a67fae4b6 100644
> --- a/locale/programs/locarchive.c
> +++ b/locale/programs/locarchive.c
> @@ -116,6 +116,16 @@ prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags,
> }
>
>
> +static int
> +open_locale_archive (const char * archivefname, int flags)
> +{
> + char *path = getenv ("LOCARCHIVE");
> + if (path)
> + return open64 (path, flags);
> + return open64 (archivefname, flags);
> +}
> +
> +
> static void
> create_archive (const char *archivefname, struct locarhandle *ah)
> {
> @@ -577,7 +587,7 @@ open_archive (struct locarhandle *ah, bool readonly)
> while (1)
> {
> /* Open the archive. We must have exclusive write access. */
> - fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
> + fd = open_locale_archive (archivefname, readonly ? O_RDONLY : O_RDWR);
> if (fd == -1)
> {
> /* Maybe the file does not yet exist? If we are opening
> --
> 2.39.2
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-05 12:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-05 8:36 [PATCH][locale]: Add LOCARCHIVE env variable Mark Goncharov
2024-06-05 12:26 ` Carlos O'Donell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).