[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/03: Fix possible deadlock in 'scm_sigaction_for_threa
From: |
Ludovic Courtès |
Subject: |
[Guile-commits] 01/03: Fix possible deadlock in 'scm_sigaction_for_thread'. |
Date: |
Sun, 16 Jul 2023 16:06:23 -0400 (EDT) |
civodul pushed a commit to branch main
in repository guile.
commit 85520354a8f5de0366c4ac3eb5403aeb27c9515e
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Jul 16 18:31:57 2023 +0200
Fix possible deadlock in 'scm_sigaction_for_thread'.
Fixes <https://bugs.gnu.org/64666>.
* libguile/scmsigs.c (scm_sigaction_for_thread): Swap the
'scm_dynwind_block_asyncs' and 'scm_i_dynwind_pthread_mutex_lock'
calls.
* NEWS: Update.
---
NEWS | 2 ++
libguile/scmsigs.c | 8 ++++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index f2e00898f..87aefb03f 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,8 @@ the compiler reports it as "possibly unused".
(<https://bugs.gnu.org/62501>)
** Fix 'system*' with non-file input/output/error port
(<https://bugs.gnu.org/63024>)
+** Fix possible deadlock in 'sigaction' (aka. 'scm_sigaction_for_thread')
+ (<https://bugs.gnu.org/64666>)
** Hashing of UTF-8 symbols with non-ASCII characters avoids corruption
(<https://bugs.gnu.org/56413>)
diff --git a/libguile/scmsigs.c b/libguile/scmsigs.c
index 975d2bd18..d137331f5 100644
--- a/libguile/scmsigs.c
+++ b/libguile/scmsigs.c
@@ -1,4 +1,4 @@
-/* Copyright 1995-2002,2004,2006-2009,2011,2013-2014,2017-2018
+/* Copyright 1995-2002,2004,2006-2009,2011,2013-2014,2017-2018,2023
Free Software Foundation, Inc.
This file is part of Guile.
@@ -336,8 +336,12 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
scm_i_ensure_signal_delivery_thread ();
scm_dynwind_begin (0);
- scm_i_dynwind_pthread_mutex_lock (&signal_handler_lock);
+
+ /* Among the pending asyncs, there might be signal handlers that will
+ call this very function. Thus, to avoid deadlocks, block asyncs
+ before grabbing SIGNAL_HANDLER_LOCK. */
scm_dynwind_block_asyncs ();
+ scm_i_dynwind_pthread_mutex_lock (&signal_handler_lock);
old_handler = SCM_SIMPLE_VECTOR_REF (*signal_handlers, csig);
if (SCM_UNBNDP (handler))