FS#20911 - [initscripts] locale: fix inheritance

Attached to Project: Arch Linux
Opened by Sébastien Luttringer (seblu) - Wednesday, 22 September 2010, 02:07 GMT
Last edited by Tom Gundersen (tomegun) - Sunday, 23 October 2011, 15:36 GMT
Task Type Bug Report
Category Arch Projects
Status Closed
Assigned To Thomas Bächler (brain0)
Roman Kyrylych (Romashka)
Tom Gundersen (tomegun)
Architecture All
Severity High
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

currently locales settings in rc.sysinit broke inheritance of locales settings. rc.sysinit create file in /etc/profile.d/locale.sh which set LANG environment variable to value setted in /etc/rc.conf.

This cause a simple issue : Every time a profile is read by a shell, locale variable a overwritted. This is bad.

Because:
- It goes in reverse to a logical behaviour
- Broke inheritance of /etc/environment variable which can be set by pam_env.
- Give an inconsistant configuration if trying to change this value in X init script (because all running shell will be in rc.conf locale)
- Configuration of non-standard locales schema cannot be clean (see example)
- It's not elegant

An example: someone want to have all messages in english but, all other locales for his country (france by example). Need to set all LC_* (except LC_ALL) to "fr_FR.UTF8" in /etc/environment. Or create a export in each config file of each shell it use to have his LANG set to french and LC_MESSAGES set to english.

In a kiss approach, and i hope also better, profile.d just have to source /etc/environment and archlinux guide should set up locales in this file and not in rc.conf. rc.sysint can also use /etc/environment to know if it has to set console in UTF8 mode.

I thinks rc.conf parameter have to set locale at start, not at any time a login shell is started.

I can help if necessary.

Additional info:
* package version : 2010.07-1
This task depends upon

This task blocks these from closing
 FS#9384 - [initscripts] allow read only root 
Closed by  Tom Gundersen (tomegun)
Sunday, 23 October 2011, 15:36 GMT
Reason for closing:  Fixed
Comment by Tom Gundersen (tomegun) - Wednesday, 01 December 2010, 10:38 GMT
In implementing support for Arch in systmed I came across this feature. To me the bug report makes sense and it seems that /etc/profile.d/locale.sh should/could be removed. However, there was probably some reason for putting it there in the first place. Could someone point me to documentation/mailing-list discussion where the rationale for this feature was discussed/described?
Comment by Roman Kyrylych (Romashka) - Saturday, 04 December 2010, 19:46 GMT
locale.sh existed for ages
A quick search in gitweb shows that it already existed in 2005:
http://projects.archlinux.org/initscripts.git/commit/?id=39f5db6e89fd04da3979c11c3b2761ea031cd94d

You can browse related bugreports:
https://bugs.archlinux.org/index.php?string=locale.sh&project=1&search_in_comments=1&search_in_details=1&status%5B%5D=&do=index
for some comments about the reasons it exists.

Currently I am testing a couple of changes for locale configuration, but no guarantees.
Comment by Tom Gundersen (tomegun) - Saturday, 04 December 2010, 20:46 GMT
@Romashka: thanks for the pointers. The oldest bug report explained the reason for the utf8 handling. It means I can delete this from the arch systemd integration, it is handled already by systemd.

If I understand correctly, the current locale.sh enables/disables utf8 every time a new shell is started. This seems wrong for two reasons: 1) What about before a shell is started? I.e. if you need to disable utf8 mode for your login. 2) You should only need to have to do it once.

Instead one could do (in addition to the change of mode of every tty as is currently done in rc.sysinit):
Change the variable /sys/module/vt/parameters/default_utf8 to enable/disable utf8 for new vc's.
Comment by Sébastien Luttringer (seblu) - Friday, 14 January 2011, 02:44 GMT
I read all the bugs. Fortunately, there is not much bug about locale.sh.

My read confort my opinion! We can do things better, even if they was written at J.C. time (and it's your first bug fix). In a nutshell, several bugs come from a bad detection to why/when/where shell should or should not setting vc in utf8.

So, locale.sh do 2 things:
1 - it set locale
2 - if term is a VC it set utf8 mode.

Two, can be done really more genisouly by tom proposal. This is run at startup. One time. So simple! So beautiful!
We generally use shell in VT and not in VC. So trying to remove this 1% used line to set VC in utf8 sounds like a costless improvment.

About point one:
Tom give a really good new reason, login program should be aware of locale settings (one day maybe, it will speak french). And to follow this idea, when default shell is not a "shell" but a custom program which not source /etc/profile.d/locale.sh, it should also be aware of locales. Like it can know HOME or other parameters set by PAM process. Think to a perl or python script has default shell.

I can try to propose a patch, but if you are working on, it's great! :)
Comment by Tom Gundersen (tomegun) - Friday, 05 August 2011, 00:41 GMT
@seblu: i have not been able to find a nice solution for this. Mostly because login and friends messes with the environment variables passed to it. For the time being I have added a small patch that at least stops generating locale.sh on every boot, but instead does the rc.conf parsing in locale.sh. That should make it a bit simpler for people to disable.

Any input on a proper solution would be appreciated. Maybe using pam? I guess the correct solution will be (as usual) to look at whatever everyone else is doing and see if someone has a nice solution for this.
Comment by Matt (laforge) - Saturday, 06 August 2011, 11:35 GMT
I won't pretend to know/care a lot about locale settings. But doesn't it go against Linux philosophy to only be able to change lang settings on system boot? Some systems aren't meant to be rebooted/shut down and have huge uptimes. Would an optional rc.d script be sufficient to handle lang notifications?
Comment by Tom Gundersen (tomegun) - Saturday, 06 August 2011, 11:44 GMT
@laforge: locale settings are set via environment variables. That means that the settings are passed to a program when it starts, and the only way to pick up changes in locale variables is to restart a program. With the current initscripts release you actually have to reboot to pick up the changes, with the change I just made in git all you have to do is to relogin. However, it would not be possible to have a rc script that changed the locale of all the running programs or anything like that.
Comment by Sébastien Luttringer (seblu) - Saturday, 06 August 2011, 11:59 GMT
"But doesn't it go against Linux philosophy to only be able to change lang settings on system boot?"

This is not a linux philosophy. LANG setting can be per user / per program and can be changed when you want. Most DE allow user to configure LANG setting directly when they start it.

Think that reboot, kill uptime score. It's bad :) But here, question is not only about LANG settings.
Comment by mkkot (mkkot) - Saturday, 13 August 2011, 11:37 GMT
I'm not sure if it's right bugreport for this comment but...
Since you introduced DAEMON_LOCALE in /etc/rc.conf, I set it to ="yes", why not. Now, when starting system, I can observe such strange behaviour:
Udev starts, then fsck checks filesystems, says they are clean etc. It is problably done by /etc/rc.d/functions:
# Check local filesystems
fsck_all() {
fsck -A -T -C"$FSCK_FD" -a -t "no${NETFS//,/,no},noopts=_netdev" $FORCEFSCK

Fsck output is displayed as it supposed to be, translated, with national characters. Then, probably when next function form /etc/rc.d/functions is called, character encoding form fsck gets broken:
# Function for setting console font if required
set_consolefont()
...

My rc.conf:

LOCALE="pl_PL.utf8"
HARDWARECLOCK="UTC"
TIMEZONE="Europe/Warsaw"
KEYMAP="pl"
CONSOLEFONT="lat2-16"
CONSOLEMAP="8859-2"
USECOLOR="yes"
DAEMON_LOCALE="yes"
Comment by Sébastien Luttringer (seblu) - Sunday, 14 August 2011, 16:45 GMT
no it's not the right bugreport. Can you open a new one, with a screenshot / copy of your init line. I don't understand what's wrong.
Comment by Matt (laforge) - Sunday, 23 October 2011, 15:07 GMT
Thanks for replies. I did pacman -Syu today and it seems some LANG stuff changed. /etc/locale.conf and /etc/profile.d/locale.sh play a role now. And it works fine afaik. Can this thread get marked "solved"? Or is there more work to do here?
Comment by Tom Gundersen (tomegun) - Sunday, 23 October 2011, 15:36 GMT
@Matt: the reboot stuff is certainly taken care of. I just tried the inheritance, and that looks sorted too (as bash only reads profile.d when it is started with --login, so in other cases it inherits the locale correctly). I'll close.

Loading...