Changeset View
Changeset View
Standalone View
Standalone View
startkde/plasma-session/startup.cpp
Show First 20 Lines • Show All 201 Lines • ▼ Show 20 Line(s) | 201 | { | |||
---|---|---|---|---|---|
202 | new StartupAdaptor(this); | 202 | new StartupAdaptor(this); | ||
203 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/Startup"), QStringLiteral("org.kde.Startup"), this); | 203 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/Startup"), QStringLiteral("org.kde.Startup"), this); | ||
204 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.Startup")); | 204 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.Startup")); | ||
205 | 205 | | |||
206 | upAndRunning(QStringLiteral("ksmserver")); | 206 | upAndRunning(QStringLiteral("ksmserver")); | ||
207 | const AutoStart autostart; | 207 | const AutoStart autostart; | ||
208 | 208 | | |||
209 | KJob* phase1; | 209 | KJob* phase1; | ||
210 | QProcessEnvironment kdedEnv = QProcessEnvironment::systemEnvironment(); | ||||
211 | kdedEnv.insert(QStringLiteral("KDED_STARTED_BY_KDEINIT"), QStringLiteral("1")); | ||||
fvogt: This (and below) are started with an empty environment, which means that neither `DISPLAY`… | |||||
StartProcessJob I think is fine. It's not set, so it'll inherit. It's the extra arg to StartServiceJob that has potential to wipe the env. It defaults to empty and we do p->setEnvironment(m_env); davidedmundson: StartProcessJob I think is fine. It's not set, so it'll inherit.
It's the extra arg to… | |||||
It is set in line 440, which defaults to empty (line 90 in the header) as well. fvogt: > StartProcessJob I think is fine. It's not set, so it'll inherit.
It is set in line 440… | |||||
210 | const QVector<KJob*> sequence = { | 212 | const QVector<KJob*> sequence = { | ||
211 | new StartProcessJob(QStringLiteral("kcminit_startup"), {}), | 213 | new StartProcessJob(QStringLiteral("kcminit_startup"), {}), | ||
212 | new StartServiceJob(QStringLiteral("kded5"), {}, QStringLiteral("org.kde.kded"), QProcess::systemEnvironment() << QStringList{ QStringLiteral("KDED_STARTED_BY_KDEINIT=1") }), | 214 | new StartServiceJob(QStringLiteral("kded5"), {}, QStringLiteral("org.kde.kded5"), kdedEnv), | ||
213 | new StartServiceJob(QStringLiteral("ksmserver"), QCoreApplication::instance()->arguments().mid(1), QStringLiteral("org.kde.ksmserver")), | 215 | new StartServiceJob(QStringLiteral("ksmserver"), QCoreApplication::instance()->arguments().mid(1), QStringLiteral("org.kde.ksmserver")), | ||
214 | new StartupPhase0(autostart, this), | 216 | new StartupPhase0(autostart, this), | ||
215 | phase1 = new StartupPhase1(autostart, this), | 217 | phase1 = new StartupPhase1(autostart, this), | ||
216 | new RestoreSessionJob(), | 218 | new RestoreSessionJob(), | ||
217 | new StartupPhase2(autostart, this), | 219 | new StartupPhase2(autostart, this), | ||
218 | }; | 220 | }; | ||
219 | KJob* last = nullptr; | 221 | KJob* last = nullptr; | ||
220 | for(KJob* job : sequence) { | 222 | for(KJob* job : sequence) { | ||
221 | if (last) { | 223 | if (last) { | ||
222 | connect(last, &KJob::finished, job, &KJob::start); | 224 | connect(last, &KJob::finished, job, &KJob::start); | ||
223 | } | 225 | } | ||
224 | last = job; | 226 | last = job; | ||
225 | } | 227 | } | ||
226 | 228 | | |||
227 | connect(phase1, &KJob::finished, this, []() { | 229 | connect(phase1, &KJob::finished, this, []() { | ||
228 | NotificationThread *loginSound = new NotificationThread(); | 230 | NotificationThread *loginSound = new NotificationThread(); | ||
229 | connect(loginSound, &NotificationThread::finished, loginSound, &NotificationThread::deleteLater); | 231 | connect(loginSound, &NotificationThread::finished, loginSound, &NotificationThread::deleteLater); | ||
230 | loginSound->start(); | 232 | loginSound->start(); | ||
231 | }); | 233 | }); | ||
apol: Unrelated change. | |||||
232 | 234 | | |||
233 | connect(sequence.last(), &KJob::finished, this, &Startup::finishStartup); | 235 | connect(sequence.last(), &KJob::finished, this, &Startup::finishStartup); | ||
234 | sequence.first()->start(); | 236 | sequence.first()->start(); | ||
235 | } | 237 | } | ||
236 | 238 | | |||
237 | void Startup::upAndRunning( const QString& msg ) | 239 | void Startup::upAndRunning( const QString& msg ) | ||
238 | { | 240 | { | ||
239 | QDBusMessage ksplashProgressMessage = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KSplash"), | 241 | QDBusMessage ksplashProgressMessage = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KSplash"), | ||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Line(s) | 389 | do { | |||
404 | auto program = arguments.takeFirst(); | 406 | auto program = arguments.takeFirst(); | ||
405 | if (!QProcess::startDetached(program, arguments)) | 407 | if (!QProcess::startDetached(program, arguments)) | ||
406 | qCWarning(PLASMA_SESSION) << "could not start" << serviceName << ":" << program << arguments; | 408 | qCWarning(PLASMA_SESSION) << "could not start" << serviceName << ":" << program << arguments; | ||
407 | } while (true); | 409 | } while (true); | ||
408 | }); | 410 | }); | ||
409 | } | 411 | } | ||
410 | 412 | | |||
411 | 413 | | |||
412 | StartServiceJob::StartServiceJob(const QString &process, const QStringList &args, const QString &serviceId, const QStringList &env): | 414 | StartServiceJob::StartServiceJob(const QString &process, const QStringList &args, const QString &serviceId, const QProcessEnvironment &env): | ||
413 | KJob(), | 415 | KJob(), | ||
414 | m_process(process), | 416 | m_process(process), | ||
415 | m_args(args), | 417 | m_args(args), | ||
416 | m_env(env) | 418 | m_env(env) | ||
417 | { | 419 | { | ||
418 | auto watcher = new QDBusServiceWatcher(serviceId, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration, this); | 420 | auto watcher = new QDBusServiceWatcher(serviceId, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration, this); | ||
419 | connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &StartServiceJob::emitResult); | 421 | connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &StartServiceJob::emitResult); | ||
420 | } | 422 | } | ||
Maybe it would make sense to do the merging of envs here? This way we only set when it's necessary. apol: Maybe it would make sense to do the merging of envs here? This way we only set when it's… | |||||
apol: only do it `if (!additionalEnv.isEmpty())` | |||||
421 | 423 | | |||
422 | void StartServiceJob::start() | 424 | void StartServiceJob::start() | ||
423 | { | 425 | { | ||
426 | qCDebug(PLASMA_SESSION) << "Starting " << m_process << m_args; | ||||
424 | QProcess* p = new QProcess(this); | 427 | QProcess* p = new QProcess(this); | ||
425 | p->setEnvironment(m_env); | 428 | p->setProcessEnvironment(m_env); | ||
426 | if (!p->startDetached(m_process, m_args)) | 429 | if (!p->startDetached(m_process, m_args)) | ||
427 | qCWarning(PLASMA_SESSION) << "error starting process" << m_process << m_args; | 430 | qCWarning(PLASMA_SESSION) << "error starting process" << m_process << m_args; | ||
428 | 431 | | |||
429 | connect(p, &QProcess::errorOccurred, this, [this] (QProcess::ProcessError error) { | 432 | connect(p, &QProcess::errorOccurred, this, [this] (QProcess::ProcessError error) { | ||
430 | qCWarning(PLASMA_SESSION) << "error on process" << error << m_process << m_args; | 433 | qCWarning(PLASMA_SESSION) << "error on process" << error << m_process << m_args; | ||
431 | }); | 434 | }); | ||
432 | } | 435 | } | ||
433 | 436 | | |||
434 | StartProcessJob::StartProcessJob(const QString &process, const QStringList &args, const QStringList &env) | 437 | StartProcessJob::StartProcessJob(const QString &process, const QStringList &args, const QProcessEnvironment &env) | ||
435 | : KJob() | 438 | : KJob() | ||
436 | , m_process(new QProcess(this)) | 439 | , m_process(new QProcess(this)) | ||
437 | { | 440 | { | ||
438 | m_process->setProgram(process); | 441 | m_process->setProgram(process); | ||
439 | m_process->setArguments(args); | 442 | m_process->setArguments(args); | ||
440 | m_process->setEnvironment(env); | 443 | m_process->setProcessEnvironment(env); | ||
441 | 444 | | |||
442 | connect(m_process, &QProcess::errorOccurred, this, [process, args] (QProcess::ProcessError error) { | 445 | connect(m_process, static_cast<void (QProcess::*)(int)>(&QProcess::finished), [this](int exitCode) { | ||
443 | qCWarning(PLASMA_SESSION) << "error starting process" << error << process << args; | 446 | qCInfo(PLASMA_SESSION) << "process job " << m_process->program() << "finished with exit code " << exitCode; | ||
447 | emitResult(); | ||||
444 | }); | 448 | }); | ||
445 | connect(m_process, &QProcess::started, this, &StartProcessJob::emitResult); | | |||
446 | } | 449 | } | ||
447 | 450 | | |||
448 | void StartProcessJob::start() | 451 | void StartProcessJob::start() | ||
449 | { | 452 | { | ||
450 | if (!m_process->startDetached()) | 453 | qCDebug(PLASMA_SESSION) << "Starting " << m_process->program() << m_process->arguments(); | ||
451 | qCWarning(PLASMA_SESSION) << "error starting process" << m_process->program(); | 454 | | ||
455 | m_process->start(); | ||||
452 | } | 456 | } | ||
453 | 457 | | |||
apol: only do it if (!additionalEnv.isEmpty())
| |||||
454 | #include "startup.moc" | 458 | #include "startup.moc" |
This (and below) are started with an empty environment, which means that neither DISPLAY, WAYLAND_DISPLAY or XAUTHORITY are set. So everything breaks horribly, as seen by @lbeltrame and openQA.