Changeset View
Changeset View
Standalone View
Standalone View
ksmserver/server.cpp
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | |||||
79 | #include <kconfig.h> | 79 | #include <kconfig.h> | ||
80 | #include <KSharedConfig> | 80 | #include <KSharedConfig> | ||
81 | #include <kdesktopfile.h> | 81 | #include <kdesktopfile.h> | ||
82 | #include <QTemporaryFile> | 82 | #include <QTemporaryFile> | ||
83 | #include <kconfiggroup.h> | 83 | #include <kconfiggroup.h> | ||
84 | #include <kprocess.h> | 84 | #include <kprocess.h> | ||
85 | #include <kshell.h> | 85 | #include <kshell.h> | ||
86 | 86 | | |||
87 | #include <KIO/CommandLauncherJob> | ||||
88 | | ||||
87 | #include <KScreenLocker/KsldApp> | 89 | #include <KScreenLocker/KsldApp> | ||
88 | 90 | | |||
89 | #include <QX11Info> | 91 | #include <QX11Info> | ||
90 | #include <krandom.h> | 92 | #include <krandom.h> | ||
91 | #include <klauncher_interface.h> | 93 | #include <klauncher_interface.h> | ||
92 | #include <startup_interface.h> | 94 | #include <startup_interface.h> | ||
93 | #include <qstandardpaths.h> | 95 | #include <qstandardpaths.h> | ||
94 | 96 | | |||
95 | #include "kscreenlocker_interface.h" | 97 | #include "kscreenlocker_interface.h" | ||
96 | #include "kwinsession_interface.h" | 98 | #include "kwinsession_interface.h" | ||
97 | 99 | | |||
98 | KSMServer* the_server = nullptr; | 100 | KSMServer* the_server = nullptr; | ||
99 | 101 | | |||
100 | KSMServer* KSMServer::self() | 102 | KSMServer* KSMServer::self() | ||
101 | { | 103 | { | ||
102 | return the_server; | 104 | return the_server; | ||
103 | } | 105 | } | ||
104 | 106 | | |||
105 | /*! Utility function to execute a command on the local machine. Used | 107 | /*! Utility function to execute a command on the local machine. Used | ||
106 | * to restart applications. | 108 | * to restart applications. | ||
107 | */ | 109 | */ | ||
108 | KProcess* KSMServer::startApplication( const QStringList& cmd, const QString& clientMachine, | 110 | void KSMServer::startApplication( const QStringList& cmd, const QString& clientMachine, | ||
109 | const QString& userId, bool wm ) | 111 | const QString& userId) | ||
110 | { | 112 | { | ||
111 | QStringList command = cmd; | 113 | QStringList command = cmd; | ||
112 | if ( command.isEmpty() ) | 114 | if ( command.isEmpty() ) | ||
113 | return nullptr; | 115 | return; | ||
114 | if ( !userId.isEmpty()) { | 116 | if ( !userId.isEmpty()) { | ||
115 | struct passwd* pw = getpwuid( getuid()); | 117 | struct passwd* pw = getpwuid( getuid()); | ||
116 | if( pw != nullptr && userId != QString::fromLocal8Bit( pw->pw_name )) { | 118 | if( pw != nullptr && userId != QString::fromLocal8Bit( pw->pw_name )) { | ||
117 | command.prepend( QStringLiteral("--") ); | 119 | command.prepend( QStringLiteral("--") ); | ||
118 | command.prepend( userId ); | 120 | command.prepend( userId ); | ||
119 | command.prepend( QStringLiteral("-u") ); | 121 | command.prepend( QStringLiteral("-u") ); | ||
120 | command.prepend( QStandardPaths::findExecutable(QStringLiteral("kdesu"))); | 122 | command.prepend( QStandardPaths::findExecutable(QStringLiteral("kdesu"))); | ||
121 | } | 123 | } | ||
122 | } | 124 | } | ||
123 | if ( !clientMachine.isEmpty() && clientMachine != QLatin1String("localhost") ) { | 125 | if ( !clientMachine.isEmpty() && clientMachine != QLatin1String("localhost") ) { | ||
124 | command.prepend( clientMachine ); | 126 | command.prepend( clientMachine ); | ||
125 | command.prepend( xonCommand ); // "xon" by default | 127 | command.prepend( xonCommand ); // "xon" by default | ||
126 | } | 128 | } | ||
127 | 129 | | |||
128 | // TODO this function actually should not use KProcess at all and use klauncher (kdeinit) instead. | 130 | const QString app = command.takeFirst(); | ||
129 | // Klauncher should also have support for tracking whether the launched process is still alive | 131 | const QStringList argList = command; | ||
130 | // or not, so this should be redone. For now, use KProcess for wm's, as they need to be tracked, | 132 | auto *job = new KIO::CommandLauncherJob(app, argList); | ||
131 | // klauncher for the rest where ksmserver doesn't care. | 133 | job->start(); | ||
132 | if( wm ) { | | |||
133 | KProcess* process = new KProcess( this ); | | |||
134 | *process << command; | | |||
135 | // make it auto-delete | | |||
136 | connect(process, static_cast<void (KProcess::*)(QProcess::ProcessError)>(&KProcess::error), process, &KProcess::deleteLater); | | |||
137 | connect(process, static_cast<void (KProcess::*)(int, QProcess::ExitStatus)>(&KProcess::finished), process, &KProcess::deleteLater); | | |||
138 | process->start(); | | |||
139 | return process; | | |||
140 | } else { | | |||
141 | int n = command.count(); | | |||
142 | org::kde::KLauncher klauncher(QStringLiteral("org.kde.klauncher5"), | | |||
143 | QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); | | |||
144 | QString app = command[0]; | | |||
145 | QStringList argList; | | |||
146 | for ( int i=1; i < n; i++) | | |||
147 | argList.append( command[i]); | | |||
148 | klauncher.exec_blind(app, argList ); | | |||
149 | return nullptr; | | |||
150 | } | | |||
151 | } | 134 | } | ||
dfaure: (pre-existing) argList = command; argList.removeFirst(); would be simpler and faster. | |||||
152 | 135 | | |||
153 | /*! Utility function to execute a command on the local machine. Used | 136 | /*! Utility function to execute a command on the local machine. Used | ||
154 | * to discard session data | 137 | * to discard session data | ||
dfaure: This return statement serves no purpose. | |||||
155 | */ | 138 | */ | ||
156 | void KSMServer::executeCommand( const QStringList& command ) | 139 | void KSMServer::executeCommand( const QStringList& command ) | ||
157 | { | 140 | { | ||
158 | if ( command.isEmpty() ) | 141 | if ( command.isEmpty() ) | ||
159 | return; | 142 | return; | ||
160 | 143 | | |||
161 | KProcess::execute( command ); | 144 | KProcess::execute( command ); | ||
162 | } | 145 | } | ||
▲ Show 20 Lines • Show All 987 Lines • Show Last 20 Lines |
(pre-existing) argList = command; argList.removeFirst(); would be simpler and faster.