Here are three patches, to revamp the 'pthread_sigmask' module.
0001: The test-pthread_sigmask1 test currently does not fail on NetBSD.
0002: A configure test meant for mingw happened to trigger also on NetBSD,
which was not intended.
0003: Define PTHREAD_SIGMASK_LIB to empty, except on AIX.
2026-04-04 Bruno Haible <[email protected]>
pthread_sigmask: Make it usable without -lpthread on most platforms.
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Define
PTHREAD_SIGMASK_LIB to empty, except on AIX. Define
PTHREAD_SIGMASK_NOT_IN_LIBC if a workaround is needed.
* lib/pthread_sigmask.c (pthread_sigmask): If
PTHREAD_SIGMASK_NOT_IN_LIBC, just use sigprocmask.
* doc/posix-functions/pthread_sigmask.texi: Mention the dropped link
requirement. Mention that the NetBSD 9 bug is fixed.
* doc/posix-functions/sigprocmask.texi: Update note relating to
pthread_sigmask.
pthread_sigmask: Don't force an override on NetBSD.
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Limit the macro test
to native Windows.
pthread_sigmask tests: Enable all tests on NetBSD.
* modules/pthread_sigmask-tests (Depends-on): Remove test-xfail.
(Makefile.am): Don't test OS_IS_NETBSD.
>From 184fc35f61e8654941c5047441ed6b8f8b8312db Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 4 Apr 2026 15:16:17 +0200
Subject: [PATCH 1/3] pthread_sigmask tests: Enable all tests on NetBSD.
* modules/pthread_sigmask-tests (Depends-on): Remove test-xfail.
(Makefile.am): Don't test OS_IS_NETBSD.
---
ChangeLog | 6 ++++++
modules/pthread_sigmask-tests | 4 ----
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3b44833968..cff444eb97 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-04-04 Bruno Haible <[email protected]>
+
+ pthread_sigmask tests: Enable all tests on NetBSD.
+ * modules/pthread_sigmask-tests (Depends-on): Remove test-xfail.
+ (Makefile.am): Don't test OS_IS_NETBSD.
+
2026-04-03 Paul Eggert <[email protected]>
sigprocmask: document race bugs on macOS
diff --git a/modules/pthread_sigmask-tests b/modules/pthread_sigmask-tests
index 6083680da4..9329074462 100644
--- a/modules/pthread_sigmask-tests
+++ b/modules/pthread_sigmask-tests
@@ -9,17 +9,13 @@ Depends-on:
inttypes-h
sleep
pthread-thread
-test-xfail
streq
memeq
configure.ac:
Makefile.am:
-# Work around https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57214
-if !OS_IS_NETBSD
TESTS += test-pthread_sigmask1
-endif
TESTS += test-pthread_sigmask2
check_PROGRAMS += test-pthread_sigmask1 test-pthread_sigmask2
test_pthread_sigmask1_LDADD = $(LDADD) @PTHREAD_SIGMASK_LIB@
--
2.52.0
>From ddbb855607988a024c3f9bc4346d1898687e679d Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 4 Apr 2026 15:16:31 +0200
Subject: [PATCH 2/3] pthread_sigmask: Don't force an override on NetBSD.
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Limit the macro test
to native Windows.
---
ChangeLog | 4 ++++
m4/pthread_sigmask.m4 | 4 ++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cff444eb97..552cb084d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2026-04-04 Bruno Haible <[email protected]>
+ pthread_sigmask: Don't force an override on NetBSD.
+ * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Limit the macro test
+ to native Windows.
+
pthread_sigmask tests: Enable all tests on NetBSD.
* modules/pthread_sigmask-tests (Depends-on): Remove test-xfail.
(Makefile.am): Don't test OS_IS_NETBSD.
diff --git a/m4/pthread_sigmask.m4 b/m4/pthread_sigmask.m4
index 2984dcdcb4..c813d109ef 100644
--- a/m4/pthread_sigmask.m4
+++ b/m4/pthread_sigmask.m4
@@ -1,5 +1,5 @@
# pthread_sigmask.m4
-# serial 24
+# serial 25
dnl Copyright (C) 2011-2026 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -19,7 +19,7 @@ AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK]
[AC_EGREP_CPP([headers_define_pthread_sigmask], [
#include <pthread.h>
#include <signal.h>
-#ifdef pthread_sigmask
+#if defined _WIN32 && defined pthread_sigmask
headers_define_pthread_sigmask
#endif],
[gl_cv_func_pthread_sigmask_macro=yes],
--
2.52.0
From ef8da50e2261d914d66d6c05dc1fe04d561d0d12 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 4 Apr 2026 15:16:44 +0200
Subject: [PATCH 3/3] pthread_sigmask: Make it usable without -lpthread on most
platforms.
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Define
PTHREAD_SIGMASK_LIB to empty, except on AIX. Define
PTHREAD_SIGMASK_NOT_IN_LIBC if a workaround is needed.
* lib/pthread_sigmask.c (pthread_sigmask): If
PTHREAD_SIGMASK_NOT_IN_LIBC, just use sigprocmask.
* doc/posix-functions/pthread_sigmask.texi: Mention the dropped link
requirement. Mention that the NetBSD 9 bug is fixed.
* doc/posix-functions/sigprocmask.texi: Update note relating to
pthread_sigmask.
---
ChangeLog | 11 +++++++++++
doc/posix-functions/pthread_sigmask.texi | 12 +++++++-----
doc/posix-functions/sigprocmask.texi | 2 +-
lib/pthread_sigmask.c | 2 +-
m4/pthread_sigmask.m4 | 25 +++++++++++++++++++++++-
5 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 552cb084d1..43413f2fc9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2026-04-04 Bruno Haible <[email protected]>
+ pthread_sigmask: Make it usable without -lpthread on most platforms.
+ * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Define
+ PTHREAD_SIGMASK_LIB to empty, except on AIX. Define
+ PTHREAD_SIGMASK_NOT_IN_LIBC if a workaround is needed.
+ * lib/pthread_sigmask.c (pthread_sigmask): If
+ PTHREAD_SIGMASK_NOT_IN_LIBC, just use sigprocmask.
+ * doc/posix-functions/pthread_sigmask.texi: Mention the dropped link
+ requirement. Mention that the NetBSD 9 bug is fixed.
+ * doc/posix-functions/sigprocmask.texi: Update note relating to
+ pthread_sigmask.
+
pthread_sigmask: Don't force an override on NetBSD.
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Limit the macro test
to native Windows.
diff --git a/doc/posix-functions/pthread_sigmask.texi b/doc/posix-functions/pthread_sigmask.texi
index 74f3ab909b..8772168d0a 100644
--- a/doc/posix-functions/pthread_sigmask.texi
+++ b/doc/posix-functions/pthread_sigmask.texi
@@ -17,13 +17,19 @@
on some platforms:
FreeBSD 6.4, OpenBSD 3.8.
@item
+This function requires compiling with @code{-pthread} and/or
+linking with @code{-lpthread} on some platforms:
+glibc 2.31, NetBSD, OpenBSD 5.8.
+@item
This function does nothing and always returns 0 in programs that are not
linked with @code{-lpthread} on some platforms:
FreeBSD 14.0, MidnightBSD 1.1, HP-UX 11.31, Solaris 9.
@item
When it fails, this function returns @minus{}1 instead of the error number on
some platforms:
-Cygwin 1.7.5.
+Cygwin 1.7.5,
+@c https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57214
+NetBSD 9.3 when libpthread is not in use.
@end itemize
Portability problems not fixed by Gnulib:
@@ -31,8 +37,4 @@
@item
On platforms that do not natively support this function,
it has unspecified behavior in a multi-threaded process.
-@item
-In case of failure, the return value is wrong on some platforms:
-@c https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57214
-NetBSD 9.3 when libpthread is not in use.
@end itemize
diff --git a/doc/posix-functions/sigprocmask.texi b/doc/posix-functions/sigprocmask.texi
index e4f9469c6b..165baa5580 100644
--- a/doc/posix-functions/sigprocmask.texi
+++ b/doc/posix-functions/sigprocmask.texi
@@ -36,7 +36,7 @@
Note: In single-threaded applications it's simpler to use
@code{sigprocmask}, since it does not require compiling with
@code{-pthread} and/or linking with @code{-lpthread} on some platforms:
-glibc 2.31, NetBSD, OpenBSD, AIX.
+AIX.
Note: While on POSIX platforms, @code{sigprocmask} is multithread-safe
and async-signal-safe (see
diff --git a/lib/pthread_sigmask.c b/lib/pthread_sigmask.c
index 95600d6098..5d40fc7b1a 100644
--- a/lib/pthread_sigmask.c
+++ b/lib/pthread_sigmask.c
@@ -30,7 +30,7 @@ int
pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask)
#undef pthread_sigmask
{
-#if HAVE_PTHREAD_SIGMASK
+#if HAVE_PTHREAD_SIGMASK && !PTHREAD_SIGMASK_NOT_IN_LIBC
# if PTHREAD_SIGMASK_INEFFECTIVE
sigset_t omask;
sigset_t *old_mask_ptr = &omask;
diff --git a/m4/pthread_sigmask.m4 b/m4/pthread_sigmask.m4
index c813d109ef..0fd0a74010 100644
--- a/m4/pthread_sigmask.m4
+++ b/m4/pthread_sigmask.m4
@@ -1,5 +1,5 @@
# pthread_sigmask.m4
-# serial 25
+# serial 26
dnl Copyright (C) 2011-2026 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -103,6 +103,27 @@ AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK]
])
fi
+ dnl We want to be able to use pthread_sigmask as a multithread-safe
+ dnl replacement of sigprocmask, in both single-threaded and multithreaded
+ dnl programs. Therefore enforce PTHREAD_SIGMASK_LIB to be empty, whenever
+ dnl possible.
+ if test -n "$PTHREAD_SIGMASK_LIB"; then
+ dnl We get here on glibc ??? 2.31, NetBSD, OpenBSD ??? 5.8, AIX.
+ dnl Except on AIX, pthread_sigmask and sigprocmask are equivalent.
+ dnl Whereas on AIX, sigprocmask is not allowed in multithreaded programs
+ dnl <https://www.ibm.com/docs/en/aix/7.2.0?topic=s-sigprocmask-sigsetmask-sigblock-subroutine>.
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ case "$host_os" in
+ aix*) ;;
+ *)
+ REPLACE_PTHREAD_SIGMASK=1
+ AC_DEFINE([PTHREAD_SIGMASK_NOT_IN_LIBC], [1],
+ [Define to 1 if pthread_sigmask requires linking with some library.])
+ PTHREAD_SIGMASK_LIB=
+ ;;
+ esac
+ fi
+
AC_SUBST([PTHREAD_SIGMASK_LIB])
dnl For backward compatibility.
LIB_PTHREAD_SIGMASK="$PTHREAD_SIGMASK_LIB"
@@ -163,6 +184,8 @@ AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK]
dnl On Cygwin 1.7.5, the pthread_sigmask() has a wrong return value
dnl convention: Upon failure, it returns -1 and sets errno.
+ dnl Likewise on NetBSD 9.3, when libpthread is not in use; see
+ dnl https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57214 .
AC_CACHE_CHECK([whether pthread_sigmask returns error numbers],
[gl_cv_func_pthread_sigmask_return_works],
[
--
2.52.0