Commit 3c34dfa9 authored by David Edmundson's avatar David Edmundson

[plasma-session] Load startup and shutdown on demand

Summary:
Currently startplasma spawns plasma-session then sits around waiting for
that to finish

plasma-session spawns all the startup then also just sits around doing
nothing

This patch makes plasma-session spawn all the startup and then quit.

It also splits the owner of the org.kde.shutdown interface to be on
demand. plasma-shutdown asks ksmserver to quit and then if applicable
runs the shutdown scripts or not.

Startplasma then knows when to exit by monitoring the DBus service
status directly.

The benefits are that we save some resources by not needing
plasma-session lingering about.

It also means the shutdown interface is re-usable as-is when the pending
systemd startup method is used.

Test Plan:
Logged in and:
 - ran killall ksmserver, session ended as before
 - logged out and cancelled due to unsaved changes
 - logged out and completed logout
 - logged out and rebooted

Reviewers: #plasma, apol

Reviewed By: apol

Subscribers: apol, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27629
parent ff84d313
......@@ -30,7 +30,7 @@ set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml)
qt5_add_dbus_interface( ksmserver_KDEINIT_SRCS ${klauncher_xml} klauncher_interface )
qt5_add_dbus_interface( ksmserver_KDEINIT_SRCS ../startkde/plasma-session/org.kde.Startup.xml startup_interface )
qt5_add_dbus_interface( ksmserver_KDEINIT_SRCS ../startkde/plasma-session/org.kde.Shutdown.xml shutdown_interface )
qt5_add_dbus_interface( ksmserver_KDEINIT_SRCS ../startkde/plasma-shutdown/org.kde.Shutdown.xml shutdown_interface )
kf5_add_kdeinit_executable( ksmserver ${ksmserver_KDEINIT_SRCS})
......
......@@ -18,7 +18,7 @@ qt5_add_dbus_interface(kworkspace_LIB_SRCS ${KSCREENLOCKER_DBUS_INTERFACES_DIR}/
qt5_add_dbus_interface(kworkspace_LIB_SRCS ${KSCREENLOCKER_DBUS_INTERFACES_DIR}/org.kde.screensaver.xml kscreenlocker_interface )
qt5_add_dbus_interface(kworkspace_LIB_SRCS ${plasma-workspace_SOURCE_DIR}/ksmserver/org.kde.LogoutPrompt.xml logoutprompt_interface)
qt5_add_dbus_interface(kworkspace_LIB_SRCS ${plasma-workspace_SOURCE_DIR}/startkde/plasma-session/org.kde.Startup.xml startup_interface)
qt5_add_dbus_interface(kworkspace_LIB_SRCS ${plasma-workspace_SOURCE_DIR}/startkde/plasma-session/org.kde.Shutdown.xml shutdown_interface)
qt5_add_dbus_interface(kworkspace_LIB_SRCS ${plasma-workspace_SOURCE_DIR}/startkde/plasma-shutdown/org.kde.Shutdown.xml shutdown_interface)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.login1.Manager.xml"
"${CMAKE_SOURCE_DIR}/data/interfaces/org.freedesktop.login1.Seat.xml"
......
......@@ -23,6 +23,7 @@ target_link_libraries(startplasma-x11 PRIVATE Qt5::Core Qt5::DBus KF5::ConfigCor
target_link_libraries(startplasma-wayland PRIVATE Qt5::Core Qt5::DBus KF5::ConfigCore)
target_link_libraries(startplasma-waylandsession PRIVATE Qt5::Core Qt5::DBus KF5::ConfigCore)
add_subdirectory(plasma-session)
add_subdirectory(plasma-shutdown)
#FIXME: reconsider, looks fishy
if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr")
......
......@@ -4,14 +4,11 @@ set(plasma_session_SRCS
main.cpp
autostart.cpp
startup.cpp
shutdown.cpp
)
ecm_qt_declare_logging_category(plasma_session_SRCS HEADER debug.h IDENTIFIER PLASMA_SESSION CATEGORY_NAME org.kde.plasma.session)
qt5_add_dbus_adaptor( plasma_session_SRCS org.kde.Startup.xml startup.h Startup)
qt5_add_dbus_adaptor( plasma_session_SRCS org.kde.Shutdown.xml shutdown.h Shutdown)
qt5_add_dbus_interface( plasma_session_SRCS org.kde.Shutdown.xml shutdown_interface)
set(kcminit_adaptor ${plasma-workspace_SOURCE_DIR}/startkde/kcminit/main.h)
set(kcminit_xml ${CMAKE_CURRENT_BINARY_DIR}/org.kde.KCMinit.xml)
......
......@@ -17,7 +17,6 @@
*/
#include "startup.h"
#include "shutdown.h"
#include <QCoreApplication>
......@@ -30,7 +29,5 @@ int main(int argc, char **argv)
app.setQuitLockEnabled(false);
new Startup(&app);
new Shutdown(&app);
app.exec();
}
......@@ -250,6 +250,7 @@ void Startup::finishStartup()
{
qCDebug(PLASMA_SESSION) << "Finished";
upAndRunning(QStringLiteral("ready"));
qApp->quit();
}
void Startup::updateLaunchEnv(const QString &key, const QString &value)
......
set(plasma_shutdown_SRCS
main.cpp
shutdown.cpp
)
ecm_qt_declare_logging_category(plasma_shutdown_SRCS HEADER debug.h IDENTIFIER PLASMA_SESSION CATEGORY_NAME org.kde.plasma.shutdown)
qt5_add_dbus_adaptor(plasma_shutdown_SRCS org.kde.Shutdown.xml shutdown.h Shutdown)
qt5_add_dbus_interface(plasma_shutdown_SRCS org.kde.Shutdown.xml shutdown_interface)
qt5_add_dbus_interface( plasma_shutdown_SRCS ../../ksmserver/org.kde.KSMServerInterface.xml ksmserver_interface )
add_executable(plasma-shutdown ${plasma_shutdown_SRCS})
target_link_libraries(plasma-shutdown
Qt5::Core
Qt5::DBus
KF5::ConfigCore
PW::KWorkspace
)
kdbusaddons_generate_dbus_service_file(plasma-shutdown org.kde.Shutdown ${KDE_INSTALL_FULL_BINDIR})
install(TARGETS plasma-shutdown ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
/*
* Copyright © 2018 David Edmundson <davidedmundson@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "shutdown.h"
#include <QCoreApplication>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
new Shutdown(&app);
app.exec();
}
......@@ -47,7 +47,8 @@ void Shutdown::startLogout(KWorkSpace::ShutdownType shutdownType)
connect(watcher, &QDBusPendingCallWatcher::finished, this, [closeSessionReply, watcher, this]() {
watcher->deleteLater();
if (closeSessionReply.isError()) {
qDebug() << "ksmserver failed to complete logout";
qCWarning(PLASMA_SESSION) << "ksmserver failed to complete logout";
qApp->quit();
}
if (closeSessionReply.value()) {
logoutComplete();
......@@ -60,6 +61,7 @@ void Shutdown::startLogout(KWorkSpace::ShutdownType shutdownType)
void Shutdown::logoutCancelled()
{
m_shutdownType = KWorkSpace::ShutdownTypeNone;
qApp->quit();
}
void Shutdown::logoutComplete() {
......
......@@ -25,6 +25,7 @@
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
createConfigDirectory();
setupCursor(true);
......
......@@ -29,12 +29,14 @@ void sighupHandler(int)
out << "GOT SIGHUP\n";
}
int main(int /*argc*/, char** /*argv*/)
int main(int argc, char** argv)
{
// When the X server dies we get a HUP signal from xinit. We must ignore it
// because we still need to do some cleanup.
signal(SIGHUP, sighupHandler);
QCoreApplication app(argc, argv);
// Boot sequence:
//
// kdeinit is used to fork off processes which improves memory usage
......
......@@ -21,7 +21,11 @@
#include <QProcess>
#include <QStandardPaths>
#include <QTextStream>
#include <QEventLoop>
#include <QDBusConnectionInterface>
#include <QDBusServiceWatcher>
#include <KConfig>
#include <KConfigGroup>
......@@ -357,14 +361,41 @@ bool startPlasmaSession(bool wayland)
}
}
const auto exitCode = runSync(QStringLiteral(CMAKE_INSTALL_FULL_BINDIR "/plasma_session"), plasmaSessionOptions);
bool rc = true;
QEventLoop e;
QProcess startPlasmaSession;
QDBusServiceWatcher serviceWatcher;
serviceWatcher.setConnection(QDBusConnection::sessionBus());
// We want to exit when both ksmserver and plasma-session-shutdown have finished
// This also closes if ksmserver crashes unexpectedly, as in those cases plasma-shutdown is not running
serviceWatcher.addWatchedService(QStringLiteral("org.kde.ksmserver"));
serviceWatcher.addWatchedService(QStringLiteral("org.kde.shutdown"));
serviceWatcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
QObject::connect(&startPlasmaSession, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [&rc, &e](int exitCode, QProcess::ExitStatus) {
if (exitCode == 255) {
// Startup error
messageBox(QStringLiteral("startkde: Could not start ksmserver. Check your installation.\n"));
rc = false;
e.quit();
}
});
QObject::connect(&serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, [&]() {
const QStringList watchedServices = serviceWatcher.watchedServices();
bool plasmaSessionRunning = std::any_of(watchedServices.constBegin(), watchedServices.constEnd(), [](const QString &service) {
return QDBusConnection::sessionBus().interface()->isServiceRegistered(service);
});
if (!plasmaSessionRunning) {
e.quit();
}
});
if (exitCode == 255) {
// Startup error
messageBox(QStringLiteral("startkde: Could not start ksmserver. Check your installation.\n"));
return false;
}
return true;
startPlasmaSession.start(QStringLiteral(CMAKE_INSTALL_FULL_BINDIR "/plasma_session"), plasmaSessionOptions);
e.exec();
return rc;
}
void waitForKonqi()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment