sddm-fix-race-pre.patch 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. From 68cc9e31d1a4c4609f42114782fc485cb07353a4 Mon Sep 17 00:00:00 2001
  2. From: Fabian Vogt <fabian@ritter-vogt.de>
  3. Date: Fri, 9 Oct 2020 21:06:01 +0200
  4. Subject: [PATCH] Merge normal and testing paths in XorgDisplayServer::start
  5. They have much in common and this means that Xephyr can also make use use
  6. of -displayfd now.
  7. ---
  8. src/daemon/XorgDisplayServer.cpp | 132 ++++++++++++++-----------------
  9. 1 file changed, 60 insertions(+), 72 deletions(-)
  10. diff --git a/src/daemon/XorgDisplayServer.cpp b/src/daemon/XorgDisplayServer.cpp
  11. index d5f29a94..e60c0221 100644
  12. --- a/src/daemon/XorgDisplayServer.cpp
  13. +++ b/src/daemon/XorgDisplayServer.cpp
  14. @@ -136,95 +136,83 @@ namespace SDDM {
  15. return false;
  16. }
  17. - if (daemonApp->testing()) {
  18. - QStringList args;
  19. - QDir x11socketDir(QStringLiteral("/tmp/.X11-unix"));
  20. - int display = 100;
  21. - while (x11socketDir.exists(QStringLiteral("X%1").arg(display))) {
  22. - ++display;
  23. - }
  24. - m_display = QStringLiteral(":%1").arg(display);
  25. - args << m_display << QStringLiteral("-auth") << m_authPath << QStringLiteral("-br") << QStringLiteral("-noreset") << QStringLiteral("-screen") << QStringLiteral("800x600");
  26. - process->start(mainConfig.X11.XephyrPath.get(), args);
  27. -
  28. -
  29. - // wait for display server to start
  30. - if (!process->waitForStarted()) {
  31. - // log message
  32. - qCritical() << "Failed to start display server process.";
  33. + // set process environment
  34. + QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  35. + env.insert(QStringLiteral("XCURSOR_THEME"), mainConfig.Theme.CursorTheme.get());
  36. + process->setProcessEnvironment(env);
  37. - // return fail
  38. - return false;
  39. - }
  40. - emit started();
  41. - } else {
  42. - // set process environment
  43. - QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  44. - env.insert(QStringLiteral("XCURSOR_THEME"), mainConfig.Theme.CursorTheme.get());
  45. - process->setProcessEnvironment(env);
  46. -
  47. - //create pipe for communicating with X server
  48. - //0 == read from X, 1== write to from X
  49. - int pipeFds[2];
  50. - if (pipe(pipeFds) != 0) {
  51. - qCritical("Could not create pipe to start X server");
  52. - }
  53. + //create pipe for communicating with X server
  54. + //0 == read from X, 1== write to from X
  55. + int pipeFds[2];
  56. + if (pipe(pipeFds) != 0) {
  57. + qCritical("Could not create pipe to start X server");
  58. + }
  59. - // start display server
  60. - QStringList args = mainConfig.X11.ServerArguments.get().split(QLatin1Char(' '), QString::SkipEmptyParts);
  61. - args << QStringLiteral("-auth") << m_authPath
  62. + // start display server
  63. + QStringList args;
  64. + if (!daemonApp->testing()) {
  65. + process->setProgram(mainConfig.X11.ServerPath.get());
  66. + args << mainConfig.X11.ServerArguments.get().split(QLatin1Char(' '), QString::SkipEmptyParts)
  67. << QStringLiteral("-background") << QStringLiteral("none")
  68. - << QStringLiteral("-noreset")
  69. - << QStringLiteral("-displayfd") << QString::number(pipeFds[1])
  70. << QStringLiteral("-seat") << displayPtr()->seat()->name();
  71. if (displayPtr()->seat()->name() == QLatin1String("seat0")) {
  72. args << QStringLiteral("vt%1").arg(displayPtr()->terminalId());
  73. }
  74. - qDebug() << "Running:"
  75. - << qPrintable(mainConfig.X11.ServerPath.get())
  76. - << qPrintable(args.join(QLatin1Char(' ')));
  77. - process->start(mainConfig.X11.ServerPath.get(), args);
  78. -
  79. - // wait for display server to start
  80. - if (!process->waitForStarted()) {
  81. - // log message
  82. - qCritical() << "Failed to start display server process.";
  83. -
  84. - // return fail
  85. - close(pipeFds[0]);
  86. - return false;
  87. - }
  88. + } else {
  89. + process->setProgram(mainConfig.X11.XephyrPath.get());
  90. + args << QStringLiteral("-br")
  91. + << QStringLiteral("-screen") << QStringLiteral("800x600");
  92. + }
  93. - // close the other side of pipe in our process, otherwise reading
  94. - // from it may stuck even X server exit.
  95. - close(pipeFds[1]);
  96. + args << QStringLiteral("-auth") << m_authPath
  97. + << QStringLiteral("-noreset")
  98. + << QStringLiteral("-displayfd") << QString::number(pipeFds[1]);
  99. - QFile readPipe;
  100. + process->setArguments(args);
  101. + qDebug() << "Running:"
  102. + << qPrintable(process->program())
  103. + << qPrintable(process->arguments().join(QLatin1Char(' ')));
  104. + process->start();
  105. - if (!readPipe.open(pipeFds[0], QIODevice::ReadOnly)) {
  106. - qCritical("Failed to open pipe to start X Server");
  107. + // wait for display server to start
  108. + if (!process->waitForStarted()) {
  109. + // log message
  110. + qCritical() << "Failed to start display server process.";
  111. - close(pipeFds[0]);
  112. - return false;
  113. - }
  114. - QByteArray displayNumber = readPipe.readLine();
  115. - if (displayNumber.size() < 2) {
  116. - // X server gave nothing (or a whitespace).
  117. - qCritical("Failed to read display number from pipe");
  118. + // return fail
  119. + close(pipeFds[0]);
  120. + return false;
  121. + }
  122. - close(pipeFds[0]);
  123. - return false;
  124. - }
  125. - displayNumber.prepend(QByteArray(":"));
  126. - displayNumber.remove(displayNumber.size() -1, 1); // trim trailing whitespace
  127. - m_display = QString::fromLocal8Bit(displayNumber);
  128. + // close the other side of pipe in our process, otherwise reading
  129. + // from it may stuck even X server exit.
  130. + close(pipeFds[1]);
  131. +
  132. + QFile readPipe;
  133. +
  134. + if (!readPipe.open(pipeFds[0], QIODevice::ReadOnly)) {
  135. + qCritical("Failed to open pipe to start X Server");
  136. - // close our pipe
  137. close(pipeFds[0]);
  138. + return false;
  139. + }
  140. + QByteArray displayNumber = readPipe.readLine();
  141. + if (displayNumber.size() < 2) {
  142. + // X server gave nothing (or a whitespace).
  143. + qCritical("Failed to read display number from pipe");
  144. - emit started();
  145. + close(pipeFds[0]);
  146. + return false;
  147. }
  148. + displayNumber.prepend(QByteArray(":"));
  149. + displayNumber.remove(displayNumber.size() -1, 1); // trim trailing whitespace
  150. + m_display = QString::fromLocal8Bit(displayNumber);
  151. +
  152. + // close our pipe
  153. + close(pipeFds[0]);
  154. +
  155. + emit started();
  156. // The file is also used by the greeter, which does care about the
  157. // display number. Write the proper entry, if it's different.