[PATCH] intl: Fix tst-gettext under inherited LC_* environment
Carlos O'Donell
carlos@redhat.com
Mon May 25 13:28:37 GMT 2026
On 5/21/26 9:26 AM, Adhemerval Zanella wrote:
> The final block of tst-gettext unsets LC_ALL plus LC_MESSAGES, LC_CTYPE,
> LC_TIME and LC_NUMERIC, sets LANG=existing-locale, and then expects
> setlocale (LC_ALL, "") to resolve every category through LANG. Any
> other LC_* category inherited from the invoking shell (e.g. LC_PAPER,
> LC_MONETARY) still takes precedence over LANG, and if it points to a
> locale that is not under the test's LOCPATH the setlocale call fails
> with ENOENT.
>
> Checked on x86_64-linux-gnu.
LGTM.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> intl/tst-gettext.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/intl/tst-gettext.c b/intl/tst-gettext.c
> index 8c60e337f35..d8605b2a05e 100644
> --- a/intl/tst-gettext.c
> +++ b/intl/tst-gettext.c
> @@ -204,11 +204,22 @@ main (int argc, char *argv[])
> result = 1;
> }
>
> - /* Now the same tests with LANG deciding. */
> + /* Now the same tests with LANG deciding. Unset every LC_* category so that
> + values inherited from the invoking shell (e.g. LC_PAPER) cannot leak into
> + setlocale (LC_ALL, "") below and force it to look up a locale that is not
> + under the test's LOCPATH. */
> unsetenv ("LC_MESSAGES");
> unsetenv ("LC_CTYPE");
> unsetenv ("LC_TIME");
> unsetenv ("LC_NUMERIC");
> + unsetenv ("LC_COLLATE");
> + unsetenv ("LC_MONETARY");
> + unsetenv ("LC_PAPER");
> + unsetenv ("LC_NAME");
> + unsetenv ("LC_ADDRESS");
> + unsetenv ("LC_TELEPHONE");
> + unsetenv ("LC_MEASUREMENT");
> + unsetenv ("LC_IDENTIFICATION");
> setenv ("LANG", "existing-locale", 1);
> check_setlocale (LC_ALL, "");
> /* This is the name of the existing domain with a catalog for the
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list