From 163764be406dd6f64dbd4affd6c294359f00501e Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 25 Nov 2017 12:42:28 +0100 Subject: democompositor: Introduce a graceful stop of a client application Use SIGTERM to terminate the application but to make sure it will go away create a unique timer and start it. The timer is owned by the QProcess and will go away once the process has terminated. On timeout use SIGKILL to make sure the process is going away. Change-Id: I9f9617a579952697aa61bd7bfa1d2fd264a443ce Reviewed-by: Paul Olav Tvete --- wayland/democompositor/processlauncher.cpp | 19 +++++++++++++++++++ wayland/democompositor/processlauncher.h | 1 + wayland/democompositor/qml/Screen.qml | 4 +++- 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'wayland') diff --git a/wayland/democompositor/processlauncher.cpp b/wayland/democompositor/processlauncher.cpp index 6147f05..29e4d64 100644 --- a/wayland/democompositor/processlauncher.cpp +++ b/wayland/democompositor/processlauncher.cpp @@ -52,6 +52,7 @@ #include "apps/appentry.h" #include +#include Q_LOGGING_CATEGORY(procs, "launcher.procs") @@ -118,6 +119,24 @@ void WaylandProcessLauncher::kill(const AppEntry& entry) } } +void WaylandProcessLauncher::stop(const AppEntry& entry, int ms) +{ + for (auto state : m_appStates) { + if (state.appEntry.sourceFileName != entry.sourceFileName) + continue; + + auto timer = new QTimer(state.process); + connect(timer, &QTimer::timeout, [entry, state, timer] { + qCDebug(procs) << "Sending SIGKILL " << state.process->pid() << " for " << entry.sourceFileName; + timer->deleteLater(); + state.process->kill(); + }); + timer->start(ms); + qCDebug(procs) << "Sending SIGTERM " << state.process->pid() << " for " << entry.sourceFileName; + state.process->terminate(); + } +} + void WaylandProcessLauncher::launch(const AppEntry &entry) { qCDebug(procs) << "Launching" << entry.executableName; diff --git a/wayland/democompositor/processlauncher.h b/wayland/democompositor/processlauncher.h index 9453368..ae847e2 100644 --- a/wayland/democompositor/processlauncher.h +++ b/wayland/democompositor/processlauncher.h @@ -87,6 +87,7 @@ public: Q_INVOKABLE QVariant appStateForPid(int pid) const; Q_INVOKABLE bool isRunning(const AppEntry& entry) const; Q_INVOKABLE void kill(const AppEntry& entry); + Q_INVOKABLE void stop(const AppEntry& entry, int timeout_ms); Q_SIGNALS: void appStarted(const AppState &appState); diff --git a/wayland/democompositor/qml/Screen.qml b/wayland/democompositor/qml/Screen.qml index bea189b..2986562 100644 --- a/wayland/democompositor/qml/Screen.qml +++ b/wayland/democompositor/qml/Screen.qml @@ -202,7 +202,9 @@ WaylandOutput { } onSlideTrigger: { //console.log("slide " + winItem + " : " + winItem.shellSurface.surface) - winItem.shellSurface.surface.client.close() + winItem.appEntry === null ? + winItem.shellSurface.surface.client.close() : + launcher.stop(winItem.appEntry, 5000); } } Rectangle { -- cgit v1.2.3