aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/scoped_ignore_signal.h18
-rw-r--r--gdbsupport/scoped_ignore_sigttou.h2
2 files changed, 14 insertions, 6 deletions
diff --git a/gdbsupport/scoped_ignore_signal.h b/gdbsupport/scoped_ignore_signal.h
index 55a921c..a14c967 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 @@ public:
/* 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 1fc8f80..5695c5d 100644
--- a/gdbsupport/scoped_ignore_sigttou.h
+++ b/gdbsupport/scoped_ignore_sigttou.h
@@ -75,7 +75,7 @@ public:
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