]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
spawn: avoid string eval for optional BSD::Resource
authorEric Wong <e@80x24.org>
Tue, 29 Apr 2025 20:47:46 +0000 (20:47 +0000)
committerEric Wong <e@80x24.org>
Thu, 1 May 2025 21:29:49 +0000 (21:29 +0000)
BSD::Resource has had a get_rlimits() sub for a while to return
a hashref to non-Inline::C users.  So favor using that after
`require' rather than a string eval which can't be checked for
syntax-only errors.

lib/PublicInbox/Spawn.pm

index c832db591bcd9786649ed8fa23f6b265c7a4c3f9..1d9f9b76b1d41d0461a0039de995c418a7bafa23 100644 (file)
@@ -384,9 +384,12 @@ sub spawn ($;$$) {
        my $rlim = [];
        foreach my $l (@RLIMITS) {
                my $v = $opt->{$l} // next;
-               my $r = $RLIMITS{$l} //
-                       eval "require BSD::Resource; BSD::Resource::$l();" //
-                       do {
+               my $r = $RLIMITS{$l} // eval {
+                               require BSD::Resource;
+                               my $rl = BSD::Resource::get_rlimits();
+                               @RLIMITS{@RLIMITS} = @$rl{@RLIMITS};
+                               $RLIMITS{$l};
+                       } // do {
                                warn "$l undefined by BSD::Resource: $@\n";
                                next;
                        };