From bdebb7d4cf637aea5aaabea44afb075e66c7b63f Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:26:07 -0300 Subject: [PATCH] fix(xcat-core): --nproc=0 exits 127 before any package work Parallel::ForkManager does not fork when max_procs is 0: start() returns 0 in the original process. start_build_worker took that 0 as a forked worker. It closed the only writer of the gate pipe, read end-of-file and exited 127, so both worker loops in buildrpms.pl stopped before they built a package or updated a repository. start_build_worker now compares $$ before and after the fork callback. When the callback returned 0 in the same process, it closes the gate and returns 0, and the caller runs the work under the locks it already holds. Both loops call start_build_worker, so both are covered. build_worker_nofork.t passes with this change. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- build-utils/lib/XCAT/BuildUtils.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build-utils/lib/XCAT/BuildUtils.pm b/build-utils/lib/XCAT/BuildUtils.pm index 38aac57e93..f140cfbcc3 100644 --- a/build-utils/lib/XCAT/BuildUtils.pm +++ b/build-utils/lib/XCAT/BuildUtils.pm @@ -765,6 +765,8 @@ Returns: failed and the worker exits with status 127, and () when the fork failed. In scalar context: the pid, or undef. In the child: 0, after the parent released it. The child never returns otherwise. + When $fork returns 0 without forking, as Parallel::ForkManager does with max_procs 0: 0 + (list context: (0, 1)) in the calling process, which then runs the work itself. =cut @@ -774,7 +776,8 @@ sub start_build_worker { require POSIX; $fork //= sub { fork() }; pipe(my $gate_r, my $gate_w) or return; - my $pid = $fork->(); + my $self = $$; + my $pid = $fork->(); unless (defined $pid) { my $error = $!; close($gate_r); @@ -782,6 +785,13 @@ sub start_build_worker { $! = $error; return; } + # Parallel::ForkManager->new(0) does not fork, and start() returns 0 in this process. The + # work then runs here, under the locks this process already holds. + if (!$pid && $$ == $self) { + close($gate_r); + close($gate_w); + return wantarray ? (0, 1) : 0; + } unless ($pid) { close($gate_w); POSIX::setpgid(0, 0) or POSIX::_exit(127);