Re: What's the locale for system files (e.g. /etc/fstab)?
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 24 Mar 2022 19:12:10 UTC
On Thu, Mar 24, 2022, 10:30 AM Simon J. Gerraty <sjg@juniper.net> wrote: > Warner Losh <imp@bsdimp.com> wrote: > > Config files, like fstab, have no locale and parsing them with a locale > leads to errors, even when the user or the system has a nondefault locale. > > > > > > > > Put more generally, there's not a system-wide place which declares the > > > encoding for system files, which leads to this problem where we > > > interpret files from one user's locale using another user's locale. > > > > Well /etc/login.conf *IS* a system wide declaration of this type of > > stuff, both lang= and charset= are declared there. > > > > Since system wide files like yhese are always parsed without a locale, > this information is correct, but I'm not sure how it applies. > > > > It is always C.UTF-8. Anything else may, or may not, work based on > accidents of coincident encoding. Not everything can change locales, and > the fstab and other parsing routines in libc assume C.UTF-8 or even just > the ascii-7/8 subset. > > > > > > > > One solution would a symlink in /etc that "points to" the name of the > > > current system-wide locale name. > > > > > > % ls -Fl /etc/locale > > > lrwxr-xr-x 1 root wheel 7 Mar 23 15:42 /etc/locale@ -> C.UTF-8 > > > > grep lang /etc/login.conf: > > :lang=C.UTF-8: > > :lang=ru_RU.UTF-8:\ > > > > Probably what you want? > > I doubt it, one is from the entry for Russian users ;-) > > > > > You can get this with the locale routines, no? No need for grep. > > I suspect not. > > AFAIK virtually everything about locale support tells you about the > locale for the current process - which does not necessarily inform you > of the locale that was in effect when a system file was last edited. > > I don't even know if it is guaranteed that everything that reads system > files groks random locales - or what happens when you have 3 admins each > prefering a different locale, do different entries in fstab for example > get impacted and the result thus not readable by anyone? > > There's probably something to be said for enforcing something like > C.UTF-8 for system files. > That is the primary reason for system files always being C.UTF-8... There is no way to tag it as anything else... and some of these files are often parsed from a context that can't set the locale, like the boot loader or the kernel... also, these files have a format that was defined back in the 7bit ascii time frame. They also don't make use of the text in a way that isn't literal... Having said that, I'm unsure how you'd mount /<kanji-for-neko> from fstab, or if that is well defined. The kernel just presents a string of bytes not containing /... Warner --sjg >