public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix scoped_ignore_sigpipe selftest on systems with BSD signal semantics
@ 2021-06-17 18:55 Pedro Alves
  2021-06-17 21:05 ` John Baldwin
  2021-06-22 13:49 ` [PATCH] Fix scoped_ignore_sigpipe selftest on systems with BSD " Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Pedro Alves @ 2021-06-17 18:55 UTC (permalink / raw)
  To: gdb-patches

The new "maint selftest scoped_ignore_sigpipe" unit test currently
fails on Solaris, and probably on all BSDs.  The problem is that the
test registers a SIGPIPE signal handler, and doesn't account for BSD
semantics where we need to rearm the signal disposition every time the
signal handler is called.  The result is that GDB dies from SIGPIPE
because the test triggers a SIGPIPE more than once:

 $ gdb -q -ex "maint selftest scoped_ignore_sigpipe"
 Running selftest scoped_ignore_sigpipe.
 $
 (gdb exited due to SIGPIPE)

Fix this by using sigaction.  I'm not adding the usual #ifdef
HAVE_SIGACTION goo, because I really want to believe that all systems
that support SIGPIPE support sigaction nowadays.  GNU/Linux, Hurd,
BSDs, macOS, Cygwin, DJGPP, AIX, etc., anything resembling a modern
Unix does support it AFAIK, only mingw does not support it, but OTOH,
it also doesn't define SIGPIPE.  Confirmed by cross building GDB for
mingw-w64.

We could probably remove the HAVE_SIGPROCMASK check too, actually.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>

	* unittests/scoped_ignore_signal-selftests.c (test_sigpipe): Use
	sigaction instead of signal to avoid BSD signal semantics.

Change-Id: I08aa6be097e1140efdb4cc63e95a845595ce4069
---
 gdb/unittests/scoped_ignore_signal-selftests.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/gdb/unittests/scoped_ignore_signal-selftests.c b/gdb/unittests/scoped_ignore_signal-selftests.c
index 29826e325dc..5927d566552 100644
--- a/gdb/unittests/scoped_ignore_signal-selftests.c
+++ b/gdb/unittests/scoped_ignore_signal-selftests.c
@@ -45,8 +45,14 @@ handle_sigpipe (int)
 static void
 test_sigpipe ()
 {
-  auto *osig = signal (SIGPIPE, handle_sigpipe);
-  SCOPE_EXIT { signal (SIGPIPE, osig); };
+  struct sigaction new_action, old_action;
+
+  new_action.sa_handler = handle_sigpipe;
+  sigemptyset (&new_action.sa_mask);
+  new_action.sa_flags = 0;
+
+  sigaction (SIGPIPE, &new_action, &old_action);
+  SCOPE_EXIT { sigaction (SIGPIPE, &old_action, nullptr); };
 
 #ifdef HAVE_SIGPROCMASK
   /* Make sure SIGPIPE isn't blocked.  */

base-commit: 336b30e58ae98fe66862ab8480d3f7bb885fef23
-- 
2.26.2


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

end of thread, other threads:[~2021-06-22 19:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 18:55 [PATCH] Fix scoped_ignore_sigpipe selftest on systems with BSD signal semantics Pedro Alves
2021-06-17 21:05 ` John Baldwin
2021-06-17 21:23   ` [pushed] Fix scoped_ignore_sigpipe selftest on systems with SysV " Pedro Alves
2021-06-22 13:49 ` [PATCH] Fix scoped_ignore_sigpipe selftest on systems with BSD " Tom Tromey
2021-06-22 19:00   ` Pedro Alves

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