LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   How can the locale be set for processes started by boot scripts? (http://www.linuxquestions.org/questions/slackware-14/how-can-the-locale-be-set-for-processes-started-by-boot-scripts-793636/)

catkin 03-06-2010 11:04 AM

How can the locale be set for processes started by boot scripts?
 
Hello :)

This thread is a continuation of an earlier thread which had an inappropriate title :doh:

How can the locale be set for processes started by boot scripts? For processes which are descendents of login shells, locale is set by /etc/profile.d/lang.*sh in which envar $LANG is set. For virtual terminals, locale is set by kernel parameter vt.default_utf8=1 (thanks Rupa). But how is it set for processes started by boot scripts which are direct descendents of the init process?

Looking around to find how it might be done, I discovered:
  • There are no *locale* files under /etc.
  • /etc/inittab has nothing about locale.
  • man init has nothing about locale.
  • man 7 locale describes locale.h and its usage.
  • man 5 locale describes the format of locale files.
  • /sbin/init (as investigated using the strings command) may call nl_langinfo but man nl_langinfo only describes how to query the locale, not where it is set.
  • The envars set while running a boot script (as displayed by the env command) are:
    CONSOLE=/dev/console
    TERM=linux
    prevlevel=N
    INIT_VERSION=sysvinit-2.86
    PATH=/bin:/usr/bin:/sbin:/usr/sbin
    vga=791
    RUNLEVEL=4
    runlevel=4
    PWD=/
    PREVLEVEL=N
    HOME=/
    SHLVL=2
I want to set the locale for Bacula. According to the Bacula Main Reference*, in the "13.1 Critical Items" section: "Bacula assumes all filenames are in UTF-8 format. This is important when saving the filenames to the catalog. ... you must explicitly ensure that your locale is set properly. Typically this means that the bf LANG environment variable must end in .UTF-8. An full example is en US.UTF-8. The exact syntax may vary a bit from OS to OS, and exactly how you define it will also vary."

It would be nice to set the locale for Bacula only but that would require front-ending a lot of executables and I'm not confident of being able to identify them all.

Presumably both the daemon processes and the processes initiated by a logged-on user should have the same locale. One solution would be to export LANG=<something>.utf8 in the Bacula boot scripts and use /etc/profile.d/lang.*sh for the logged-on users but I'm curious how it can be set for all processes.

EDIT: Bacula is configured to use MySQL so presumably that, too, should have LANG=<something>.utf8.

Best

Charles

* Available as PDF or HTML at http://www.bacula.org/en/?page=documentation)

gnashley 03-08-2010 03:04 AM

Two ideas: modify individual boot scripts to pass the desired LOCALE to the process, or create wrappers for the called binaries which set the LOCALE before exec-ing the real program.

catkin 03-08-2010 03:12 AM

Quote:

Originally Posted by gnashley (Post 3889939)
Two ideas: modify individual boot scripts to pass the desired LOCALE to the process, or create wrappers for the called binaries which set the LOCALE before exec-ing the real program.

Thanks gnashley :)

The first suggestion is the one I will go with if I can't find a way to set locale for the whole system by setting it earlier in the process tree.

I considered the second suggestion but rejected it because of the difficulty of identifying all the binaries, and it's a lot of work, and it might break if an upgrade introduced new binaries.


All times are GMT -5. The time now is 09:33 PM.