[plasma-session] Avoid hypothetical race condition starting a service

Summary:
If for some reason a service is started before StartServiceJob runs, we
will end up blocking forever.

Test Plan: Logged in

Reviewers: #plasma, apol

Reviewed By: apol

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27471
wilder-5.18
David Edmundson 6 years ago
parent 285155fad1
commit 854b64fc13
  1. 9
      startkde/plasma-session/startup.cpp
  2. 1
      startkde/plasma-session/startup.h

@ -417,7 +417,8 @@ void AutoStartAppsJob::start() {
StartServiceJob::StartServiceJob(const QString &process, const QStringList &args, const QString &serviceId):
KJob(),
m_process(process),
m_args(args)
m_args(args),
m_serviceId(serviceId)
{
auto watcher = new QDBusServiceWatcher(serviceId, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration, this);
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &StartServiceJob::emitResult);
@ -425,6 +426,12 @@ StartServiceJob::StartServiceJob(const QString &process, const QStringList &args
void StartServiceJob::start()
{
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(m_serviceId)) {
qCDebug(PLASMA_SESSION) << m_process << "already running";
emitResult();
return;
}
qCDebug(PLASMA_SESSION) << "Starting " << m_process << m_args;
QProcess::startDetached(m_process, m_args);
}

@ -92,6 +92,7 @@ public:
private:
const QString m_process;
const QStringList m_args;
const QString m_serviceId;
};
class RestoreSessionJob: public KJob

Loading…
Cancel
Save