emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master ad63bdf05a: Fix xwidgets setting their own signal handlers


From: Po Lu
Subject: master ad63bdf05a: Fix xwidgets setting their own signal handlers
Date: Tue, 4 Jan 2022 21:41:20 -0500 (EST)

branch: master
commit ad63bdf05aa4a0e66139c24fbac8b08b22fc4542
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Fix xwidgets setting their own signal handlers
    
    * src/xgselect.c (release_select_lock):
    (acquire_select_lock): Fix coding style.
    (xg_select): Call `catch_child_signal' if xwidgets are enabled.
    
    * src/xwidget.c (kill_xwidget):
    (kill_buffer_xwidgets): Call `catch_child_signal'.  (bug#53013)
---
 src/xgselect.c | 22 ++++++++++++++++++++--
 src/xwidget.c  |  4 ++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/xgselect.c b/src/xgselect.c
index 8afd3f238f..674c259db7 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -28,11 +28,13 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "lisp.h"
 #include "blockinput.h"
 #include "systime.h"
+#include "process.h"
 
 static ptrdiff_t threads_holding_glib_lock;
 static GMainContext *glib_main_context;
 
-void release_select_lock (void)
+void
+release_select_lock (void)
 {
 #if GNUC_PREREQ (4, 7, 0)
   if (__atomic_sub_fetch (&threads_holding_glib_lock, 1, __ATOMIC_ACQ_REL) == 
0)
@@ -43,7 +45,8 @@ void release_select_lock (void)
 #endif
 }
 
-static void acquire_select_lock (GMainContext *context)
+static void
+acquire_select_lock (GMainContext *context)
 {
 #if GNUC_PREREQ (4, 7, 0)
   if (__atomic_fetch_add (&threads_holding_glib_lock, 1, __ATOMIC_ACQ_REL) == 
0)
@@ -181,6 +184,21 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set 
*efds,
 #else
   need_to_dispatch = true;
 #endif
+
+  /* xwidgets make heavy use of GLib subprocesses, which add their own
+     SIGCHLD handler at arbitrary locations.  That doesn't play well
+     with Emacs's own handler, so once GLib does its thing with its
+     subprocesses we restore our own SIGCHLD handler (which chains the
+     GLib handler) here.
+
+     There is an obvious race condition, but we can't really do
+     anything about that, except hope a SIGCHLD arrives soon to clear
+     up the situation.  */
+
+#ifdef HAVE_XWIDGETS
+  catch_child_signal ();
+#endif
+
   if (need_to_dispatch)
     {
       acquire_select_lock (context);
diff --git a/src/xwidget.c b/src/xwidget.c
index 24dafa7d3c..7d6d256a19 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -3610,6 +3610,8 @@ kill_xwidget (struct xwidget *xw)
   xw->widget_osr = NULL;
   xw->widgetwindow_osr = NULL;
   xw->find_text = NULL;
+
+  catch_child_signal ();
 #elif defined NS_IMPL_COCOA
   nsxwidget_kill (xw);
 #endif
@@ -3630,4 +3632,6 @@ kill_buffer_xwidgets (Lisp_Object buffer)
        kill_xwidget (xw);
       }
     }
+
+  catch_child_signal ();
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]