]> Sergey Matveev's repositories - public-inbox.git/commitdiff
spawn: require soft and hard entries in RLIMIT_* handling
authorEric Wong <e@80x24.org>
Tue, 12 Mar 2019 01:47:59 +0000 (01:47 +0000)
committerEric Wong <e@80x24.org>
Thu, 4 Apr 2019 09:13:58 +0000 (09:13 +0000)
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
t/spawn.t

index fd9816082188dc8265bdad89a1449e5e9cbe73ee..7b0f3bdde6637f356e14be70790b77914c44a060 100644 (file)
@@ -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;
index 5abedc96b727b186a6bd1998b4cdec980ae24795..884042824265b59717d4ca1bc9a6096f50f0807a 100644 (file)
--- 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 = '';