[arch-projects] [initscripts][RFC][PATCH] locale.sh: add support for user-specific locale.conf, drop DAEMON_LOCALE

Dave Reisner d at falconindy.com
Fri Aug 24 10:44:43 EDT 2012


On Fri, Aug 24, 2012 at 10:23:43AM -0400, Dave Reisner wrote:
> On Sat, Aug 11, 2012 at 07:53:34PM +0200, Tom Gundersen wrote:
> > We use the first configuration file we find out of:
> > 
> >  * $XDG_CONFIG_HOME/locale.conf
> >  * /etc/locale.conf
> >  * /etc/rc.conf
> > 
> > All subsequent config files are ignored. E.g., an emtpy /etc/locale.conf
> > means that LOCALE from rc.conf is ignored.
> > 
> > This will easily allow users to set one locale to be used for
> > daemons/boot and a separate one to be used for users consoles etc.
> > 
> > This eliminates the need for DAEMON_LOCALE, so remove that
> > functionality. A post-install note will be added.
> > 
> > The constraints that led to this suggestion:
> > 
> > 1) The default locale should work even if locale-gen has not been run,
> >    i.e., it should be "C".
> > 2) It is common to want the system locale to be "English", which a
> >    priori "C" satisfies. However, "C" is not UTF-8, which causes issues
> >    when the user locale is in UTF-8 (as it is the system locale that
> >    configures the console mode).
> > 3) Users might (and often do) want a different locale than what is used
> >    system-wide. Moreover, different users might want different locales.
> > 
> > In case this seems far-fetched: This computer is shared by two people
> > neither of whose mother tongue is English (and whose mother tongue
> > is  not the same). I also want all my daemons to output in English so I can
> > paste the output in bug reports etc.
> > 
> > Signed-off-by: Tom Gundersen <teg at jklm.no>
> > ---
> 
> Finally getting around to reviewing this. In short, this won't work. See
> below.
> 
> >  functions     | 24 ++++++++----------------
> >  locale.sh     | 10 ++++++----
> >  rc.conf.5.txt | 13 +++----------
> >  3 files changed, 17 insertions(+), 30 deletions(-)
> > 
> > diff --git a/functions b/functions
> > index e8ff7b8..7e7549a 100644
> > --- a/functions
> > +++ b/functions
> > @@ -9,7 +9,14 @@ localevars=(LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY
> >              LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE
> >              LC_MEASUREMENT LC_IDENTIFICATION LC_ALL)
> >  
> > -vconsolevars=(KEYMAP KEYMAP_TOGGLE FONT FONT_MAP FONT_UNIMAP)
> > +
> > +# clear the TZ envvar, so daemons always respect /etc/localtime
> > +unset TZ
> > +
> > +# sanitize the locale settings
> > +unset "${localevars[@]}"
> > +
> > +. /etc/profile.d/locale.sh
> 
> This is going to read locale from root's home, if such a thing exists.
> An odd case perhaps, but do we really want this side effect?
> 
> >  
> >  if [[ $1 == "start" ]]; then
> >  	if [[ $STARTING ]]; then
> > @@ -66,12 +73,6 @@ if (( $? != 3 )); then
> >  fi
> >  unset TERM_COLORS
> >  
> > -# clear the TZ envvar, so daemons always respect /etc/localtime
> > -unset TZ
> > -
> > -# sanitize the locale settings
> > -unset "${localevars[@]}"
> > -
> >  parse_envfile() {
> >  	local file=$1 validkeys=("${@:2}") ret=0 lineno=0 key= val=
> >  	local -r quotes=$'[\'"]' comments=$'[;#]*'
> > @@ -723,15 +724,6 @@ if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then
> >  	declare -r RC_FUNCTIONS_HOOK_FUNCS_DEFINED=1
> >  fi
> >  
> > -if [[ $DAEMON_LOCALE != [nN][oO] ]]; then
> > -	export LANG=${LOCALE:-C}
> > -	if [[ -r /etc/locale.conf ]]; then
> > -		parse_envfile /etc/locale.conf "${localevars[@]}"
> > -	fi
> > -else
> > -	export LANG=C
> > -fi
> > -
> >  # set colors
> >  if [[ $USECOLOR != [nN][oO] ]]; then
> >  	if tput setaf 0 &>/dev/null; then
> > diff --git a/locale.sh b/locale.sh
> > index c465f6f..48c3c50 100644
> > --- a/locale.sh
> > +++ b/locale.sh
> > @@ -1,10 +1,12 @@
> >  unset LANG
> >  
> > -if [ -s /etc/locale.conf ]; then
> > +if [ -s $XDG_CONFIG_HOME/locale.conf ]; then
> > +	. $XDG_CONFIG_HOME/locale.conf
> 
> This is a problem. I'm going to say that most of the time,
> XDG_CONFIG_HOME won't be defined here. We read iterate over
> /etc/profile.d in glob order (defined by current LC_COLLATE). If
> XDG_CONFIG_HOME is set by /etc/profile.d/xorg.sh, we aren't ever going
> to see this var defined.
> 
> In addition, when XDG_CONFIG_HOME isn't defined, then under absurd
> circumstances, /locale.conf would be read. I think you meant to combine
> this case with the one below it for $HOME/config:
> 
> if [ -s "${XDG_CONFIG_HOME:-$HOME/.config}/locale.conf" ]; then
>   . "${XDG_CONFIG_HOME:-$HOME/.config}/locale.conf"
> fi
> 
> But, again, with the current conditions, this just won't ever be
> defined. It's furthermore, impossible to set/override XDG_CONFIG_HOME in
> user config since it's all read post /etc/profile.
> 
> Maybe we just stick to $HOME/.config/locale.conf?
> 
> > +elif [ -s $HOME/.config/locale.conf ]; then
> > +	. $HOME/.config/locale.conf
> > +elif [ -s /etc/locale.conf ]; then
> >  	. /etc/locale.conf
> > -fi
> > -
> > -if [ -z "$LANG" ] && [ -s /etc/rc.conf ]; then
> > +elif [ -s /etc/rc.conf ]; then
> >  	LANG=$(. /etc/rc.conf 2>/dev/null; echo "$LOCALE")
> >  fi
> 
> This means that /etc/rc.conf has the last say which is contrary to the
> documentation below. And, if /etc/rc.conf exists without LOCALE defined,
> you just set locale to an empty string.
> 

Nevermind this, misread the if/elif.

> >  
> > diff --git a/rc.conf.5.txt b/rc.conf.5.txt
> > index 73c2423..8983871 100644
> > --- a/rc.conf.5.txt
> > +++ b/rc.conf.5.txt
> > @@ -190,21 +190,14 @@ FONT_MAP in /etc/vconsole.conf takes precedence (see vconsole.conf(5)), and is r
> >  This sets your system language, which will be used by all i18n-friendly applications and utilities.
> >  See `locale -a` (or locale.gen) for available options.
> >  
> > -LANG in /etc/locale.conf takes precedence (see locale.conf(5)), and is recommended.
> > +LANG in /etc/locale.conf takes precedence (see locale.conf(5)), and is recommended. User-specific
> > +locale settings which override both /etc/locale.conf and /etc/rc.conf are set in
> > +$XDG_CONFIG_HOME/locale.conf using the same syntax as /etc/locale.conf.
> >  
> >  If unset, it falls back to the C locale.
> >  
> >  	LOCALE="en_US.UTF-8"
> >  
> > -*DAEMON_LOCALE=*
> > -
> > -	- If set to 'no', export the C locale to daemons and during the boot process.
> > -	- Otherwise, export LANG (or LOCALE) as configured in /etc/locale.conf (or /etc/rc.conf).
> > -
> > -Leave this unset, unless you have a specific reason to set it to 'no'.
> > -
> > -	DAEMON_LOCALE="yes"
> > -
> >  *USECOLOR=*
> >  
> >  Use ANSI color sequences in start-up messages, unless set to 'no'.
> > -- 
> > 1.7.11.4
> > 


More information about the arch-projects mailing list