[binutils-gdb] [gdb] Fix scoped_ignore_sigpipe selftest on Solaris
Tom de Vries
vries@sourceware.org
Wed Dec 2 15:08:26 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cf930396cd27c2c3ef86aacf9b98736a8401edbd
commit cf930396cd27c2c3ef86aacf9b98736a8401edbd
Author: Tom de Vries <tdevries@suse.de>
Date: Wed Dec 2 16:08:21 2026 +0100
[gdb] Fix scoped_ignore_sigpipe selftest on Solaris
On i386-solaris (and likewise sparc-solaris) I run into a failure in selftest
scoped_ignore_sigpipe:
...
$ gdb -q -batch -ex "maint selftest scoped_ignore_sigpipe"
Running selftest scoped_ignore_sigpipe.
$
...
Note that there's no summary as I would have in a passing case:
...
$ gdb -q -batch -ex "maint selftest scoped_ignore_sigpipe"
Running selftest scoped_ignore_sigpipe.
Ran 1 unit tests, 0 failed
$
...
The problem happens here in test_sigpipe:
...
auto *osig = signal (SIGPIPE, handle_sigpipe);
...
check_pipe_write (true);
...
check_pipe_write (true);
...
The first check_pipe_write generates a SIGPIPE. Just before calling the
installed handler handle_sigpipe, the signal disposition is reset to SIG_DFL.
So once the second check_pipe_write generates a SIGPIPE, handle_sigpipe is not
called as expected by the test.
The function signal, that we used to install the signal handler, has
implementation-defined behavior, and on some platforms (like Linux) the signal
disposition remains the same, while on others (like Solaris) it gets reset
back to its default.
Fix this in test_sigpipe by re-installing the signal handler, rather than
assuming it's still installed.
Also check that it's still installed after the lifetime of
scoped_ignore_sigpipe.
It is possible to fix this by using sigaction instead of signal, but sigaction
is not available on all platforms, and maintaining a combined solution with
sigaction as the default and signal as fallback seems overkill for a selftest.
An LLM review comment suggested to use scoped_signal_handler, but if that one
falls back to signal, it has the exact same problem as we're fixing here.
Tested by running the selftests on i386-solaris, sparc-solaris and
x86_64-linux.
Diff:
---
gdb/unittests/scoped_ignore_signal-selftests.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/gdb/unittests/scoped_ignore_signal-selftests.c b/gdb/unittests/scoped_ignore_signal-selftests.c
index 7a0f2c2764f..e8ce59001ac 100644
--- a/gdb/unittests/scoped_ignore_signal-selftests.c
+++ b/gdb/unittests/scoped_ignore_signal-selftests.c
@@ -85,6 +85,14 @@ test_sigpipe ()
a SIGPIPE signal. */
check_pipe_write (true);
+ /* In this test we use signal to install a signal handler. The
+ function has implementation-defined behavior, which on some
+ platforms (like Solaris) means that the kernel resets the signal
+ disposition to SIG_DFL just before executing the signal handler.
+ So don't assume here that handle_sigpipe is still installed as the
+ signal handler for SIGPIPE; install it to be sure. */
+ signal (SIGPIPE, handle_sigpipe);
+
/* Now check that with a scoped_ignore_sigpipe in scope, SIGPIPE is
ignored/blocked. */
{
@@ -104,6 +112,12 @@ test_sigpipe ()
check_pipe_write (false);
}
+ /* Check that scoped_ignore_sigpipe preserved the installed signal handler.
+ If not, throw an error. If so, re-install handle_sigpipe, which is a
+ nop. */
+ sighandler_t current_handler = signal (SIGPIPE, handle_sigpipe);
+ SELF_CHECK (current_handler == handle_sigpipe);
+
/* No scoped_ignore_sigpipe is in scope anymore, so this should
result in a SIGPIPE signal. */
check_pipe_write (true);
More information about the Gdb-cvs
mailing list