]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Spawn.pm
lei: less error-prone FD mapping
[public-inbox.git] / lib / PublicInbox / Spawn.pm
index b03f2d59abca5c2f921abdda68ce046a16505c52..1842899c6ac16929ae76aaa2d13b43831da6d094 100644 (file)
@@ -209,7 +209,7 @@ my $fdpass = <<'FDPASS';
 #include <sys/socket.h>
 
 #if defined(CMSG_SPACE) && defined(CMSG_LEN)
-#define SEND_FD_CAPA 5
+#define SEND_FD_CAPA 10
 #define SEND_FD_SPACE (SEND_FD_CAPA * sizeof(int))
 union my_cmsg {
        struct cmsghdr hdr;
@@ -343,7 +343,7 @@ undef $fdpass;
 sub which ($) {
        my ($file) = @_;
        return $file if index($file, '/') >= 0;
-       foreach my $p (split(':', $ENV{PATH})) {
+       for my $p (split(/:/, $ENV{PATH})) {
                $p .= "/$file";
                return $p if -x $p;
        }
@@ -352,8 +352,7 @@ sub which ($) {
 
 sub spawn ($;$$) {
        my ($cmd, $env, $opts) = @_;
-       my $f = which($cmd->[0]);
-       defined $f or die "$cmd->[0]: command not found\n";
+       my $f = which($cmd->[0]) // die "$cmd->[0]: command not found\n";
        my @env;
        $opts ||= {};
 
@@ -365,7 +364,7 @@ sub spawn ($;$$) {
        for my $child_fd (0..2) {
                my $parent_fd = $opts->{$child_fd};
                if (defined($parent_fd) && $parent_fd !~ /\A[0-9]+\z/) {
-                       defined(my $fd = fileno($parent_fd)) or
+                       my $fd = fileno($parent_fd) //
                                        die "$parent_fd not an IO GLOB? $!";
                        $parent_fd = $fd;
                }
@@ -374,7 +373,7 @@ sub spawn ($;$$) {
        my $rlim = [];
 
        foreach my $l (@RLIMITS) {
-               defined(my $v = $opts->{$l}) or next;
+               my $v = $opts->{$l} // next;
                my $r = eval "require BSD::Resource; BSD::Resource::$l();";
                unless (defined $r) {
                        warn "$l undefined by BSD::Resource: $@\n";