Skip to content

Commit

Permalink
linux_me2me_host.py: Quit gnome-session properly
Browse files Browse the repository at this point in the history
When the gnome-session process is killed, it can cause the service
restart to halt at times. This change tries to stop the gnome-session
using gnome-session-quit instead.

Bug: chromium:1291247
Change-Id: Iee4763ab86fd7bf73518dfeae2a8ace8950e47cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4192107
Reviewed-by: Lambros Lambrou <lambroslambrou@chromium.org>
Auto-Submit: Salman Malik <salmanmalik@chromium.org>
Commit-Queue: Salman Malik <salmanmalik@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096363}
  • Loading branch information
Salman authored and Chromium LUCI CQ committed Jan 24, 2023
1 parent 809a6cd commit 362dbf0
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion remoting/host/linux/linux_me2me_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@
# wayland compositor/server for clients to connect to.
RUNTIME_DIR_TEMPLATE = "/run/user/%s"

# Binary name for the gnome-session.
# Binary name for `gnome-session`.
GNOME_SESSION = "gnome-session"

# Binary name for `gnome-session-quit`.
GNOME_SESSION_QUIT = "gnome-session-quit"

# Globals needed by the atexit cleanup() handler.
g_desktop = None
g_host_hash = hashlib.md5(socket.gethostname().encode()).hexdigest()
Expand Down Expand Up @@ -933,6 +936,39 @@ def _wait_for_setup_before_host_launch(self):
return self._wait_for_wayland_compositor_running()

def cleanup(self):
if self.host_proc is not None:
logging.info("Sending SIGTERM to host proc (pid=%s)", self.host_proc.pid)
try:
psutil_proc = psutil.Process(self.host_proc.pid)
psutil_proc.terminate()

# Use a short timeout, to avoid delaying service shutdown if the
# process refuses to die for some reason.
psutil_proc.wait(timeout=10)
except psutil.TimeoutExpired:
logging.error("Timed out - sending SIGKILL")
psutil_proc.kill()
except psutil.Error:
logging.error("Error terminating process")
self.host_proc = None

# We currently only support gnome-session (which is currently managed)
# by CRD itself.
logging.info("Executing %s" % GNOME_SESSION_QUIT)
if shutil.which(GNOME_SESSION_QUIT):
cleanup_proc = subprocess.Popen(
[GNOME_SESSION_QUIT, "--force", "--no-prompt"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=self.child_env)
stdout, stderr = cleanup_proc.communicate()
if stderr:
logging.error("Failed to execute %s:\n%s" %
(GNOME_SESSION_QUIT, stderr))
self.session_proc = None
else:
logging.warning("No %s found on the system" % GNOME_SESSION_QUIT)

super(WaylandDesktop, self).cleanup()
if self._wayland_socket:
full_socket_path = os.path.join(self.runtime_dir, self._wayland_socket)
Expand Down

0 comments on commit 362dbf0

Please sign in to comment.