]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SpawnPP.pm
run update-copyrights from gnulib for 2019
[public-inbox.git] / lib / PublicInbox / SpawnPP.pm
index d0df94d0ded0f4cf179a2420a274e13da062be6d..25c8c87fd86747ffb9fb7466cd4223d83419813a 100644 (file)
@@ -1,13 +1,16 @@
-# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# Pure-Perl implementation of "spawn".  This can't take advantage
+# of vfork, so no speedups under Linux for spawning from large processes.
 package PublicInbox::SpawnPP;
 use strict;
 use warnings;
 use POSIX qw(dup2 :signal_h);
 
 # Pure Perl implementation for folks that do not use Inline::C
-sub public_inbox_fork_exec ($$$$$$) {
-       my ($in, $out, $err, $f, $cmd, $env) = @_;
+sub pi_fork_exec ($$$$$$) {
+       my ($in, $out, $err, $f, $cmd, $env, $rlim) = @_;
        my $old = POSIX::SigSet->new();
        my $set = POSIX::SigSet->new();
        $set->fillset or die "fillset failed: $!";
@@ -19,6 +22,11 @@ sub public_inbox_fork_exec ($$$$$$) {
                $pid = -1;
        }
        if ($pid == 0) {
+               while (@$rlim) {
+                       my ($r, $soft, $hard) = splice(@$rlim, 0, 3);
+                       BSD::Resource::setrlimit($r, $soft, $hard) or
+                         warn "failed to set $r=[$soft,$hard]\n";
+               }
                if ($in != 0) {
                        dup2($in, 0) or die "dup2 failed for stdin: $!";
                }