Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing LOCPATH environment variable does not reinitialize locale subsystem #5815

Closed
therealpxc opened this issue Apr 12, 2019 · 4 comments
Closed
Assignees
Milestone

Comments

@therealpxc
Copy link

@therealpxc therealpxc commented Apr 12, 2019

Fish has apparently got some monitoring built in to detect locale changes and change encodings accordingly, which is awesome.

But I noticed when working around a locale configuration issue (once mistakenly reported as a Fish bug here: #4935) that LOCALE_ARCHIVE is not among them.

This means that unfortunately, setting LOCALE_ARCHIVE inside one's Fish configuration is insufficient to get certain prompt characters to print correctly, even though subsequent launches of Fish (in whose environment LOCALE_ARCHIVE is already set) will have the locale set correctly.

To reproduce, simply (1) have Fish launch with a glibc seeking a locale-archive file in one directory, which lacks some locales, and change the LOCALE_ARCHIVE environment variable to one that includes more locales. Then to witness the other problem, (2) change one of the monitored locale environment variables so that Fish attempts to reinitialize locale stuff.

Here's a demonstration

Last login: Fri Apr 12 20:51:53 2019 from 10.144.8.187
pxc@somehost:~ $ fish -l -i
Welcome to fish, the friendly interactive shell
 somehost ? ~ ? echo $LOCALE_ARCHIVE
/nix/store/67b3n3zga54zic8s72vd4sdz1nl4lr0q-glibc-locales-2.27/lib/locale/locale-archive
 somehost ? ~ ? set -e LOCALE_ARCHIVE
 somehost ? ~ ? fish --debug-level 5 ^| grep setlocale
<5> fish: init_locale() setlocale(): '(null)'
Welcome to fish, the friendly interactive shell
 somehost ? ~ ? set -gx LANG en_US.UTF-8
<5> fish: init_locale() setlocale(): '(null)'
 somehost ? ~ ? exit
 somehost ? ~ ? cat ~/.config/fish/conf.d/00000-nixify.fish
if not set -q NIX_PROFILE
  if not functions -q fenv
    set fenvdir ~/.local/share/omf/pkg/foreign-env/functions
    test -d "$fenvdir"; and set fish_function_path $fish_function_path $fenvdir
  end
  fenv source /etc/profile.d/nix.sh ^/dev/null
end

# for non-NixOS, see https://github.com/NixOS/nixpkgs/issues/54418
set -q LOCALE_ARCHIVE
or set -gx LOCALE_ARCHIVE (nix-build --no-out-link '<nixpkgs>' -A glibcLocales)'/lib/locale/locale-archive'
 somehost ? ~ ? source ~/.config/fish/conf.d/00000-nixify.fish
 somehost ? ~ ? echo $LOCALE_ARCHIVE
/nix/store/67b3n3zga54zic8s72vd4sdz1nl4lr0q-glibc-locales-2.27/lib/locale/locale-archive
 somehost ? ~ ? fish --debug-level 5 ^| grep setlocale
<5> fish: init_locale() setlocale(): 'en_US.UTF-8'
Welcome to fish, the friendly interactive shell
 somehost  ~  set -gx LANG en_AU.UTF-8
<5> fish: init_locale() setlocale(): 'en_AU.UTF-8'
 somehost  ~  set -gx LANG en_US.UTF-8
<5> fish: init_locale() setlocale(): 'en_US.UTF-8'
 somehost  ~  exit
 somehost ? ~ ?

Given that Fish's setlocale() occurs but fails when LANG is reset after setting LOCALE_ARCHIVE, I worry that some limitation of glibc may be involved, but I don't really know how that works. I hope that's not the case, and that this bug report can still be useful. 😳

@zanchey
Copy link
Member

@zanchey zanchey commented Apr 13, 2019

LOCALE_ARCHIVE is not a variable that POSIX or glibc knows about - perhaps a Nix-specific thing?

@therealpxc
Copy link
Author

@therealpxc therealpxc commented Apr 13, 2019

Hm, I should have looked at that more closely. I think that's right.

@therealpxc
Copy link
Author

@therealpxc therealpxc commented Apr 13, 2019

So it appears that what I wrote originally also applies, with slight adjustment, to the variable LOCPATH, which is actually part of glibc. I'm not sure why Nix uses LOCALE_ARCHIVE and prefers the archive format, instead of compiling them separately and using LOCPATH or a modification of it (which is what Guix does).

But getting fish to respond to LOCPATH changes would be a nice, non-Nix-specific way to accommodate changes in the locations by which glibc should find locales that might also be useful in Nixpkgs and could certainly simplify any patches Nixpkgs might want to include for its own Fish package.

Last login: Sat Apr 13 01:44:32 2019 from 10.144.8.187
Welcome to fish, the friendly interactive shell
 somehost ? ~ ? ls -lh /usr/lib/locale/ | head
total 2.0M
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 aa_DJ
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 aa_DJ.utf8
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 aa_ER
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 aa_ER@saaho
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 aa_ET
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 af_ZA
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 af_ZA.utf8
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 agr_PE
drwxr-xr-x 3 root root 4.0K Apr 13 01:38 ak_GH
 somehost ? ~ ? set -e LOCALE_ARCHIVE
 somehost ? ~ ? fish --debug-level 5 -c exit ^| grep setlocale
<5> fish: init_locale() setlocale(): '(null)'
 somehost ? ~ ? set -gx LOCPATH /usr/lib/locale
 somehost ? ~ ? fish --debug-level 5 -c exit ^| grep setlocale
<5> fish: init_locale() setlocale(): 'en_US.UTF-8'
 somehost ? ~ ? fish
Welcome to fish, the friendly interactive shell
 somehost  ~ 

@therealpxc therealpxc changed the title Changing LOCALE_ARCHIVE environment variable does not reinitialize locale subsystem Changing LOCPATH environment variable does not reinitialize locale subsystem Apr 13, 2019
@zanchey
Copy link
Member

@zanchey zanchey commented Apr 13, 2019

Yes, LOCPATH seems to be the standard interface (glibc, AIX... uh, z/OS....), so I'll add that.

@zanchey zanchey added this to the fish 3.1.0 milestone Apr 13, 2019
@zanchey zanchey self-assigned this Apr 13, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants