]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdbsupport/scoped_ignore_signal.h
gdb: fall back on sigpending + sigwait if sigtimedwait is not available
[thirdparty/binutils-gdb.git] / gdbsupport / scoped_ignore_signal.h
index a14c96779bf214d6a407dc2efcb8e3226c86347b..57dd4b6d4025654ee544353f934145620e2d610d 100644 (file)
@@ -58,7 +58,6 @@ public:
     if (!m_was_blocked)
       {
        sigset_t set;
-       const timespec zero_timeout = {};
 
        sigemptyset (&set);
        sigaddset (&set, Sig);
@@ -66,7 +65,19 @@ public:
        /* If we got a pending Sig signal, consume it before
           unblocking.  */
        if (ConsumePending)
-         sigtimedwait (&set, nullptr, &zero_timeout);
+         {
+#ifdef HAVE_SIGTIMEDWAIT
+           const timespec zero_timeout = {};
+
+           sigtimedwait (&set, nullptr, &zero_timeout);
+#else
+           sigset_t pending;
+
+           sigpending (&pending);
+           if (sigismember (&pending, Sig))
+             sigwait (&set, nullptr);
+#endif
+         }
 
        sigprocmask (SIG_UNBLOCK, &set, nullptr);
       }