Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: John Baldwin <jhb@FreeBSD.org>, gdb-patches@sourceware.org
Subject: Re: [PATCH 0/4] Introduce scoped_ignore_signal & make it thread safe
Date: Thu, 17 Jun 2021 16:36:57 +0100	[thread overview]
Message-ID: <18c7433b-464d-b274-88a2-5495aab407ba@palves.net> (raw)
In-Reply-To: <7f678d4a-b015-655f-f79a-36daccab5062@palves.net>

On 2021-06-17 3:38 p.m., Pedro Alves wrote:
> On 2021-06-15 6:04 p.m., John Baldwin wrote:

> If SIGTTOU ends up raised by some other thread while the main thread has it blocked
> in scoped_ignore_sigttou, and if it is sent to the whole process, there's a small time window
> where the sigtimedwait in the main thread can eat the signal.  That still seems better than
> the current status where the end result can be that we can end up with the signal enabled
> instead of ignored and then gdb backgrounds itself.  This is of course highly theoretical since I
> expect that gdb threads run with signals blocked from the get go.  But you never know what
> Python code does.
> 

Hmm, I just thought of an easy fix for that.  Just don't consume the pending
signal in SIGTTOU's case.  I wonder how portable is this?  WDYT?

I'll see if I can try this on Solaris.

From 7f9288f1c3c4f184ebc08dd56406de0c13f5246a Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Thu, 17 Jun 2021 16:23:03 +0100
Subject: [PATCH] No sigtimedwait for SIGTTOU

Change-Id: I92f754dbc45c45819dce2ce68b8c067d8d5c61b1
---
 gdbsupport/scoped_ignore_signal.h  | 18 +++++++++++++-----
 gdbsupport/scoped_ignore_sigttou.h |  2 +-
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/gdbsupport/scoped_ignore_signal.h b/gdbsupport/scoped_ignore_signal.h
index 55a921cb332..a14c96779bf 100644
--- a/gdbsupport/scoped_ignore_signal.h
+++ b/gdbsupport/scoped_ignore_signal.h
@@ -25,9 +25,16 @@
 /* RAII class used to ignore a signal in a scope.  If sigprocmask is
    supported, then the signal is only ignored by the calling thread.
    Otherwise, the signal disposition is set to SIG_IGN, which affects
-   the whole process.  */
-
-template <int Sig>
+   the whole process.  If ConsumePending is true, the destructor
+   consumes a pending Sig.  SIGPIPE for example is queued on the
+   thread even if blocked at the time the pipe is written to.  SIGTTOU
+   OTOH is not raised at all if the thread writing to the terminal has
+   it blocked.  Because SIGTTOU is sent to the whole process instead
+   of to a specific thread, consuming a pending SIGTTOU in the
+   destructor could consume a signal raised due to actions done by
+   some other thread.  */
+
+template <int Sig, bool ConsumePending>
 class scoped_ignore_signal
 {
 public:
@@ -58,7 +65,8 @@ class scoped_ignore_signal
 
 	/* If we got a pending Sig signal, consume it before
 	   unblocking.  */
-	sigtimedwait (&set, nullptr, &zero_timeout);
+	if (ConsumePending)
+	  sigtimedwait (&set, nullptr, &zero_timeout);
 
 	sigprocmask (SIG_UNBLOCK, &set, nullptr);
       }
@@ -89,7 +97,7 @@ struct scoped_ignore_signal_nop
 };
 
 #ifdef SIGPIPE
-using scoped_ignore_sigpipe = scoped_ignore_signal<SIGPIPE>;
+using scoped_ignore_sigpipe = scoped_ignore_signal<SIGPIPE, true>;
 #else
 using scoped_ignore_sigpipe = scoped_ignore_signal_nop;
 #endif
diff --git a/gdbsupport/scoped_ignore_sigttou.h b/gdbsupport/scoped_ignore_sigttou.h
index 1fc8f80d7fd..5695c5db905 100644
--- a/gdbsupport/scoped_ignore_sigttou.h
+++ b/gdbsupport/scoped_ignore_sigttou.h
@@ -75,7 +75,7 @@ class scoped_ignore_sigttou
   DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou);
 
 private:
-  lazy_init<scoped_ignore_signal<SIGTTOU>> m_ignore_signal;
+  lazy_init<scoped_ignore_signal<SIGTTOU, false>> m_ignore_signal;
 };
 
 #else

base-commit: 2af6d46fd331b8e632bb9245614bad0c974392a4
-- 
2.26.2


  reply	other threads:[~2021-06-17 16:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15 11:14 Pedro Alves
2021-06-15 11:14 ` [PATCH 1/4] Move scoped_ignore_sigttou to gdbsupport/ Pedro Alves
2021-06-15 11:14 ` [PATCH 2/4] Introduce scoped_restore_signal Pedro Alves
2021-06-17 14:57   ` Pedro Alves
2021-06-15 11:14 ` [PATCH 3/4] scoped_ignore_signal: Use sigprocmask+sigtimedwait instead of signal Pedro Alves
2021-06-26 12:35   ` Simon Marchi via Gdb-patches
2021-06-26 13:41     ` John Baldwin
2021-06-26 19:10       ` Simon Marchi via Gdb-patches
2021-06-27 14:55       ` Pedro Alves
2021-06-27 19:01         ` Simon Marchi via Gdb-patches
2021-06-15 11:14 ` [PATCH 4/4] Add a unit test for scoped_ignore_sigpipe Pedro Alves
2021-06-15 22:26   ` Lancelot SIX via Gdb-patches
2021-06-17 13:00     ` Pedro Alves
2021-06-15 17:04 ` [PATCH 0/4] Introduce scoped_ignore_signal & make it thread safe John Baldwin
2021-06-17 14:38   ` Pedro Alves
2021-06-17 15:36     ` Pedro Alves [this message]
2021-06-17 16:45       ` John Baldwin
2021-06-17 18:44         ` [pushed] Don't call sigtimedwait for scoped_ignore_sigttou Pedro Alves
2021-06-15 20:16 ` [PATCH 0/4] Introduce scoped_ignore_signal & make it thread safe Tom Tromey

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

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

  git send-email \
    --in-reply-to=18c7433b-464d-b274-88a2-5495aab407ba@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    /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