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

Locale broken when osh is set as default shell #318

Closed
Wychmire opened this issue May 30, 2019 · 6 comments
Closed

Locale broken when osh is set as default shell #318

Wychmire opened this issue May 30, 2019 · 6 comments

Comments

@Wychmire
Copy link

Wychmire commented May 30, 2019

When oilshell is set as the default shell (via any method: chsh, usermod, or making a new user with osh as default shell) LANG becomes unset (or never gets set?)
If the shell is set to Bash locale will print the desired results, but if you use chsh to change the shell to osh and relog locale tells me LANG and the other relevant variables are not set. Running osh from inside bash

bash$ osh
osh$ locale

still results in the correct variables being printed.

With bash as the default shell:

bash$ locale
LANG=en_US.UTF8
LC_CTYPE="en_US.UTF8"
LC_NUMERIC="en_US.UTF8"
LC_TIME="en_US.UTF8"
LC_COLLATE="en_US.UTF8"
LC_MONETARY="en_US.UTF8"
LC_MESSAGES="en_US.UTF8"
LC_PAPER="en_US.UTF8"
LC_NAME="en_US.UTF8"
LC_ADDRESS="en_US.UTF8"
LC_TELEPHONE="en_US.UTF8"
LC_MEASUREMENT="en_US.UTF8"
LC_IDENTIFICATION="en_US.UTF8"
LC_ALL=

With osh as the default shell:

osh$ locale
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=

I feel like if the locale is set from KDE's settings this issue doesn't appear, but I no longer have KDE around to test it out.

Edit: I used this script to add osh to the shell list

#!/bin/bash
if ! grep osh /etc/shells >/dev/null; then \
	echo /usr/local/bin/osh >> /etc/shells; \
else \
	shell=$(shell grep osh etc/shells); \
	if [ $$shell != /usr/local/bin/osh ]; then \
		sed -i -e "s#$$shell#/usr/local/bin/osh#g" /etc/shells; \
	fi \
fi
@andychu
Copy link
Contributor

andychu commented May 30, 2019

Thanks for the report! What distro are you on?

I was not able to reproduce on Ubuntu 16.04. However I think this would be a good thing to document for people switching to OSH, as it appears it varies by distro.

I'm not sure how the locale / LANG gets set to be honest!

I thought it might have been in /etc/bash.bashrc but I didn't find it there. Maybe the login program is responsible for it? I recently learned that the login program also sets $HOME. A POSIX shell doesn't have to set $HOME.

osh$ whoami
osh-user

osh$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
osh$ osh --version
Oil version 0.6.pre20
Release Date: 2019-05-14 18:26:37+00:00
Arch: x86_64
OS: Linux
Platform: #46~16.04.1-Ubuntu SMP Thu May 3 10:06:43 UTC 2018
Compiler: GCC 5.4.0 20160609
Interpreter: OVM
Interpreter version: 2.7.13
Bytecode: bytecode-opy.zip

@Wychmire
Copy link
Author

I'm running Arch, where to set up localization you edit /etc/locale.gen and uncomment your language and then run locale-gen (w/ sudo or as root). You also edit /etc/locale.conf to include (in my case) LANG=en_US.UTF-8.

Do you have a file at /etc/profile.d/locale.sh? It looks like it might be responsible. I don't have a local locale.conf so it should fall back to the last elseif and load locale.conf from etc but it doesn't.

#!/bin/sh

# load locale.conf in XDG paths.
# /etc/locale.conf loads and overrides by kernel command line is done by systemd
# But we override it here, see FS#56688
if [ -z "$LANG" ]; then
  if [ -n "$XDG_CONFIG_HOME" ] && [ -r "$XDG_CONFIG_HOME/locale.conf" ]; then
    . "$XDG_CONFIG_HOME/locale.conf"
  elif [ -n "$HOME" ] && [ -r "$HOME/.config/locale.conf" ]; then
    . "$HOME/.config/locale.conf"
  elif [ -r /etc/locale.conf ]; then
    . /etc/locale.conf
  fi
fi

# define default LANG to C if not already defined
LANG=${LANG:-C}

# export all locale (7) variables when they exist
export LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \
       LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT \
       LC_IDENTIFICATION

It's worth noting that osh does pick it up if you set the variable in /etc/environment.

According to the ArchWiki Bourne-compatible shells should source /etc/profile which in turn sources everything from /etc/profile.d/. Bash's online man page says basically the same thing. Bash reads and executes /etc/profile and then it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order.

So I think osh just needs to source /etc/profile on startup?

If I source it manually it looks like it works. I also tried adding source /etc/profile to my oshrc and the locale gets set.

osh$ locale
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=

osh$ source /etc/profile

osh$ locale
LANG=en_US.UTF8
LC_CTYPE="en_US.UTF8"
LC_NUMERIC="en_US.UTF8"
LC_TIME="en_US.UTF8"
LC_COLLATE="en_US.UTF8"
LC_MONETARY="en_US.UTF8"
LC_MESSAGES="en_US.UTF8"
LC_PAPER="en_US.UTF8"
LC_NAME="en_US.UTF8"
LC_ADDRESS="en_US.UTF8"
LC_TELEPHONE="en_US.UTF8"
LC_MEASUREMENT="en_US.UTF8"
LC_IDENTIFICATION="en_US.UTF8"
LC_ALL=

@andychu
Copy link
Contributor

andychu commented May 30, 2019

OK that makes sense. OSH intentionally doesn't source anything but one file:

https://github.com/oilshell/oil/blob/master/doc/osh-manual.md

As explained, that's to avoid this rat's nest: https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/

The way I see it, sourcing /etc/profile in oshrc is the right thing. Although you're the first person to run into this, and I'm sure not the last.

I will put a note about LANG there.


But I'm still not sure how it gets set on my system... my /etc/profile.d looks like this, and I couldn't find LANG there:

andy@lisa:/etc/profile.d$ ls
appmenu-qt5.sh  apps-bin-path.sh  bash_completion.sh  cedilla-portuguese.sh  vte-2.91.sh

andychu pushed a commit that referenced this issue May 30, 2019
@andychu
Copy link
Contributor

andychu commented May 30, 2019

I added more detail here:

https://github.com/oilshell/oil/blob/master/doc/osh-manual.md

Let me know what you think. The manual is not in great shape yet, but I expect setting up oshrc to be one of the #1 issues for new users, so I put it first.

@Wychmire
Copy link
Author

Ah, I think that explains the entire issue! I do feel like I'm not the only one who will encounter this problem and it might be worth adding a commented out source /etc/profile with a brief explanation, but that's up to you of course and after reading the linked article it's pretty clear why you wouldn't want to. Will there be a man page/wiki at some point?
I think what you added does explain what's needed clearly enough.

Maybe it's because I'm not using a Display Manager like GDM or SDDM? I'm pretty sure when I was using SDDM with osh as my default shell I didn't have this problem.

@Wychmire
Copy link
Author

Closing since the cause for the issue has been found.

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

No branches or pull requests

2 participants