commit:     1c1b32c6af1e053338714a850503f632bd25f820
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Sep 13 22:51:57 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Sat Sep 13 22:51:57 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=1c1b32c6

Drop the run_localedef() subroutine

Given that run_localedef() no longer expects a $prefix parameter, its
continued existence is difficult to justify. Adapt the run() subroutine
so as to be able to act in its stead.

See-also: 18bead55adee7ad706316320dbeb9abb8cc147e8
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/locale-gen b/locale-gen
index 90ed60b..9018e7b 100755
--- a/locale-gen
+++ b/locale-gen
@@ -28,6 +28,9 @@ my @TEMPFILES;
 # Unset BASH_ENV for security reasons. Even as sh(1), bash acts upon it.
 delete $ENV{'BASH_ENV'};
 
+# Prevent the --verbose option of localedef(1) from being implicitly enabled.
+delete $ENV{'POSIXLY_CORRECT'};
+
 # Protect against the inheritance of an unduly restrictive umask.
 umask 0022;
 
@@ -250,7 +253,7 @@ sub list_locales ($prefix) {
                if (length $prefix) {
                        push @args, '--prefix', $prefix;
                }
-               run_localedef(@args);
+               run('localedef', @args);
        } else {
                chomp(my @locales = readline $pipe);
                if (-1 == waitpid($pid, 0) || $? != 0) {
@@ -485,7 +488,7 @@ sub generate_locales ($workers, @locales) {
 
 sub compile_locale ($locale, $charmap, $canonical) {
        my $output_dir = "./$canonical";
-       run_localedef('--no-archive', '-i', $locale, '-f', $charmap, '--', 
$output_dir);
+       run('localedef', '--no-archive', '-i', $locale, '-f', $charmap, '--', 
$output_dir);
 }
 
 sub generate_archive ($gentoo_prefix, $locale_dir, $prior_archive, 
@canonicals) {
@@ -503,7 +506,7 @@ sub generate_archive ($gentoo_prefix, $locale_dir, 
$prior_archive, @canonicals)
        printf "Adding %d locale%s to the locale archive ...\n", $total, 
plural($total);
        my $stderr = fopen('stderr.log', '+>');
        redirect_stderr($stderr, sub {
-               run_localedef(qw( --prefix . --quiet --add-to-archive -- ), 
@canonicals);
+               run(qw( localedef --prefix . --quiet --add-to-archive -- ), 
@canonicals);
        });
 
        # Propagate the diagnostics and errors raised by localedef(1), if any.
@@ -566,19 +569,6 @@ sub install_archive ($src_path, $dst_path, 
$may_reset_labels) {
        }
 }
 
-sub run_localedef (@args) {
-       # Prevent the --verbose option from being potentially implied.
-       delete local $ENV{'POSIXLY_CORRECT'};
-
-       # Execute localedef(1). Don't fork if doing so from a child process.
-       my @cmd = ('localedef', @args);
-       if ($$ == $PID) {
-               system @cmd;
-       } elsif (! exec @cmd) {
-               exit 1;
-       }
-}
-
 sub fopen ($path, $mode = '<') {
        if (! open my $fh, $mode, $path) {
                die "$PROGRAM: Can't open '$path': $!\n";
@@ -616,8 +606,14 @@ sub render_printable ($value) {
 }
 
 sub run ($cmd, @args) {
-       system $cmd, @args;
-       throw_child_error($cmd);
+       if ($$ == $PID) {
+               system $cmd, @args;
+               throw_child_error($cmd);
+       } else {
+               # Refrain from forking if called from a subprocess.
+               exec $cmd, @args;
+               exit ($! == ENOENT ? 127 : 126);
+       }
 }
 
 sub throw_child_error ($cmd, $status = $?) {

Reply via email to