kwin: do not start the kwin_killer_helper program as detached process

simplifies the process checks, the process is terminated from the
KWin::Client destructor anyway

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-10 08:09:05 +02:00
parent 4e74fe086e
commit 4ffb216b5f
2 changed files with 13 additions and 12 deletions

View file

@ -102,7 +102,7 @@ Client::Client()
, tab_group(NULL) , tab_group(NULL)
, in_layer(UnknownLayer) , in_layer(UnknownLayer)
, ping_timer(NULL) , ping_timer(NULL)
, m_killHelperPID(0) , m_killHelperProc(0)
, m_pingTimestamp(XCB_TIME_CURRENT_TIME) , m_pingTimestamp(XCB_TIME_CURRENT_TIME)
, m_userTime(XCB_TIME_CURRENT_TIME) // Not known yet , m_userTime(XCB_TIME_CURRENT_TIME) // Not known yet
, allowed_actions(0) , allowed_actions(0)
@ -206,9 +206,8 @@ Client::Client()
*/ */
Client::~Client() Client::~Client()
{ {
if (m_killHelperPID && ::kill(m_killHelperPID, 0) == -1) { // means the process is alive if (m_killHelperProc) { // means the process is alive
::kill(m_killHelperPID, SIGTERM); m_killHelperProc->terminate();
m_killHelperPID = 0;
} }
//SWrapper::Client::clientRelease(this); //SWrapper::Client::clientRelease(this);
#ifdef HAVE_XSYNC #ifdef HAVE_XSYNC
@ -1316,9 +1315,9 @@ void Client::gotPing(xcb_timestamp_t timestamp)
return; return;
delete ping_timer; delete ping_timer;
ping_timer = NULL; ping_timer = NULL;
if (m_killHelperPID && ::kill(m_killHelperPID, 0) == -1) { // means the process is alive if (m_killHelperProc) { // means the process is alive
::kill(m_killHelperPID, SIGTERM); m_killHelperProc->terminate();
m_killHelperPID = 0; m_killHelperProc = nullptr;
} }
} }
@ -1332,7 +1331,7 @@ void Client::pingTimeout()
void Client::killProcess(bool ask, xcb_timestamp_t timestamp) void Client::killProcess(bool ask, xcb_timestamp_t timestamp)
{ {
if (m_killHelperPID && ::kill(m_killHelperPID, 0) == -1) // means the process is alive if (m_killHelperProc && m_killHelperProc->state() == QProcess::Running) // means the process is alive
return; return;
Q_ASSERT(!ask || timestamp != XCB_TIME_CURRENT_TIME); Q_ASSERT(!ask || timestamp != XCB_TIME_CURRENT_TIME);
pid_t pid = info->pid(); pid_t pid = info->pid();
@ -1349,13 +1348,13 @@ void Client::killProcess(bool ask, xcb_timestamp_t timestamp)
} }
} else { } else {
QString hostname = clientMachine()->isLocal() ? "localhost" : clientMachine()->hostName(); QString hostname = clientMachine()->isLocal() ? "localhost" : clientMachine()->hostName();
QProcess::startDetached(KStandardDirs::findExe("kwin_killer_helper"), m_killHelperProc = new QProcess(this);
m_killHelperProc->start(KStandardDirs::findExe("kwin_killer_helper"),
QStringList() << "--pid" << QByteArray::number(qulonglong(pid)) << "--hostname" << hostname QStringList() << "--pid" << QByteArray::number(qulonglong(pid)) << "--hostname" << hostname
<< "--windowname" << caption() << "--windowname" << caption()
<< "--applicationname" << resourceClass() << "--applicationname" << resourceClass()
<< "--wid" << QString::number(window()) << "--wid" << QString::number(window())
<< "--timestamp" << QString::number(timestamp), << "--timestamp" << QString::number(timestamp));
QString(), &m_killHelperPID);
} }
} }

View file

@ -43,6 +43,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// TODO: Cleanup the order of things in this .h file // TODO: Cleanup the order of things in this .h file
#include <QTimer> #include <QTimer>
#include <QProcess>
class KStartupInfoData; class KStartupInfoData;
class KStartupInfoId; class KStartupInfoId;
@ -899,7 +901,7 @@ private:
TabGroup* tab_group; TabGroup* tab_group;
Layer in_layer; Layer in_layer;
QTimer* ping_timer; QTimer* ping_timer;
qint64 m_killHelperPID; QProcess* m_killHelperProc;
xcb_timestamp_t m_pingTimestamp; xcb_timestamp_t m_pingTimestamp;
xcb_timestamp_t m_userTime; xcb_timestamp_t m_userTime;
unsigned long allowed_actions; unsigned long allowed_actions;