commit:     46475884156ef41e4f785bdcc4af5b7d0fd91f62
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Sep 14 14:07:58 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Mon Sep 15 04:05:05 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=46475884

Have list_locales() call close to wait for the child

Presently, the list_locales() subroutine uses the waitpid builtin to
wait for the child process in which localedef(1) is executed. Instead,
have the parent process close its end of the pipe. Doing so suffices
because the closure of a filehandle produced by a piped open returns
false if one of the other syscalls involved fails or if the process
exits with a non-zero status. In other words, the child shall be
implicitly waited for.

Besides, it is sensible to close a pipe upon the very moment it no
longer serves any purpose.

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

 locale-gen | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/locale-gen b/locale-gen
index 13a9223..871d52b 100644
--- a/locale-gen
+++ b/locale-gen
@@ -255,7 +255,7 @@ sub list_locales ($prefix) {
                run('localedef', @args);
        } else {
                chomp(my @locales = readline $pipe);
-               if (-1 == waitpid($pid, 0) || $? != 0) {
+               if (! close $pipe && $! == 0) {
                        die "$PROGRAM: Can't obtain a list of the presently 
installed locales\n";
                }
                return @locales;

Reply via email to