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

shell: /etc/locale.conf is missing, the default POSIX has no UTF-8 support #568

Closed
eriksjolund opened this issue Jul 11, 2020 · 25 comments
Closed
Labels

Comments

@eriksjolund
Copy link

eriksjolund commented Jul 11, 2020

On a newly bought HP Elitebook 850 G6 laptop that has a keyboard with Swedish keyboard layout, I did the following

  1. Boot up fedora-coreos-32.20200601.3.0-live.x86_64.iso from a USB stick.
  2. Type sudo localectl set-keymap sv-latin1
  3. Type stty -a
[core@localhost ~]$ stty -a
speed 38400 baud; rows 67; columns 240; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc
[core@localhost ~]$ 
  1. Press the key å. The terminal now looks like:
[core@localhost ~]$ å
  1. Press the key å. The terminal now looks like:
[core@localhost ~]$ åå
  1. Press backspace. The terminal now looks like:
[core@localhost ~]$ å
  1. Press backspace. The terminal now looks like:
[core@localhost ~]$ 
  1. Press backspace. The terminal now looks like:
[core@localhost ~]$
  1. Press backspace. The terminal now looks like:
[core@localhost ~]
  1. Press backspace. The terminal still looks like:
[core@localhost ~]

(But this time the laptop makes a loud system beep)

Behavior on Fedora 32

I performed a similar test on a 2 year old HP Elitebook 850 G5 laptop that has a keyboard with Swedish keyboard layout and was installed with Fedora 32. During its installation Swedish keyboard was chosen.

I did the following

  1. Boot up Fedora 32 from local SSD and log in to a graphical session
  2. Press Ctrl-F3
  3. Log in to the text terminal by typing my username and password
  4. Type sudo localectl status and my password
[erik@laptop ~]$ sudo localectl status
[sudo] password for esjolund:
   System Locale: LANG=en_US.UTF-8
       VC Keymap: sv-latin1
      X11 Layout: se,us
     X11 Variant: ,
[erik@laptop ~]$ 
  1. Type stty -a
[erik@laptop ~]$ stty -a
speed 38400 baud; rows 67; columns 240; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc
[erik@laptop ~]$ 
  1. Press the key å. The terminal now looks like:
[erik@laptop ~]$ å
  1. Press the key å. The terminal now looks like:
[erik@laptop ~]$ åå
  1. Press backspace. The terminal now looks like:
[erik@laptop ~]$ å
  1. Press backspace. The terminal now looks like:
[erik@laptop ~]$ 
  1. Press backspace. The terminal still looks like:
[erik@laptop ~]$ 

(But this time the laptop makes a loud system beep)

I compared the outputs from stty -a between Fedora CoreOS and Fedora 32. They were identical.

@dustymabe
Copy link
Member

hey @eriksjolund - is this still reproducible?

@eriksjolund
Copy link
Author

@dustymabe Yes it is reproducible but I had to use the keymap se instead of sv-latin1.
(Maybe the keymap was renamed. That's my guess)

( I skipped the command stty -a because the command produces so much text to type)

  1. Boot up fedora-coreos-35.20211203.1.0-live.x86_64.iso from a USB stick.
  2. Run sudo localectl set-keymap sv-latin1
    The command fails with the error message Failed to set keymap: Keymap sv-latin1 is not installed.
  3. Run sudo localectl set-keymap se
  4. Press the key å. The terminal now looks like:
[core@localhost ~]$ å
  1. Press the key å. The terminal now looks like:
[core@localhost ~]$ åå
  1. Press backspace. The terminal now looks like:
[core@localhost ~]$ å
  1. Press backspace. The terminal now looks like:
[core@localhost ~]$ 
  1. Press backspace. The terminal now looks like:
[core@localhost ~]$
  1. Press backspace. The terminal now looks like:
[core@localhost ~]
  1. Press backspace. The terminal still looks like:
[core@localhost ~]

(But this time the laptop makes a loud system beep)

@lucab
Copy link
Contributor

lucab commented Dec 8, 2021

I think this is a locale mismatch, specifically in relation to UTF-8 handling.
For some reason, on the node console I can see that locale believes that we are under a POSIX config, contrarily to what localectl status says (C.UTF-8).
The POSIX locale is not UTF-8 aware, so deleting multibyte sequences ends up eating more than one character.
The issue can be locally fixed by setting LANG=C.UTF-8 for the console session.
But this should really be the proper FCOS default already, so the real question is why it does not get applied (even though localectl status believes so).

@lucab
Copy link
Contributor

lucab commented Dec 8, 2021

By the way this is easier to observe on a random node via SSH:

$ export -n LANG; export -n LANGUAGE
$ ssh core@<node> -- 'locale && localectl status'

LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

   System Locale: LANG=C.UTF-8
       VC Keymap: n/a
      X11 Layout: n/a

@miabbott
Copy link
Member

miabbott commented Dec 8, 2021

@lucab asked for locale from a non-ostree system; I had an F34 Cloud VM locally - grabbed a screenshot of the GUI

image

@dustymabe
Copy link
Member

@lucab - are you using cosa run or kola spawn for this investigation? If I use cosa run I get what you are seeing, but if I virt-install --import the same qcow and SSH in using the ssh utility I see UTF-8 from locale and not POSIX.

@miabbott
Copy link
Member

miabbott commented Dec 8, 2021

cosa run --devshell-console:

$ locale && localectl status                                                                                                                                                                                                                                                                               
LANG=C.UTF-8                                                                                                                                                                                                                                                                                                                  
LC_CTYPE="C.UTF-8"                                                                                                                                                                                                                                                                                                            
LC_NUMERIC="C.UTF-8"                                                                                                                                                                                                                                                                                                          
LC_TIME="C.UTF-8"                                                                                                                                                                                                                                                                                                             
LC_COLLATE="C.UTF-8"                                                           
LC_MONETARY="C.UTF-8"                                                          
LC_MESSAGES="C.UTF-8"                                                   
LC_PAPER="C.UTF-8"                                                             
LC_NAME="C.UTF-8"                                                       
LC_ADDRESS="C.UTF-8"                                                      
LC_TELEPHONE="C.UTF-8"                                                
LC_MEASUREMENT="C.UTF-8"                  
LC_IDENTIFICATION="C.UTF-8"                             
LC_ALL=                                   
   System Locale: LANG=C.UTF-8                                                 
       VC Keymap: n/a                                                                                                                                                                                                                                                                                                         
      X11 Layout: n/a                                                                         

cosa run:

$ locale && localectl status
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
   System Locale: LANG=C.UTF-8
       VC Keymap: n/a
      X11 Layout: n/a

@lucab
Copy link
Contributor

lucab commented Dec 9, 2021

@dustymabe neither, that was on a plain qemu-kvm with the qemu (x86) image. But I can see the same on a bare metal (arm64) machine.
Do note that I had to do export -n LANG; export -n LANGUAGE to see this.
By default our SSHd takes the language env from the client, which is likely the reason why we haven't noticed this before:

$ sudo cat /etc/ssh/sshd_config.d/50-redhat.conf 
[...]
# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

@dustymabe
Copy link
Member

I see. So basically we don't see it mainly because we typically SSH in and $LANG,$LANGUAGE are set up from the client that way.

@lucab
Copy link
Contributor

lucab commented Dec 9, 2021

I'm slightly relieved that system services seems to get a sane LANG which matches what localectl status thinks:

# systemd-run env   
Running as unit: run-r5e45c17e88ff46938b876c1b91bdd0d0.service

# journalctl -u run-r5e45c17e88ff46938b876c1b91bdd0d0.service
systemd[1]: Started /usr/bin/env.
env[1912]: LANG=C.UTF-8
env[1912]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
env[1912]: INVOCATION_ID=2a75de64ef6248f98f9c14b489f08710
env[1912]: JOURNAL_STREAM=8:32021
env[1912]: SYSTEMD_EXEC_PID=1912
systemd[1]: run-r5e45c17e88ff46938b876c1b91bdd0d0.service: Deactivated successfully.

So at least this can be narrowed down to users interactive shells only, hopefully.

@lucab
Copy link
Contributor

lucab commented Dec 9, 2021

Ok, I think this is due to the fact that we don't have a /etc/locale.conf file in our images. A simple echo 'LANG=C.UTF-8' > /etc/locale.conf makes everything work.

But now, a bigger point. This usually gets set up by systemd-firstboot, but we don't use that. Still, systemd owns the default for that part of the machine config (which is also configurable at build-time through meson). We could symlink /etc/locale.conf to some default content under /usr in our images, but... I'm not seeing any file with such content provided by systemd.

So, bottom line, I think we'd need systemd to expose its default as a (factory?) file somewhere, and then have a mechanism to symlink/copy that to the expected /etc path.

@lucab lucab changed the title Backspace eats the prompt (localectl set-keymap sv-latin1, press "å", press backspace) shell: /etc/locale.conf is missing, the default POSIX has no UTF-8 support Dec 9, 2021
@travier
Copy link
Member

travier commented Dec 9, 2021

Maybe we can do the echo 'LANG=C.UTF-8' > /etc/locale.conf workaround in a post-process script in the manifest (see Colin's better suggestion) as a quick win until a better solution is found. It would still be possible to set your own via Ignition if needed.

@cgwalters
Copy link
Member

Ah, glad you were finally able to localize the problem!

We can ship this file statically in our config overlay too instead of doing it via a script.

Are you sure this is "usually" set up by systemd-firstboot? At least for most other Fedora editions, they use Anaconda which I would bet money writes that file.

@lucab
Copy link
Contributor

lucab commented Dec 9, 2021

Oh yes, there is probably not a single definition of a "usual" flow, and likely Anaconda plays a role too. I was going by the definition in the systemd docs:

/etc/locale.conf is usually created and updated using systemd-localed.service(8). localectl(1) may be used to alter the settings in this file during runtime from the command line. Use systemd-firstboot(1) to initialize them on mounted (but not booted) system images.

@jlebon
Copy link
Member

jlebon commented Dec 9, 2021

Indeed, looks like the relevant Anaconda code is here.
So 👍 to just shipping the config.

@dustymabe
Copy link
Member

dustymabe commented Dec 9, 2021

Rather than implement this for each OSTree variant in Fedora this feels almost like this could/should be a systemd tmpfile. i.e. if it doesn't exist then copy /path/to/default/locale into place.

@lucab
Copy link
Contributor

lucab commented Dec 10, 2021

Yes, we can quickfix this via a static file in the overlay and a tmpfiles.d fragment.
Before adding that, let's just make sure we agree on a common path forward with systemd, otherwise we'll end up adding another (the third) hardcoded/arbitrary default locale value.
I wrote down the problem and the sketch of our plan at systemd/systemd#21723. If they overall agree with that plan of actions, then I see no blockers.

@dustymabe
Copy link
Member

@lucab indeed. What you propose in systemd/systemd#21723 was exactly what I was thinking/proposing as well (I'm just bad at explaining it). Thank you for writing that up!

@dustymabe dustymabe added the status/pending-upstream-release Fixed upstream. Waiting on an upstream component source code release. label Jan 4, 2022
@dustymabe
Copy link
Member

Fixed upstream by systemd/systemd@2588920

@lucab
Copy link
Contributor

lucab commented May 24, 2022

This got released in systemd v251: https://github.com/systemd/systemd/releases/tag/v251.
I believe we will get the fix when rebasing to Fedora 37.

@dustymabe dustymabe added status/pending-next-release Fixed upstream. Waiting on a next release. and removed status/pending-upstream-release Fixed upstream. Waiting on an upstream component source code release. labels May 24, 2022
@dustymabe dustymabe added the F37 label Jun 22, 2022
@dustymabe
Copy link
Member

The fix for this went into next stream release 37.20220910.1.0. Please try out the new release and report issues.

@dustymabe dustymabe added status/pending-testing-release Fixed upstream. Waiting on a testing release. and removed status/pending-next-release Fixed upstream. Waiting on a next release. labels Oct 3, 2022
@dustymabe
Copy link
Member

The fix for this went into testing stream release 37.20221106.2.1. Please try out the new release and report issues.

@dustymabe dustymabe removed the status/pending-testing-release Fixed upstream. Waiting on a testing release. label Nov 15, 2022
@dustymabe dustymabe added the status/pending-stable-release Fixed upstream and in testing. Waiting on stable release. label Nov 15, 2022
@eriksjolund
Copy link
Author

I'm not able to try out the new releases on the laptop where I originally reproduced the bug.
(I no longer have access to that laptop)

@lucab
Copy link
Contributor

lucab commented Nov 22, 2022

I can confirm that this seems to be fixed on current testing:

$ export -n LANG; export -n LANGUAGE
$ ssh core@fcos-oracloud-testing-01.fcos -- 'grep OSTREE_VERSION /etc/os-release && locale && localectl status'

OSTREE_VERSION='37.20221106.2.1'

LANG=C.UTF-8
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=

   System Locale: LANG=C.UTF-8
       VC Keymap: n/a
      X11 Layout: n/a

The default locale for interactive shells is now C.UTF-8, with proper UTF-8 multibyte handling.

@lucab lucab closed this as completed Nov 22, 2022
@lucab lucab reopened this Nov 22, 2022
@dustymabe
Copy link
Member

The fix for this went into stable stream release 37.20221106.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants