unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: "Nicolás Ojeda Bär" <n.oje.bar@gmail.com>
Cc: meta@public-inbox.org
Subject: [PATCH 2/2] sigfd: set SIGWINCH for MIPS and PA-RISC on Linux
Date: Mon, 17 Oct 2022 09:30:53 +0000	[thread overview]
Message-ID: <20221017093053.1517046-3-e@80x24.org> (raw)
In-Reply-To: <20221015081246.18167-1-n.oje.bar@gmail.com>

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 syscall
numbers.

[1] https://cfarm.tetaneutral.net/machines/list/
---
 devel/syscall-list         |  2 ++
 lib/PublicInbox/Sigfd.pm   | 13 ++++---------
 lib/PublicInbox/Syscall.pm |  5 ++++-
 t/sigfd.t                  |  5 ++++-
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/devel/syscall-list b/devel/syscall-list
index adb450da..0b36c0e2 100755
--- a/devel/syscall-list
+++ b/devel/syscall-list
@@ -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;
 }
diff --git a/lib/PublicInbox/Sigfd.pm b/lib/PublicInbox/Sigfd.pm
index 583f9f14..3d964be3 100644
--- a/lib/PublicInbox/Sigfd.pm
+++ b/lib/PublicInbox/Sigfd.pm
@@ -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;
diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index 291e0489..ee4c6107 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -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
diff --git a/t/sigfd.t b/t/sigfd.t
index a68b12a6..7eb6b222 100644
--- 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);
 	}

      parent reply	other threads:[~2022-10-17  9:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-15  8:12 SIGWINCH not recognized under macOS Nicolás Ojeda Bär
2022-10-15  8:12 ` [PATCH] SIGWINCH is 28 on macOS Nicolás Ojeda Bär
2022-10-17  8:33   ` [PATCH] SIGWINCH is 28 on Darwin-based OSes Eric Wong
2022-10-17  9:30 ` [PATCH 0/2] fix SIGWINCH for Linux MIPS and PA-RISC Eric Wong
2022-10-17  9:30 ` [PATCH 1/2] syscall: avoid needless string comparison on x86-64 Eric Wong
2022-10-17  9:30 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221017093053.1517046-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --cc=n.oje.bar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).