From 87c93679b8b4cf586ef9c539c18a38feec145005 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 16 May 2024 00:50:57 +0300 Subject: [PATCH] kwin: rework client killing to not rely on xon program because xon is no longer a thing (not in debian repos apparently) killing remote clients and killing remote clients required it, assuming XKillClient() knows how to kill remote clients then it will now. if not then.. Signed-off-by: Ivailo Monev --- kwin/client.cpp | 53 +++++++++++++++++++++--------------------- kwin/client.h | 2 +- kwin/killer/killer.cpp | 13 ++--------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/kwin/client.cpp b/kwin/client.cpp index eab6ae8b..ce264715 100644 --- a/kwin/client.cpp +++ b/kwin/client.cpp @@ -99,7 +99,7 @@ Client::Client() , tab_group(NULL) , in_layer(UnknownLayer) , ping_timer(NULL) - , m_killHelperProc(0) + , m_killHelperProc(NULL) , m_pingTimestamp(XCB_TIME_CURRENT_TIME) , m_userTime(XCB_TIME_CURRENT_TIME) // Not known yet , allowed_actions(0) @@ -1248,9 +1248,11 @@ void Client::closeWindow() if (Pdeletewindow) { sendClientMessage(window(), atoms->wm_protocols, atoms->wm_delete_window); pingWindow(); - } else // Client will not react on wm_delete_window. We have not choice - // but destroy his connection to the XServer. + } else { + // Client will not react on wm_delete_window, No choice but to destroy the + // connection to the XServer. killWindow(); + } } @@ -1260,7 +1262,6 @@ void Client::closeWindow() void Client::killWindow() { kDebug(1212) << "Client::killWindow():" << caption(); - killProcess(false); XKillClient(display(), window()); // Always kill this client at the server destroyClient(); } @@ -1303,36 +1304,36 @@ void Client::pingTimeout() kDebug(1212) << "Ping timeout:" << caption(); ping_timer->deleteLater(); ping_timer = NULL; - killProcess(true, m_pingTimestamp); -} -void Client::killProcess(bool ask, xcb_timestamp_t timestamp) -{ if (m_killHelperProc && m_killHelperProc->state() == QProcess::Running) // means the process is alive return; - Q_ASSERT(!ask || timestamp != XCB_TIME_CURRENT_TIME); + Q_ASSERT(!ask || m_pingTimestamp != XCB_TIME_CURRENT_TIME); pid_t pid = info->pid(); if (pid <= 0 || clientMachine()->hostName().isEmpty()) // Needed properties missing return; kDebug(1212) << "Kill process:" << pid << "(" << clientMachine()->hostName() << ")"; - if (!ask) { - if (!clientMachine()->isLocal()) { - QStringList lst; - lst << clientMachine()->hostName() << "kill" << QString::number(pid); - QProcess::startDetached("xon", lst); - } else { - ::kill(pid, SIGTERM); - } - } else { - QString hostname = clientMachine()->isLocal() ? "localhost" : clientMachine()->hostName(); - m_killHelperProc = new QProcess(this); - m_killHelperProc->start(KStandardDirs::findExe("kwin_killer_helper"), - QStringList() << "--pid" << QByteArray::number(qulonglong(pid)) << "--hostname" << hostname - << "--windowname" << caption() - << "--applicationname" << resourceClass() - << "--wid" << QString::number(window()) - << "--timestamp" << QString::number(timestamp)); + QString hostname = clientMachine()->isLocal() ? "localhost" : clientMachine()->hostName(); + m_killHelperProc = new QProcess(this); + connect(m_killHelperProc, SIGNAL(finished(int)), this, SLOT(killHelperFinished(int))); + m_killHelperProc->start( + KStandardDirs::findExe("kwin_killer_helper"), + QStringList() << "--pid" << QByteArray::number(qulonglong(pid)) << "--hostname" << hostname + << "--windowname" << caption() + << "--applicationname" << resourceClass() + << "--wid" << QString::number(window()) + << "--timestamp" << QString::number(m_pingTimestamp) + ); +} + +void Client::killHelperFinished(int exitCode) +{ + if (exitCode == 2) { + kDebug(1212) << "Kill confirmed:" << caption(); + killWindow(); } + kDebug(1212) << "Kill not confirmed:" << caption(); + m_killHelperProc->deleteLater(); + m_killHelperProc = nullptr; } void Client::setSkipTaskbar(bool b, bool from_outside) diff --git a/kwin/client.h b/kwin/client.h index 11b1fdc7..721d921c 100644 --- a/kwin/client.h +++ b/kwin/client.h @@ -666,6 +666,7 @@ private slots: void performMoveResize(); void removeSyncSupport(); void pingTimeout(); + void killHelperFinished(int exitCode); //Signals for the scripting interface //Signals make an excellent way for communication @@ -750,7 +751,6 @@ private: void createDecoration(const QRect &oldgeom); void pingWindow(); - void killProcess(bool ask, xcb_timestamp_t timestamp = XCB_TIME_CURRENT_TIME); void updateUrgency(); static void sendClientMessage(xcb_window_t w, xcb_atom_t a, xcb_atom_t protocol, long data1 = 0, long data2 = 0, long data3 = 0); diff --git a/kwin/killer/killer.cpp b/kwin/killer/killer.cpp index bfdf3395..c27a7e93 100644 --- a/kwin/killer/killer.cpp +++ b/kwin/killer/killer.cpp @@ -72,7 +72,7 @@ int main(int argc, char* argv[]) caption = Qt::escape(caption); appname = Qt::escape(appname); hostname = Qt::escape(hostname); - QString pidString = QString::number(pid); // format pid ourself as it does not make sense to format an ID according to locale settings + QString pidString = QString::number(pid); QString question = i18nc("@info", "Application \"%1\" is not responding", appname); question += isLocal @@ -89,16 +89,7 @@ int main(int argc, char* argv[]) KGuiItem cancelButton = KGuiItem(i18n("Wait Longer"), "chronometer"); app.updateUserTimestamp(timestamp); if (KMessageBox::warningContinueCancelWId(id, question, QString(), continueButton, cancelButton) == KMessageBox::Continue) { - if (!isLocal) { - QStringList lst; - lst << hostname << "kill" << QString::number(pid); - QProcess::startDetached("xon", lst); - } else { - if (::kill(pid, SIGKILL) == -1) { - kWarning(1212) << "KWin process killer failed"; - } - } + return 2; } - return 0; }