Warning, file /frameworks/kdbusaddons/src/kdeinitinterface.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of libkdbusaddons
0003 
0004     SPDX-FileCopyrightText: 2013 David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "kdeinitinterface.h"
0010 #include "kdbusaddons_debug.h"
0011 
0012 #include <QDBusConnection>
0013 #include <QDBusConnectionInterface>
0014 #include <QDir>
0015 #include <QLockFile>
0016 #include <QProcess>
0017 #include <QStandardPaths>
0018 
0019 #include <QCoreApplication>
0020 #include <QLibraryInfo>
0021 
0022 void KDEInitInterface::ensureKdeinitRunning()
0023 {
0024     QDBusConnectionInterface *dbusDaemon = QDBusConnection::sessionBus().interface();
0025     if (dbusDaemon->isServiceRegistered(QStringLiteral("org.kde.klauncher5"))) {
0026         return;
0027     }
0028     qCDebug(KDBUSADDONS_LOG) << "klauncher not running... launching kdeinit";
0029 
0030     QLockFile lock(QDir::tempPath() + QLatin1Char('/') + QLatin1String("startkdeinitlock"));
0031     // If we can't get the lock, then someone else is already in the process of starting kdeinit.
0032     if (!lock.tryLock()) {
0033         // Wait for that to happen, by locking again 30 seconds max.
0034         if (!lock.tryLock(30000)) {
0035             qCWarning(KDBUSADDONS_LOG) << "'kdeinit5' is taking more than 30 seconds to start.";
0036             return;
0037         }
0038         // Check that the DBus name is up, i.e. the other process did manage to do it successfully.
0039         if (dbusDaemon->isServiceRegistered(QStringLiteral("org.kde.klauncher5"))) {
0040             return;
0041         }
0042     }
0043     // Try to launch kdeinit.
0044     QString srv = QStandardPaths::findExecutable(QStringLiteral("kdeinit5"));
0045     // If not found in system paths, search other paths
0046     if (srv.isEmpty()) {
0047         const QStringList searchPaths = QStringList() << QCoreApplication::applicationDirPath() // then look where our application binary is located
0048                                                       << QLibraryInfo::location(QLibraryInfo::BinariesPath); // look where exec path is (can be set in qt.conf)
0049         srv = QStandardPaths::findExecutable(QStringLiteral("kdeinit5"), searchPaths);
0050         if (srv.isEmpty()) {
0051             qCWarning(KDBUSADDONS_LOG) << "Can not find 'kdeinit5' executable at " << qgetenv("PATH") << searchPaths.join(QStringLiteral(", "));
0052             return;
0053         }
0054     }
0055 
0056     QStringList args;
0057 #ifndef Q_OS_WIN
0058     args += QStringLiteral("--suicide");
0059 #endif
0060     // NOTE: kdeinit5 is supposed to finish quickly, certainly in less than 30 seconds.
0061     QProcess::execute(srv, args);
0062 }