]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Syscall.pm
ds: simplify signalfd use
[public-inbox.git] / lib / PublicInbox / Syscall.pm
index c403f78ad209eac4c5c89f80c0545b17871e6619..7ab4291119ea4deb84a7fe31ec6ed9e144a84d3d 100644 (file)
@@ -5,7 +5,7 @@
 # This license differs from the rest of public-inbox
 #
 # This module is Copyright (c) 2005 Six Apart, Ltd.
-# Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 #
 # All rights reserved.
 #
@@ -22,7 +22,7 @@ our @EXPORT_OK = qw(epoll_ctl epoll_create epoll_wait
                   EPOLLIN EPOLLOUT EPOLLET
                   EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
                   EPOLLONESHOT EPOLLEXCLUSIVE
-                  signalfd $SFD_NONBLOCK);
+                  signalfd);
 our %EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait
                              EPOLLIN EPOLLOUT
                              EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
@@ -55,7 +55,7 @@ sub _load_syscall {
     $clean->(); # don't trust modules before us
     my $rv = eval { require 'syscall.ph'; 1 } || eval { require 'sys/syscall.ph'; 1 };
     $clean->(); # don't require modules after us trust us
-    return $rv;
+    $rv;
 }
 
 
@@ -67,7 +67,6 @@ our (
      );
 
 my $SFD_CLOEXEC = 02000000; # Perl does not expose O_CLOEXEC
-our $SFD_NONBLOCK = O_NONBLOCK;
 our $no_deprecated = 0;
 
 if ($^O eq "linux") {
@@ -195,21 +194,18 @@ if ($^O eq "linux") {
         *epoll_ctl = \&epoll_ctl_mod4;
     }
 }
-
-elsif ($^O eq "freebsd") {
-    if ($ENV{FREEBSD_SENDFILE}) {
-        # this is still buggy and in development
-    }
-}
+# use Inline::C for *BSD-only or general POSIX stuff.
+# Linux guarantees stable syscall numbering, BSDs only offer a stable libc
+# use scripts/syscall-list on Linux to detect new syscall numbers
 
 ############################################################################
 # epoll functions
 ############################################################################
 
-sub epoll_defined { return $SYS_epoll_create ? 1 : 0; }
+sub epoll_defined { $SYS_epoll_create ? 1 : 0; }
 
 sub epoll_create {
-       syscall($SYS_epoll_create, $no_deprecated ? 0 : ($_[0]||100)+0);
+       syscall($SYS_epoll_create, $no_deprecated ? 0 : 100);
 }
 
 # epoll_ctl wrapper
@@ -224,7 +220,7 @@ sub epoll_ctl_mod8 {
 # epoll_wait wrapper
 # ARGS: (epfd, maxevents, timeout (milliseconds), arrayref)
 #  arrayref: values modified to be [$fd, $event]
-our $epoll_wait_events;
+our $epoll_wait_events = '';
 our $epoll_wait_size = 0;
 sub epoll_wait_mod4 {
        my ($epfd, $maxevents, $timeout_msec, $events) = @_;
@@ -269,14 +265,15 @@ sub epoll_wait_mod8 {
        }
 }
 
-sub signalfd ($$$) {
-       my ($fd, $signos, $flags) = @_;
+sub signalfd ($$) {
+       my ($signos, $nonblock) = @_;
        if ($SYS_signalfd4) {
                my $set = POSIX::SigSet->new(@$signos);
-               syscall($SYS_signalfd4, $fd, "$$set",
+               syscall($SYS_signalfd4, -1, "$$set",
                        # $Config{sig_count} is NSIG, so this is NSIG/8:
                        int($Config{sig_count}/8),
-                       $flags|$SFD_CLOEXEC);
+                       # SFD_NONBLOCK == O_NONBLOCK for every architecture
+                       ($nonblock ? O_NONBLOCK : 0) |$SFD_CLOEXEC);
        } else {
                $! = ENOSYS;
                undef;