[luatex] annoying locale error

luigi scarso luigi.scarso at gmail.com
Thu Nov 10 05:36:55 CET 2022


On Thu, 10 Nov 2022 at 05:11, Werner LEMBERG <wl at gnu.org> wrote:

>
> [I don't know the exact luatex version, sorry]
>
>
> Folks,
>
>
> I get the very annoying and extremely unhelpful error message
>
> ```
> Unable to read environment locale:exit now.
> ```
>
> This is from a CI container where I can't easily call `locale` to find
> out more details.  Additionally, looking up this problem in the
> internet, it seems that luatex is sensitive to very subtle details
> that can easily be missed (for example, `-` vs. `_`).
>
> Is there a way to make luatex tell me what exactly the problem is?
>
>
This is the part of luainit.c where luatex calls setlocale:

 /*tex
        Get the current locale (it should be |C|) and save |LC_CTYPE|,
|LC_COLLATE|
        and |LC_NUMERIC|. Later |luainterpreter()| will consciously use
them.
    */
    old_locale = xstrdup(setlocale (LC_ALL, NULL));
    lc_ctype = NULL;
    lc_collate = NULL;
    lc_numeric = NULL;
    if (old_locale) {
        /*tex
            If |setlocale| fails here, then the state could be compromised,
and
            we exit.
        */
        env_locale = setlocale (LC_ALL, "");
        if (!env_locale && !lua_only) {
            fprintf(stderr,"Unable to read environment locale: exit
now.\n");
            exit(1);
        }
        tmp = setlocale (LC_CTYPE, NULL);
        if (tmp) {
            lc_ctype = xstrdup(tmp);
        }
        tmp = setlocale (LC_COLLATE, NULL);
        if (tmp) {
            lc_collate = xstrdup(tmp);
        }
        tmp = setlocale (LC_NUMERIC, NULL);
        if (tmp) {
            lc_numeric = xstrdup(tmp);
        }
        /*tex
            Return to the previous locale if possible, otherwise it's a
serious
            error and we exit: we can't ensure a 'sane' locale for lua.
        */
        env_locale = setlocale (LC_ALL, old_locale);
        if (!env_locale) {
          fprintf(stderr,"Unable to restore original locale %s: exit
now.\n",old_locale);
          exit(1);
        }
        xfree(old_locale);
    } else {
       fprintf(stderr,"Unable to store environment locale.\n");
    }
    /*tex make sure that the locale is 'sane' (for lua) */
    putenv(LC_CTYPE_C);
    putenv(LC_COLLATE_C);
    putenv(LC_NUMERIC_C);

 --
luigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/luatex/attachments/20221110/2fc5d64d/attachment.html>


More information about the luatex mailing list.