]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Syscall.pm
lei: move to v5.12 to avoid "use strict"
[public-inbox.git] / lib / PublicInbox / Syscall.pm
index e972aa41e8bad910378c3beae9e58d87bcb974d3..777c44d0660269d9753de2682b9000e04db5b4f2 100644 (file)
@@ -16,8 +16,7 @@
 # You may distribute under the terms of either the GNU General Public
 # License or the Artistic License, as specified in the Perl README file.
 package PublicInbox::Syscall;
-use strict;
-use v5.10.1;
+use v5.12;
 use parent qw(Exporter);
 use POSIX qw(ENOENT ENOSYS EINVAL O_NONBLOCK);
 use Socket qw(SOL_SOCKET SCM_RIGHTS);
@@ -390,12 +389,10 @@ sub rename_noreplace ($$) {
        }
 }
 
-sub nodatacow_fh {
-       return if !defined($SYS_fstatfs);
-       my $buf = '';
-       vec($buf, 120 * 8 - 1, 1) = 0;
+sub nodatacow_fh ($) {
        my ($fh) = @_;
-       syscall($SYS_fstatfs, fileno($fh), $buf) == 0 or
+       my $buf = "\0" x 120;
+       syscall($SYS_fstatfs // return, fileno($fh), $buf) == 0 or
                return warn("fstatfs: $!\n");
        my $f_type = unpack('l!', $buf); # statfs.f_type is a signed word
        return if $f_type != 0x9123683E; # BTRFS_SUPER_MAGIC
@@ -418,6 +415,7 @@ sub CMSG_ALIGN ($) { ($_[0] + SIZEOF_size_t - 1) & ~(SIZEOF_size_t - 1) }
 use constant CMSG_ALIGN_SIZEOF_cmsghdr => CMSG_ALIGN(SIZEOF_cmsghdr);
 sub CMSG_SPACE ($) { CMSG_ALIGN($_[0]) + CMSG_ALIGN_SIZEOF_cmsghdr }
 sub CMSG_LEN ($) { CMSG_ALIGN_SIZEOF_cmsghdr + $_[0] }
+use constant msg_controllen => CMSG_SPACE(10 * SIZEOF_int) + 16; # 10 FDs
 
 if (defined($SYS_sendmsg) && defined($SYS_recvmsg)) {
 no warnings 'once';
@@ -457,7 +455,7 @@ no warnings 'once';
 *recv_cmd4 = sub ($$$) {
        my ($sock, undef, $len) = @_;
        vec($_[1], ($len + 1) * 8, 1) = 0;
-       vec(my $cmsghdr = '', 256 * 8 - 1, 1) = 1;
+       my $cmsghdr = "\0" x msg_controllen; # 10 * sizeof(int)
        my $iov = pack('P'.TMPL_size_t, $_[1], $len);
        my $mh = pack('PL' . # msg_name, msg_namelen (socklen_t (U32))
                        BYTES_4_hole . # 4-byte padding on 64-bit
@@ -468,7 +466,7 @@ no warnings 'once';
                        @BYTES_4_hole,
                        $iov, 1, # msg_iov, msg_iovlen
                        $cmsghdr, # msg_control
-                       256, # msg_controllen
+                       msg_controllen,
                        0); # msg_flags
        my $r = syscall($SYS_recvmsg, fileno($sock), $mh, 0);
        return (undef) if $r < 0; # $! set