From 8645007bffb844e6d35d19e902f0cce380233b40 Mon Sep 17 00:00:00 2001 From: Leonhard <106322251+leolost2605@users.noreply.github.com> Date: Tue, 28 May 2024 20:01:43 +0200 Subject: [PATCH] Avoid ending our own process (#1919) --- src/Dialogs.vala | 12 ++++++++++++ src/ShellClients/ManagedClient.vala | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Dialogs.vala b/src/Dialogs.vala index 2f382674..658f9cb1 100644 --- a/src/Dialogs.vala +++ b/src/Dialogs.vala @@ -172,6 +172,18 @@ namespace Gala { return; } + try { + var our_pid = new Credentials ().get_unix_pid (); + if (our_pid == window.get_pid ()) { + critical ("We have an unresponsive window somewhere. Mutter wants to end its own process. Don't let it."); + // In all seriousness this sounds bad, but can happen if one of our WaylandClients gets unresponsive. + on_response (1); + return; + } + } catch (Error e) { + warning ("Failed to safeguard kill pid: %s", e.message); + } + base.show (); } diff --git a/src/ShellClients/ManagedClient.vala b/src/ShellClients/ManagedClient.vala index d354fc46..6d3cf1ab 100644 --- a/src/ShellClients/ManagedClient.vala +++ b/src/ShellClients/ManagedClient.vala @@ -18,6 +18,8 @@ public class Gala.ManagedClient : Object { public Meta.WaylandClient? wayland_client { get; private set; } + private Subprocess? subprocess; + public ManagedClient (Meta.Display display, string[] args) { Object (display: display, args: args); } @@ -29,6 +31,15 @@ public class Gala.ManagedClient : Object { display.window_created.connect ((window) => { if (wayland_client != null && wayland_client.owns_window (window)) { window_created (window); + + // We have to manage is alive manually since windows created by WaylandClients have our pid + // and we don't want to end our own process + window.notify["is-alive"].connect (() => { + if (!window.is_alive && subprocess != null) { + subprocess.force_exit (); + warning ("WaylandClient window became unresponsive, killing the client."); + } + }); } }); } else { @@ -44,7 +55,7 @@ public class Gala.ManagedClient : Object { #else wayland_client = new Meta.WaylandClient (subprocess_launcher); #endif - var subprocess = wayland_client.spawnv (display, args); + subprocess = wayland_client.spawnv (display, args); yield subprocess.wait_async (); @@ -61,7 +72,7 @@ public class Gala.ManagedClient : Object { private async void start_x () { try { - var subprocess = new Subprocess.newv (args, NONE); + subprocess = new Subprocess.newv (args, NONE); yield subprocess.wait_async (); //Restart the daemon if it crashes