]> Sergey Matveev's repositories - public-inbox.git/commitdiff
sigfd: set SIGWINCH for MIPS and PA-RISC on Linux
authorEric Wong <e@80x24.org>
Mon, 17 Oct 2022 09:30:53 +0000 (09:30 +0000)
committerEric Wong <e@80x24.org>
Mon, 17 Oct 2022 22:16:45 +0000 (22:16 +0000)
SIGWINCH is actually different for these architectures on Linux
according to the signal(7) man page.

Note: AFAICS there's no parisc machine in the GCC Farm[1],
so it remains untested.  I've only tested mips64 for mips,
but I expect them to both work.

OpenBSD (on gcc231) octeon defines SIGWINCH as the common `28',
so it appears Linux is the only one with arch-dependent signal
numbers (ditto with syscalls).

[1] https://cfarm.tetaneutral.net/machines/list/

devel/syscall-list
lib/PublicInbox/Sigfd.pm
lib/PublicInbox/Syscall.pm
t/sigfd.t

index adb450da27b829be299efb2fbdaa8aafdf8f3b0d..0b36c0e262f2950f099d471a050f5e45722cceb1 100755 (executable)
@@ -26,6 +26,7 @@ system($cc, '-o', $x, $f, @cflags) == 0 or die "cc failed \$?=$?";
 exec($x);
 __DATA__
 #define _GNU_SOURCE
+#include <signal.h>
 #include <sys/syscall.h>
 #include <sys/ioctl.h>
 #ifdef __linux__
@@ -65,5 +66,6 @@ int main(void)
 #endif /* Linux, any other OSes with stable syscalls? */
        printf("size_t=%zu off_t=%zu pid_t=%zu\n",
                 sizeof(size_t), sizeof(off_t), sizeof(pid_t));
+       D(SIGWINCH);
        return 0;
 }
index 583f9f1416345b502fd4fafbaf7b1350e065c0e1..3d964be36b5c36c350f5d5c5f18af85694b228e0 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Wraps a signalfd (or similar) for PublicInbox::DS
@@ -6,7 +6,7 @@
 package PublicInbox::Sigfd;
 use strict;
 use parent qw(PublicInbox::DS);
-use PublicInbox::Syscall qw(signalfd EPOLLIN EPOLLET);
+use PublicInbox::Syscall qw(signalfd EPOLLIN EPOLLET %SIGNUM);
 use POSIX ();
 
 # returns a coderef to unblock signals if neither signalfd or kqueue
@@ -14,13 +14,8 @@ use POSIX ();
 sub new {
        my ($class, $sig, $nonblock) = @_;
        my %signo = map {;
-               my $cb = $sig->{$_};
-               # SIGWINCH is 28 on FreeBSD, NetBSD, OpenBSD, Darwin
-               my $num = ($_ eq 'WINCH' && $^O =~ /linux|bsd|darwin/i) ? 28 : do {
-                       my $m = "SIG$_";
-                       POSIX->$m;
-               };
-               $num => $cb;
+               # $num => $cb;
+               ($SIGNUM{$_} // POSIX->can("SIG$_")->()) => $sig->{$_}
        } keys %$sig;
        my $self = bless { sig => \%signo }, $class;
        my $io;
index 291e0489ca35cb192d47c36f5c9e77faed497e7a..ee4c61072214bd9143b0e1b3a7b5511cdbd13e30 100644 (file)
@@ -21,13 +21,14 @@ use parent qw(Exporter);
 use POSIX qw(ENOENT ENOSYS EINVAL O_NONBLOCK);
 use Socket qw(SOL_SOCKET SCM_RIGHTS);
 use Config;
+our %SIGNUM = (WINCH => 28); # most Linux, {Free,Net,Open}BSD, *Darwin
 
 # $VERSION = '0.25'; # Sys::Syscall version
 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 rename_noreplace);
+                  signalfd rename_noreplace %SIGNUM);
 our %EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait
                              EPOLLIN EPOLLOUT
                              EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
@@ -159,6 +160,7 @@ if ($^O eq "linux") {
         $SYS_epoll_wait   = 226;
         $u64_mod_8        = 1;
         $SYS_signalfd4 = 309;
+        $SIGNUM{WINCH} = 23;
     } elsif ($machine =~ m/^ppc64/) {
         $SYS_epoll_create = 236;
         $SYS_epoll_ctl    = 237;
@@ -252,6 +254,7 @@ if ($^O eq "linux") {
        $SYS_recvmsg = 4177;
        $FS_IOC_GETFLAGS = 0x40046601;
        $FS_IOC_SETFLAGS = 0x80046602;
+       $SIGNUM{WINCH} = 20;
     } else {
         # as a last resort, try using the *.ph files which may not
         # exist or may be wrong
index a68b12a65f01d8f5b36f0592acb8cf1a128a38cc..7eb6b222819b0363416f659957a97dbdea30438d 100644 (file)
--- a/t/sigfd.t
+++ b/t/sigfd.t
@@ -18,7 +18,8 @@ SKIP: {
        local $SIG{HUP} = sub { $hit->{HUP}->{normal}++ };
        local $SIG{TERM} = sub { $hit->{TERM}->{normal}++ };
        local $SIG{INT} = sub { $hit->{INT}->{normal}++ };
-       for my $s (qw(HUP TERM INT)) {
+       local $SIG{WINCH} = sub { $hit->{WINCH}->{normal}++ };
+       for my $s (qw(HUP TERM INT WINCH)) {
                $sig->{$s} = sub { $hit->{$s}->{sigfd}++ };
        }
        my $sigfd = PublicInbox::Sigfd->new($sig, 0);
@@ -26,6 +27,7 @@ SKIP: {
                ok($sigfd, 'Sigfd->new works');
                kill('HUP', $$) or die "kill $!";
                kill('INT', $$) or die "kill $!";
+               kill('WINCH', $$) or die "kill $!";
                my $fd = fileno($sigfd->{sock});
                ok($fd >= 0, 'fileno(Sigfd->{sock}) works');
                my $rvec = '';
@@ -54,6 +56,7 @@ SKIP: {
                PublicInbox::DS->Reset;
                is($hit->{TERM}->{sigfd}, 1, 'TERM sigfd fired in event loop');
                is($hit->{HUP}->{sigfd}, 3, 'HUP sigfd fired in event loop');
+               is($hit->{WINCH}->{sigfd}, 1, 'WINCH sigfd fired in event loop');
        } else {
                skip('signalfd disabled?', 10);
        }