unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* SIGWINCH not recognized under macOS
@ 2022-10-15  8:12 Nicolás Ojeda Bär
  2022-10-15  8:12 ` [PATCH] SIGWINCH is 28 on macOS Nicolás Ojeda Bär
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Nicolás Ojeda Bär @ 2022-10-15  8:12 UTC (permalink / raw)
  To: meta

Hello,

I'm trying to use public-inbox on macOS (a BSD derivative).  The logic
hardcoding the signal number for SIGWINCH needs to be extended to handle this
case. There may be other similar changes which are needed, but this is the only
one I've seen so far.

Cheers,
Nicolas



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] SIGWINCH is 28 on macOS
  2022-10-15  8:12 SIGWINCH not recognized under macOS Nicolás Ojeda Bär
@ 2022-10-15  8:12 ` 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
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Nicolás Ojeda Bär @ 2022-10-15  8:12 UTC (permalink / raw)
  To: meta; +Cc: Nicolás Ojeda Bär

---
 lib/PublicInbox/Sigfd.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/Sigfd.pm b/lib/PublicInbox/Sigfd.pm
index 81e5a1b1..cb9ddc1a 100644
--- a/lib/PublicInbox/Sigfd.pm
+++ b/lib/PublicInbox/Sigfd.pm
@@ -15,8 +15,8 @@ sub new {
 	my ($class, $sig, $nonblock) = @_;
 	my %signo = map {;
 		my $cb = $sig->{$_};
-		# SIGWINCH is 28 on FreeBSD, NetBSD, OpenBSD
-		my $num = ($_ eq 'WINCH' && $^O =~ /linux|bsd/i) ? 28 : do {
+		# SIGWINCH is 28 on FreeBSD, NetBSD, OpenBSD, macOS
+		my $num = ($_ eq 'WINCH' && $^O =~ /linux|bsd|darwin/i) ? 28 : do {
 			my $m = "SIG$_";
 			POSIX->$m;
 		};
-- 
2.32.0 (Apple Git-132)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] SIGWINCH is 28 on Darwin-based OSes
  2022-10-15  8:12 ` [PATCH] SIGWINCH is 28 on macOS Nicolás Ojeda Bär
@ 2022-10-17  8:33   ` Eric Wong
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-10-17  8:33 UTC (permalink / raw)
  To: Nicolás Ojeda Bär; +Cc: meta

Thanks.  Pushed as commit 70d2806f623b7d5c8fe8328f8e53a24e7be34393
with slightly edited commit message and comments to avoid
mention of a non-Free platform:

From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= <n.oje.bar@gmail.com>
Date: Sat, 15 Oct 2022 10:12:46 +0200
Subject: [PATCH] SIGWINCH is 28 on Darwin-based OSes

[ew: avoid mention of non-Free platform]

Acked-by: Eric Wong <e@80x24.org>
---
 lib/PublicInbox/Sigfd.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/Sigfd.pm b/lib/PublicInbox/Sigfd.pm
index 81e5a1b1..583f9f14 100644
--- a/lib/PublicInbox/Sigfd.pm
+++ b/lib/PublicInbox/Sigfd.pm
@@ -15,8 +15,8 @@ sub new {
 	my ($class, $sig, $nonblock) = @_;
 	my %signo = map {;
 		my $cb = $sig->{$_};
-		# SIGWINCH is 28 on FreeBSD, NetBSD, OpenBSD
-		my $num = ($_ eq 'WINCH' && $^O =~ /linux|bsd/i) ? 28 : do {
+		# SIGWINCH is 28 on FreeBSD, NetBSD, OpenBSD, Darwin
+		my $num = ($_ eq 'WINCH' && $^O =~ /linux|bsd|darwin/i) ? 28 : do {
 			my $m = "SIG$_";
 			POSIX->$m;
 		};

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 0/2] fix SIGWINCH for Linux MIPS and PA-RISC
  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  9:30 ` 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 ` [PATCH 2/2] sigfd: set SIGWINCH for MIPS and PA-RISC on Linux Eric Wong
  3 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-10-17  9:30 UTC (permalink / raw)
  To: Nicolás Ojeda Bär; +Cc: meta

Nicolás Ojeda Bär wrote:
> The logic
> hardcoding the signal number for SIGWINCH needs to be extended to handle this
> case. There may be other similar changes which are needed, but this is the only
> one I've seen so far.

Yeah, apparently two Linux architectures use n != 28 as SIGWINCH;
but *BSDs are more consistent with SIGWINCH.

1/2 was part of some ongoing unrelated work, but it's in the same area
and ready-to-go, anyways.

Eric Wong (2):
  syscall: avoid needless string comparison on x86-64
  sigfd: set SIGWINCH for MIPS and PA-RISC on Linux

 devel/syscall-list         |  2 ++
 lib/PublicInbox/Sigfd.pm   | 13 ++++---------
 lib/PublicInbox/Syscall.pm | 22 ++++++++++++----------
 t/sigfd.t                  |  5 ++++-
 4 files changed, 22 insertions(+), 20 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] syscall: avoid needless string comparison on x86-64
  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  9:30 ` [PATCH 0/2] fix SIGWINCH for Linux MIPS and PA-RISC Eric Wong
@ 2022-10-17  9:30 ` Eric Wong
  2022-10-17  9:30 ` [PATCH 2/2] sigfd: set SIGWINCH for MIPS and PA-RISC on Linux Eric Wong
  3 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-10-17  9:30 UTC (permalink / raw)
  To: Nicolás Ojeda Bär; +Cc: meta

For common x86-64 systems, we can avoid a needless
string comparison on `mips64' by restructuring the
branches for architecture detection.
---
 lib/PublicInbox/Syscall.pm | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index 412ca64f..291e0489 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -97,15 +97,14 @@ if ($^O eq "linux") {
     # boundaries.
     my $u64_mod_8 = 0;
 
-    # if we're running on an x86_64 kernel, but a 32-bit process,
-    # we need to use the x32 or i386 syscall numbers.
-    if ($machine eq "x86_64" && $Config{ptrsize} == 4) {
-        $machine = $Config{cppsymbols} =~ /\b__ILP32__=1\b/ ? 'x32' : 'i386';
-    }
-
-    # Similarly for mips64 vs mips
-    if ($machine eq "mips64" && $Config{ptrsize} == 4) {
-        $machine = "mips";
+    if ($Config{ptrsize} == 4) {
+	# if we're running on an x86_64 kernel, but a 32-bit process,
+	# we need to use the x32 or i386 syscall numbers.
+	if ($machine eq 'x86_64') {
+	    $machine = $Config{cppsymbols} =~ /\b__ILP32__=1\b/ ? 'x32' : 'i386'
+	} elsif ($machine eq 'mips64') { # similarly for mips64 vs mips
+	    $machine = 'mips';
+	}
     }
 
     if ($machine =~ m/^i[3456]86$/) {

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] sigfd: set SIGWINCH for MIPS and PA-RISC on Linux
  2022-10-15  8:12 SIGWINCH not recognized under macOS Nicolás Ojeda Bär
                   ` (2 preceding siblings ...)
  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
  3 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2022-10-17  9:30 UTC (permalink / raw)
  To: Nicolás Ojeda Bär; +Cc: meta

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);
 	}

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-17  9:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] sigfd: set SIGWINCH for MIPS and PA-RISC on Linux Eric Wong

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).