From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0433A20082 for ; Thu, 31 Dec 2020 13:51:58 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 32/36] syscall: SFD_NONBLOCK can be a constant, again Date: Thu, 31 Dec 2020 13:51:50 +0000 Message-Id: <20201231135154.6070-33-e@80x24.org> In-Reply-To: <20201231135154.6070-1-e@80x24.org> References: <20201231135154.6070-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Since Perl exposes O_NONBLOCK as a constant, we can safely make SFD_NONBLOCK a constant, too. This is not the case for SFD_CLOEXEC, since O_CLOEXEC is not exposed by Perl despite being used internally in the interpreter. --- lib/PublicInbox/DSKQXS.pm | 4 ++-- lib/PublicInbox/Daemon.pm | 4 ++-- lib/PublicInbox/LEI.pm | 4 ++-- lib/PublicInbox/Sigfd.pm | 4 ++-- lib/PublicInbox/Syscall.pm | 4 ++-- script/public-inbox-watch | 4 ++-- t/sigfd.t | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/PublicInbox/DSKQXS.pm b/lib/PublicInbox/DSKQXS.pm index aa2c9168..9a37e4ce 100644 --- a/lib/PublicInbox/DSKQXS.pm +++ b/lib/PublicInbox/DSKQXS.pm @@ -18,7 +18,7 @@ use Symbol qw(gensym); use IO::KQueue; use Errno qw(EAGAIN); use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT EPOLLET - EPOLL_CTL_ADD EPOLL_CTL_MOD EPOLL_CTL_DEL $SFD_NONBLOCK); + EPOLL_CTL_ADD EPOLL_CTL_MOD EPOLL_CTL_DEL SFD_NONBLOCK); our @EXPORT_OK = qw(epoll_ctl epoll_wait); sub EV_DISPATCH () { 0x0080 } @@ -57,7 +57,7 @@ sub signalfd { sub TIEHANDLE { # similar to signalfd() my ($class, $signo, $flags) = @_; my $self = $class->new; - $self->{timeout} = ($flags & $SFD_NONBLOCK) ? 0 : -1; + $self->{timeout} = ($flags & SFD_NONBLOCK) ? 0 : -1; my $kq = $self->{kq}; $kq->EV_SET($_, EVFILT_SIGNAL, EV_ADD) for @$signo; $self; diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index bdf1dc45..f68337a0 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -16,7 +16,7 @@ sub SO_ACCEPTFILTER () { 0x1000 } STDOUT->autoflush(1); STDERR->autoflush(1); use PublicInbox::DS qw(now); -use PublicInbox::Syscall qw($SFD_NONBLOCK); +use PublicInbox::Syscall qw(SFD_NONBLOCK); require PublicInbox::Listener; use PublicInbox::EOFpipe; use PublicInbox::Sigfd; @@ -627,7 +627,7 @@ sub daemon_loop ($$$$) { # this calls epoll_create: PublicInbox::Listener->new($_, $tls_cb || $post_accept) } @listeners; - my $sigfd = PublicInbox::Sigfd->new($sig, $SFD_NONBLOCK); + my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK); local %SIG = (%SIG, %$sig) if !$sigfd; if (!$sigfd) { # wake up every second to accept signals if we don't diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 7b7f45de..03302f8a 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -16,7 +16,7 @@ use POSIX (); use IO::Handle (); use Sys::Syslog qw(syslog openlog); use PublicInbox::Config; -use PublicInbox::Syscall qw($SFD_NONBLOCK EPOLLIN EPOLLONESHOT); +use PublicInbox::Syscall qw(SFD_NONBLOCK EPOLLIN EPOLLONESHOT); use PublicInbox::Sigfd; use PublicInbox::DS qw(now dwaitpid); use PublicInbox::Spawn qw(spawn run_die); @@ -704,7 +704,7 @@ sub lazy_start { USR1 => \&noop, USR2 => \&noop, }; - my $sigfd = PublicInbox::Sigfd->new($sig, $SFD_NONBLOCK); + my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK); local %SIG = (%SIG, %$sig) if !$sigfd; if ($sigfd) { # TODO: use inotify/kqueue to detect unlinked sockets PublicInbox::DS->SetLoopTimeout(5000); diff --git a/lib/PublicInbox/Sigfd.pm b/lib/PublicInbox/Sigfd.pm index 5d61e630..bf91bb37 100644 --- a/lib/PublicInbox/Sigfd.pm +++ b/lib/PublicInbox/Sigfd.pm @@ -6,7 +6,7 @@ package PublicInbox::Sigfd; use strict; use parent qw(PublicInbox::DS); -use PublicInbox::Syscall qw(signalfd EPOLLIN EPOLLET $SFD_NONBLOCK); +use PublicInbox::Syscall qw(signalfd EPOLLIN EPOLLET SFD_NONBLOCK); use POSIX qw(:signal_h); use IO::Handle (); @@ -33,7 +33,7 @@ sub new { } else { return; # wake up every second to check for signals } - if ($flags & $SFD_NONBLOCK) { # it can go into the event loop + if ($flags & SFD_NONBLOCK) { # it can go into the event loop $self->SUPER::new($io, EPOLLIN | EPOLLET); } else { # master main loop $self->{sock} = $io; diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm index c403f78a..180ee2cc 100644 --- a/lib/PublicInbox/Syscall.pm +++ b/lib/PublicInbox/Syscall.pm @@ -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 SFD_NONBLOCK); our %EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait EPOLLIN EPOLLOUT EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD @@ -67,7 +67,7 @@ our ( ); my $SFD_CLOEXEC = 02000000; # Perl does not expose O_CLOEXEC -our $SFD_NONBLOCK = O_NONBLOCK; +sub SFD_NONBLOCK () { O_NONBLOCK } our $no_deprecated = 0; if ($^O eq "linux") { diff --git a/script/public-inbox-watch b/script/public-inbox-watch index 55183ef2..4fd6ad49 100755 --- a/script/public-inbox-watch +++ b/script/public-inbox-watch @@ -14,7 +14,7 @@ use PublicInbox::Watch; use PublicInbox::Config; use PublicInbox::DS; use PublicInbox::Sigfd; -use PublicInbox::Syscall qw($SFD_NONBLOCK); +use PublicInbox::Syscall qw(SFD_NONBLOCK); my $do_scan = 1; GetOptions('scan!' => \$do_scan, # undocumented, testing only 'help|h' => \(my $show_help)) or do { print STDERR $help; exit 1 }; @@ -57,7 +57,7 @@ if ($watch) { # --no-scan is only intended for testing atm, undocumented. PublicInbox::DS::requeue($scan) if $do_scan; - my $sigfd = PublicInbox::Sigfd->new($sig, $SFD_NONBLOCK); + my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK); local %SIG = (%SIG, %$sig) if !$sigfd; if (!$sigfd) { PublicInbox::Sigfd::sig_setmask($oldset); diff --git a/t/sigfd.t b/t/sigfd.t index 8daf3137..07120b64 100644 --- a/t/sigfd.t +++ b/t/sigfd.t @@ -4,7 +4,7 @@ use Test::More; use IO::Handle; use POSIX qw(:signal_h); use Errno qw(ENOSYS); -use PublicInbox::Syscall qw($SFD_NONBLOCK); +use PublicInbox::Syscall qw(SFD_NONBLOCK); require_ok 'PublicInbox::Sigfd'; SKIP: { @@ -42,8 +42,8 @@ SKIP: { } $sigfd = undef; - my $nbsig = PublicInbox::Sigfd->new($sig, $SFD_NONBLOCK); - ok($nbsig, 'Sigfd->new $SFD_NONBLOCK works'); + my $nbsig = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK); + ok($nbsig, 'Sigfd->new SFD_NONBLOCK works'); is($nbsig->wait_once, undef, 'nonblocking ->wait_once'); ok($! == Errno::EAGAIN, 'got EAGAIN'); kill('HUP', $$) or die "kill $!";