123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- From 68cc9e31d1a4c4609f42114782fc485cb07353a4 Mon Sep 17 00:00:00 2001
- From: Fabian Vogt <fabian@ritter-vogt.de>
- Date: Fri, 9 Oct 2020 21:06:01 +0200
- Subject: [PATCH] Merge normal and testing paths in XorgDisplayServer::start
- They have much in common and this means that Xephyr can also make use use
- of -displayfd now.
- ---
- src/daemon/XorgDisplayServer.cpp | 132 ++++++++++++++-----------------
- 1 file changed, 60 insertions(+), 72 deletions(-)
- diff --git a/src/daemon/XorgDisplayServer.cpp b/src/daemon/XorgDisplayServer.cpp
- index d5f29a94a..e60c02210 100644
- --- a/src/daemon/XorgDisplayServer.cpp
- +++ b/src/daemon/XorgDisplayServer.cpp
- @@ -136,95 +136,83 @@ namespace SDDM {
- return false;
- }
-
- - if (daemonApp->testing()) {
- - QStringList args;
- - QDir x11socketDir(QStringLiteral("/tmp/.X11-unix"));
- - int display = 100;
- - while (x11socketDir.exists(QStringLiteral("X%1").arg(display))) {
- - ++display;
- - }
- - m_display = QStringLiteral(":%1").arg(display);
- - args << m_display << QStringLiteral("-auth") << m_authPath << QStringLiteral("-br") << QStringLiteral("-noreset") << QStringLiteral("-screen") << QStringLiteral("800x600");
- - process->start(mainConfig.X11.XephyrPath.get(), args);
- -
- -
- - // wait for display server to start
- - if (!process->waitForStarted()) {
- - // log message
- - qCritical() << "Failed to start display server process.";
- + // set process environment
- + QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
- + env.insert(QStringLiteral("XCURSOR_THEME"), mainConfig.Theme.CursorTheme.get());
- + process->setProcessEnvironment(env);
-
- - // return fail
- - return false;
- - }
- - emit started();
- - } else {
- - // set process environment
- - QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
- - env.insert(QStringLiteral("XCURSOR_THEME"), mainConfig.Theme.CursorTheme.get());
- - process->setProcessEnvironment(env);
- -
- - //create pipe for communicating with X server
- - //0 == read from X, 1== write to from X
- - int pipeFds[2];
- - if (pipe(pipeFds) != 0) {
- - qCritical("Could not create pipe to start X server");
- - }
- + //create pipe for communicating with X server
- + //0 == read from X, 1== write to from X
- + int pipeFds[2];
- + if (pipe(pipeFds) != 0) {
- + qCritical("Could not create pipe to start X server");
- + }
-
- - // start display server
- - QStringList args = mainConfig.X11.ServerArguments.get().split(QLatin1Char(' '), QString::SkipEmptyParts);
- - args << QStringLiteral("-auth") << m_authPath
- + // start display server
- + QStringList args;
- + if (!daemonApp->testing()) {
- + process->setProgram(mainConfig.X11.ServerPath.get());
- + args << mainConfig.X11.ServerArguments.get().split(QLatin1Char(' '), QString::SkipEmptyParts)
- << QStringLiteral("-background") << QStringLiteral("none")
- - << QStringLiteral("-noreset")
- - << QStringLiteral("-displayfd") << QString::number(pipeFds[1])
- << QStringLiteral("-seat") << displayPtr()->seat()->name();
-
- if (displayPtr()->seat()->name() == QLatin1String("seat0")) {
- args << QStringLiteral("vt%1").arg(displayPtr()->terminalId());
- }
- - qDebug() << "Running:"
- - << qPrintable(mainConfig.X11.ServerPath.get())
- - << qPrintable(args.join(QLatin1Char(' ')));
- - process->start(mainConfig.X11.ServerPath.get(), args);
- -
- - // wait for display server to start
- - if (!process->waitForStarted()) {
- - // log message
- - qCritical() << "Failed to start display server process.";
- -
- - // return fail
- - close(pipeFds[0]);
- - return false;
- - }
- + } else {
- + process->setProgram(mainConfig.X11.XephyrPath.get());
- + args << QStringLiteral("-br")
- + << QStringLiteral("-screen") << QStringLiteral("800x600");
- + }
-
- - // close the other side of pipe in our process, otherwise reading
- - // from it may stuck even X server exit.
- - close(pipeFds[1]);
- + args << QStringLiteral("-auth") << m_authPath
- + << QStringLiteral("-noreset")
- + << QStringLiteral("-displayfd") << QString::number(pipeFds[1]);
-
- - QFile readPipe;
- + process->setArguments(args);
- + qDebug() << "Running:"
- + << qPrintable(process->program())
- + << qPrintable(process->arguments().join(QLatin1Char(' ')));
- + process->start();
-
- - if (!readPipe.open(pipeFds[0], QIODevice::ReadOnly)) {
- - qCritical("Failed to open pipe to start X Server");
- + // wait for display server to start
- + if (!process->waitForStarted()) {
- + // log message
- + qCritical() << "Failed to start display server process.";
-
- - close(pipeFds[0]);
- - return false;
- - }
- - QByteArray displayNumber = readPipe.readLine();
- - if (displayNumber.size() < 2) {
- - // X server gave nothing (or a whitespace).
- - qCritical("Failed to read display number from pipe");
- + // return fail
- + close(pipeFds[0]);
- + return false;
- + }
-
- - close(pipeFds[0]);
- - return false;
- - }
- - displayNumber.prepend(QByteArray(":"));
- - displayNumber.remove(displayNumber.size() -1, 1); // trim trailing whitespace
- - m_display = QString::fromLocal8Bit(displayNumber);
- + // close the other side of pipe in our process, otherwise reading
- + // from it may stuck even X server exit.
- + close(pipeFds[1]);
- +
- + QFile readPipe;
- +
- + if (!readPipe.open(pipeFds[0], QIODevice::ReadOnly)) {
- + qCritical("Failed to open pipe to start X Server");
-
- - // close our pipe
- close(pipeFds[0]);
- + return false;
- + }
- + QByteArray displayNumber = readPipe.readLine();
- + if (displayNumber.size() < 2) {
- + // X server gave nothing (or a whitespace).
- + qCritical("Failed to read display number from pipe");
-
- - emit started();
- + close(pipeFds[0]);
- + return false;
- }
- + displayNumber.prepend(QByteArray(":"));
- + displayNumber.remove(displayNumber.size() -1, 1); // trim trailing whitespace
- + m_display = QString::fromLocal8Bit(displayNumber);
- +
- + // close our pipe
- + close(pipeFds[0]);
- +
- + emit started();
-
- // The file is also used by the greeter, which does care about the
- // display number. Write the proper entry, if it's different.
|