about summary refs log tree commit homepage
path: root/lib/PublicInbox/SpawnPP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-02-25 05:14:10 +0000
committerEric Wong <e@80x24.org>2019-04-04 09:13:58 +0000
commit721368cd04bfbd03c0d9173fff633ae34f16409a (patch)
tree8b4f8fc9eb232c551f9f3455de8bb4aea0e35712 /lib/PublicInbox/SpawnPP.pm
parent293c51d2c23ceb8b8018cf4bfa3deaf56f7753b2 (diff)
downloadpublic-inbox-721368cd04bfbd03c0d9173fff633ae34f16409a.tar.gz
We'll be spawning cgit and git-diff, which can take gigantic
amounts of CPU time and/or heap given the right (ermm... wrong)
input.  Limit the damage that large/expensive diffs can cause.
Diffstat (limited to 'lib/PublicInbox/SpawnPP.pm')
-rw-r--r--lib/PublicInbox/SpawnPP.pm9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/PublicInbox/SpawnPP.pm b/lib/PublicInbox/SpawnPP.pm
index 743db224..8692b767 100644
--- a/lib/PublicInbox/SpawnPP.pm
+++ b/lib/PublicInbox/SpawnPP.pm
@@ -9,8 +9,8 @@ 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: $!";
@@ -22,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: $!";
                 }