From 53eafcd90a3179200192263807cf3df7c869b500 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 30 Jan 2024 07:22:21 +0000 Subject: spawn: support some rlimit uses via Inline::C BSD::Resource isn't packaged for Alpine (as of 3.19), but we also have optional Inline::C support and already rely on calling setrlimit(2) directly from the Inline::C version of pi_fork_exec. --- t/spawn.t | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 't') diff --git a/t/spawn.t b/t/spawn.t index 48f541b8..5b17ed38 100644 --- a/t/spawn.t +++ b/t/spawn.t @@ -6,7 +6,7 @@ use Test::More; use PublicInbox::Spawn qw(which spawn popen_rd run_qx); require PublicInbox::Sigfd; require PublicInbox::DS; - +my $rlimit_map = PublicInbox::Spawn->can('rlimit_map'); { my $true = which('true'); ok($true, "'true' command found with which()"); @@ -192,14 +192,19 @@ EOF } SKIP: { - eval { - require BSD::Resource; - defined(BSD::Resource::RLIMIT_CPU()) - } or skip 'BSD::Resource::RLIMIT_CPU missing', 3; + if ($rlimit_map) { # Inline::C installed + my %rlim = $rlimit_map->(); + ok defined($rlim{RLIMIT_CPU}), 'RLIMIT_CPU defined'; + } else { + eval { + require BSD::Resource; + defined(BSD::Resource::RLIMIT_CPU()) + } or skip 'BSD::Resource::RLIMIT_CPU missing', 3; + } my $cmd = [ $^X, qw(-w -e), <<'EOM' ]; use POSIX qw(:signal_h); -use BSD::Resource qw(times); use Time::HiRes qw(time); # gettimeofday +my $have_bsd_resource = eval { require BSD::Resource }; my $set = POSIX::SigSet->new; $set->emptyset; # spawn() defaults to blocking all signals sigprocmask(SIG_SETMASK, $set) or die "SIG_SETMASK: $!"; @@ -211,10 +216,10 @@ while (1) { # and `write' (via Perl warn)) on otherwise idle systems to # hit RLIMIT_CPU and fire signals: # https://marc.info/?i=02A4BB8D-313C-464D-845A-845EB6136B35@gmail.com - my @t = times; + my @t = $have_bsd_resource ? BSD::Resource::times() : (0, 0); $tot = $t[0] + $t[1]; if (time > $next) { - warn "# T: @t (utime, ctime, cutime, cstime)\n"; + warn "# T: @t (utime, ctime, cutime, cstime)\n" if @t; $next = time + 1.1; } } -- cgit v1.2.3-24-ge0c7