commit: f5371db11967838deb85ce0d11ea76f3676ccadd Author: Kerin Millar <kfm <AT> plushkava <DOT> net> AuthorDate: Sun Aug 17 01:38:04 2025 +0000 Commit: Kerin Millar <kfm <AT> plushkava <DOT> net> CommitDate: Sun Aug 17 01:56:01 2025 +0000 URL: https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=f5371db1
Ensure that locales/charmaps are opened relative to the prefix Consider a scenario in which an arbitrary prefix is specified. # mkdir /var/tmp/rootfs # cd / # cp -a --parents usr/share/i18n /var/tmp/rootfs # locale-gen -c - --prefix /var/tmp/rootfs <<<"C.UTF-8 UTF-8" Compiling 1 locale definition file with 1 worker ... [1/1] Compiling locale: C.UTF-8 The location of the archive shall be "/var/tmp/rootfs/usr/lib/locale/locale-archive". Adding 1 locale to the locale archive ... Successfully installed an archive containing 1 locale, of 0.46 MiB in size. At first glance, it would appear that all has gone well. However, through the use of the strace(1) utility, it can be seen that the localedef(1) utility is unable to honour the specified prefix in the course of opening the locale and charmap files. openat(AT_FDCWD, "/usr/share/i18n/charmaps/UTF-8.gz", O_RDONLY) = 3 openat(AT_FDCWD, "/usr/share/i18n/locales/C", O_RDONLY) = 3 Address this issue by setting the I18NPATH environment variable in accordance with the specified prefix. With that, it can be seen that the appropriate files are now opened. openat(AT_FDCWD, "/var/tmp/rootfs/usr/share/i18n/charmaps/UTF-8.gz", O_RDONLY) = 3 openat(AT_FDCWD, "/var/tmp/rootfs/usr/share/i18n/locales/C", O_RDONLY) = 3 It should be noted that this bug would have been rather difficult to reproduce in a Gentoo Prefix environment, since its localedef(1) binary hard-codes the appropriate prefix. Bug: https://bugs.gentoo.org/785406 Reported-by: Joakim Tjernlund <joakim.tjernlund <AT> nokia.com> Signed-off-by: Kerin Millar <kfm <AT> plushkava.net> locale-gen | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/locale-gen b/locale-gen index f0b85fe..b3052ed 100755 --- a/locale-gen +++ b/locale-gen @@ -60,6 +60,10 @@ umask 0022; my %opt = parse_opts($gentoo_prefix, @ARGV); my $prefix = $opt{'prefix'} // $gentoo_prefix; + # Ensure that locale/charmap files are opened relative to the prefix. + # This is important in situations where the --prefix option is given. + $ENV{'I18NPATH'} = catdir($prefix, '/usr/share/i18n'); + # For the directory to be unknown strongly implies the absence of glibc. if (! defined $locale_dir) { die "$PROGRAM: Aborting because the OS does not appear to use GNU libc\n";
