From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2567D205C8 for ; Tue, 12 Mar 2019 04:00:47 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 13/13] spawn: require soft and hard vals for RLIMIT_* params Date: Tue, 12 Mar 2019 04:00:46 +0000 Message-Id: <20190312040046.4619-14-e@80x24.org> In-Reply-To: <20190312040046.4619-1-e@80x24.org> References: <20190312040046.4619-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Our high-level config already treats single limits as a soft==hard limit for limiters; so stop handling that redundant in the low-level spawn() sub. --- lib/PublicInbox/Spawn.pm | 8 +------- t/spawn.t | 3 ++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index fd98160..7b0f3bd 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -205,18 +205,12 @@ sub spawn ($;$$) { foreach my $l (RLIMITS()) { defined(my $v = $opts->{$l}) or next; - my ($soft, $hard); - if (ref($v)) { - ($soft, $hard) = @$v; - } else { - $soft = $hard = $v; - } my $r = eval "require BSD::Resource; BSD::Resource::$l();"; unless (defined $r) { warn "$l undefined by BSD::Resource: $@\n"; next; } - push @$rlim, $r, $soft, $hard; + push @$rlim, $r, @$v; } my $pid = pi_fork_exec($in, $out, $err, $f, $cmd, \@env, $rlim); $pid < 0 ? undef : $pid; diff --git a/t/spawn.t b/t/spawn.t index 5abedc9..8840428 100644 --- a/t/spawn.t +++ b/t/spawn.t @@ -100,7 +100,8 @@ SKIP: { my ($r, $w); pipe($r, $w) or die "pipe: $!"; my $cmd = ['sh', '-c', 'while true; do :; done']; - my $opt = { RLIMIT_CPU => [ 1, 1 ], RLIMIT_CORE => 0, 1 => fileno($w) }; + my $fd = fileno($w); + my $opt = { RLIMIT_CPU => [ 1, 1 ], RLIMIT_CORE => [ 0, 0 ], 1 => $fd }; my $pid = spawn($cmd, undef, $opt); close $w or die "close(w): $!"; my $rset = ''; -- EW