From 9bc337f9830109b2138bfeb2ee70f9481c3c549a Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 22 Jun 2018 13:19:56 +0200 Subject: widget: Make vte_terminal_spawn_async match its synchronous variant It doesn't cause any visible change in behaviour on its own. However, for downstreams that continue to use gnome-pty-helper, this avoids a race condition where the helper closes its copy of the pseudo-terminal slave file descriptor right after VteTerminal has started polling the master for input, but before the child process has been forked. This causes VteTerminal to receive a G_IO_HUP and it stops reading the master for further input. The subsequently forked child process gets left in a defunct state, and this CRITICAL is logged: Vte-CRITICAL **: void vte_terminal_watch_child(VteTerminal*, GPid): assertion 'impl->m_pty != NULL' failed Polling the pseudo-terminal master device after the child process has been set up, avoids this race because the child keeps its copy of the slave file descriptor open. This prevents VteTerminal from receiving any G_IO_HUP even if the helper closes its copy afterwards. Fixes GNOME/vte#7: https://gitlab.gnome.org/GNOME/vte/issues/7 --- src/vtegtk.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vtegtk.cc b/src/vtegtk.cc index 9e541be1..c435b55c 100644 --- a/src/vtegtk.cc +++ b/src/vtegtk.cc @@ -2543,10 +2543,12 @@ spawn_async_cb (GObject *source, /* Automatically watch the child */ if (terminal != nullptr) { - if (pid != -1) + if (pid != -1) { + vte_terminal_set_pty(terminal, pty); vte_terminal_watch_child(terminal, pid); - else + } else { vte_terminal_set_pty(terminal, nullptr); + } } else { if (pid != -1) { vte_reaper_add_child(pid); @@ -2671,8 +2673,6 @@ vte_terminal_spawn_async(VteTerminal *terminal, return; } - vte_terminal_set_pty(terminal, pty); - guint spawn_flags = (guint)spawn_flags_; /* We do NOT support this flag. If you want to have some FD open in the child -- cgit v1.2.1