From e315b5fc0304bc14214be42f336e4b8aa18b459e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20R=C3=B6sner?= Date: Sun, 12 Oct 2025 12:06:14 +0200 Subject: [PATCH] www-servers/pound: tests: use forks instead of threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The test harness perl script for pound uses threads for socket listeners, requiring PERL_FEATURES="ithreads". - To avoid forcing users to rebuild all perl, replace threads by forks of the main process. Signed-off-by: Philipp Rösner Part-of: https://github.com/gentoo/gentoo/pull/44136 Closes: https://github.com/gentoo/gentoo/pull/44136 Signed-off-by: Sam James --- .../pound/files/pound-4.16-test-threads.patch | 93 +++++++++++++++++++ .../pound/files/pound-4.17-test-threads.patch | 84 +++++++++++++++++ www-servers/pound/pound-4.16.ebuild | 4 + www-servers/pound/pound-4.17.ebuild | 4 + 4 files changed, 185 insertions(+) create mode 100644 www-servers/pound/files/pound-4.16-test-threads.patch create mode 100644 www-servers/pound/files/pound-4.17-test-threads.patch diff --git a/www-servers/pound/files/pound-4.16-test-threads.patch b/www-servers/pound/files/pound-4.16-test-threads.patch new file mode 100644 index 000000000000..1231ecc0b20a --- /dev/null +++ b/www-servers/pound/files/pound-4.16-test-threads.patch @@ -0,0 +1,93 @@ +Replace usage of threads for socket listeners by forks of the +main process in order to avoid requiring perl built with +PERL_FEATURES="ithreads". +The added return values are necessary because otherwise +the process (before the thread) would continue it's procedure +call chain (before, the thread exited, not executing any more +code). + +--- a/tests/poundharness.pl ++++ b/tests/poundharness.pl +@@ -16,8 +16,6 @@ + use strict; + use warnings; + use Socket qw(:DEFAULT :crlf); +-use threads; +-use threads::shared; + use Getopt::Long; + use HTTP::Tiny; + use POSIX qw(:sys_wait_h); +@@ -90,7 +88,6 @@ sub cleanup { + ## ----------------------------------- + + my %status_codes; +-share(%status_codes); + + $SIG{QUIT} = $SIG{HUP} = $SIG{TERM} = $SIG{INT} = \&cleanup; + +@@ -1542,19 +1539,16 @@ sub read_and_process { + my $self = shift; + + foreach my $lst (@{$self->{listeners}}) { +- $lst->listen; +- } +- +- foreach my $lst (@{$self->{listeners}}) { +- threads->create(sub { +- my $lst = shift; ++ my $pid = fork(); ++ if ($pid == 0) { + $lst->listen; + while (1) { +- my $fh; +- accept($fh, $lst->socket_handle) or threads->exit(); +- process_http_request($fh, $lst) ++ my $fh; ++ accept($fh, $lst->socket_handle) or last; ++ process_http_request($fh, $lst) + } +- }, $lst)->detach; ++ exit 0; ++ } + } + } + +@@ -1595,7 +1589,7 @@ sub process_http_request { + + local $| = 1; + my $http = HTTPServ->new($sock, $backend); +- $http->parse(); ++ return unless $http->parse(); + if ($http->uri =~ m{^/([^/]+)(/.*)?}) { + my ($dir, $rest) = ($1, $2); + if (my $ep = $endpoints{$dir}) { +@@ -1658,7 +1652,8 @@ sub getline { + sub ParseRequest { + my $http = shift; + +- my $input = $http->getline() or threads->exit(); ++ my $input = $http->getline(); ++ return 0 unless defined $input; + # print "GOT $input\n"; + my @res = split " ", $input; + if (@res != 3) { +@@ -1666,6 +1661,7 @@ sub ParseRequest { + } + + ($http->{METHOD}, $http->{URI}, $http->{VERSION}) = @res; ++ return 1; + } + + sub ParseHeader { +@@ -1703,9 +1699,10 @@ sub GetBody { + + sub parse { + my $http = shift; +- $http->ParseRequest; ++ return 0 unless $http->ParseRequest; + $http->ParseHeader; + $http->GetBody; ++ return 1; + } + + sub reply { diff --git a/www-servers/pound/files/pound-4.17-test-threads.patch b/www-servers/pound/files/pound-4.17-test-threads.patch new file mode 100644 index 000000000000..e0705eb38e5a --- /dev/null +++ b/www-servers/pound/files/pound-4.17-test-threads.patch @@ -0,0 +1,84 @@ +Replace usage of threads for socket listeners by forks of the +main process in order to avoid requiring perl built with +PERL_FEATURES="ithreads". +The added return values are necessary because otherwise +the process (before the thread) would continue it's procedure +call chain (before, the thread exited, not executing any more +code). + +--- a/tests/poundharness.pl ++++ b/tests/poundharness.pl +@@ -16,7 +16,6 @@ + use strict; + use warnings; + use Socket qw(:DEFAULT :crlf); +-use threads; + use Getopt::Long; + use HTTP::Tiny; + use POSIX qw(:sys_wait_h); +@@ -1619,19 +1618,16 @@ sub read_and_process { + my $self = shift; + + foreach my $lst (@{$self->{listeners}}) { +- $lst->listen; +- } +- +- foreach my $lst (@{$self->{listeners}}) { +- threads->create(sub { +- my $lst = shift; ++ my $pid = fork(); ++ if ($pid == 0) { + $lst->listen; + while (1) { +- my $fh; +- accept($fh, $lst->socket_handle) or threads->exit(); +- process_http_request($fh, $lst) ++ my $fh; ++ accept($fh, $lst->socket_handle) or last; ++ process_http_request($fh, $lst) + } +- }, $lst)->detach; ++ exit 0; ++ } + } + } + +@@ -1694,7 +1690,7 @@ sub process_http_request { + + local $| = 1; + my $http = HTTPServ->new($sock, $backend); +- $http->parse(); ++ return unless $http->parse(); + if ($http->uri =~ m{^/([^/]+)(/.*)?}) { + my ($dir, $rest) = ($1, $2); + if (my $ep = $endpoints{$dir}) { +@@ -1757,7 +1753,8 @@ sub getline { + sub ParseRequest { + my $http = shift; + +- my $input = $http->getline() or threads->exit(); ++ my $input = $http->getline(); ++ return 0 unless defined $input; + # print "GOT $input\n"; + my @res = split " ", $input; + if (@res != 3) { +@@ -1765,6 +1762,7 @@ sub ParseRequest { + } + + ($http->{METHOD}, $http->{URI}, $http->{VERSION}) = @res; ++ return 1; + } + + sub ParseHeader { +@@ -1802,9 +1800,10 @@ sub GetBody { + + sub parse { + my $http = shift; +- $http->ParseRequest; ++ return 0 unless $http->ParseRequest; + $http->ParseHeader; + $http->GetBody; ++ return 1; + } + + sub reply { diff --git a/www-servers/pound/pound-4.16.ebuild b/www-servers/pound/pound-4.16.ebuild index 7442e39b32a6..d3fe791372aa 100644 --- a/www-servers/pound/pound-4.16.ebuild +++ b/www-servers/pound/pound-4.16.ebuild @@ -38,6 +38,10 @@ BDEPEND=" ) " +PATCHES=( + "${FILESDIR}"/${P}-test-threads.patch +) + src_configure() { local myconf=( --disable-dynamic-backends diff --git a/www-servers/pound/pound-4.17.ebuild b/www-servers/pound/pound-4.17.ebuild index 89c5a348f314..c14176eb1bcc 100644 --- a/www-servers/pound/pound-4.17.ebuild +++ b/www-servers/pound/pound-4.17.ebuild @@ -38,6 +38,10 @@ BDEPEND=" ) " +PATCHES=( + "${FILESDIR}"/${P}-test-threads.patch +) + src_configure() { local myconf=( --disable-dynamic-backends