1324.patch 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. From adfaa222fdfa6115ea2b320b0bbc2126db9270a5 Mon Sep 17 00:00:00 2001
  2. From: Fabian Vogt <fabian@ritter-vogt.de>
  3. Date: Thu, 12 Nov 2020 20:30:55 +0100
  4. Subject: [PATCH 1/3] Retry starting the display server
  5. Even if the CanGraphical property of a Seat is true, it's possible that it's
  6. still too early for X to start, as it might need some driver or device which
  7. isn't present yet.
  8. Fixes #1316
  9. ---
  10. src/daemon/Seat.cpp | 23 ++++++++++++++++++-----
  11. src/daemon/Seat.h | 4 +++-
  12. src/daemon/XorgDisplayServer.cpp | 10 ++++++----
  13. 3 files changed, 27 insertions(+), 10 deletions(-)
  14. diff --git a/src/daemon/Seat.cpp b/src/daemon/Seat.cpp
  15. index eef26da45..838c2221d 100644
  16. --- a/src/daemon/Seat.cpp
  17. +++ b/src/daemon/Seat.cpp
  18. @@ -28,6 +28,7 @@
  19. #include <QDebug>
  20. #include <QFile>
  21. +#include <QTimer>
  22. #include <functional>
  23. @@ -52,7 +53,7 @@ namespace SDDM {
  24. return m_name;
  25. }
  26. - bool Seat::createDisplay(int terminalId) {
  27. + void Seat::createDisplay(int terminalId) {
  28. //reload config if needed
  29. mainConfig.load();
  30. @@ -84,12 +85,24 @@ namespace SDDM {
  31. m_displays << display;
  32. // start the display
  33. - if (!display->start()) {
  34. - qCritical() << "Could not start Display server on vt" << terminalId;
  35. - return false;
  36. + startDisplay(display);
  37. + }
  38. +
  39. + void Seat::startDisplay(Display *display, int tryNr) {
  40. + if (display->start())
  41. + return;
  42. +
  43. + // It's possible that the system isn't ready yet (driver not loaded,
  44. + // device not enumerated, ...). It's not possible to tell when that changes,
  45. + // so try a few times with a delay in between.
  46. + qWarning() << "Attempt" << tryNr << "starting the Display server on vt" << display->terminalId() << "failed";
  47. +
  48. + if(tryNr >= 3) {
  49. + qCritical() << "Could not start Display server on vt" << display->terminalId();
  50. + return;
  51. }
  52. - return true;
  53. + QTimer::singleShot(2000, display, [=] { startDisplay(display, tryNr + 1); });
  54. }
  55. void Seat::removeDisplay(Display* display) {
  56. diff --git a/src/daemon/Seat.h b/src/daemon/Seat.h
  57. index bf22566b7..f9fe7331f 100644
  58. --- a/src/daemon/Seat.h
  59. +++ b/src/daemon/Seat.h
  60. @@ -35,13 +35,15 @@ namespace SDDM {
  61. const QString &name() const;
  62. public slots:
  63. - bool createDisplay(int terminalId = -1);
  64. + void createDisplay(int terminalId = -1);
  65. void removeDisplay(SDDM::Display* display);
  66. private slots:
  67. void displayStopped();
  68. private:
  69. + void startDisplay(SDDM::Display *display, int tryNr = 1);
  70. +
  71. QString m_name;
  72. QVector<Display *> m_displays;
  73. diff --git a/src/daemon/XorgDisplayServer.cpp b/src/daemon/XorgDisplayServer.cpp
  74. index e60c02210..5f40fe8c3 100644
  75. --- a/src/daemon/XorgDisplayServer.cpp
  76. +++ b/src/daemon/XorgDisplayServer.cpp
  77. @@ -248,6 +248,12 @@ namespace SDDM {
  78. }
  79. void XorgDisplayServer::finished() {
  80. + // clean up
  81. + if (process) {
  82. + process->deleteLater();
  83. + process = nullptr;
  84. + }
  85. +
  86. // check flag
  87. if (!m_started)
  88. return;
  89. @@ -283,10 +289,6 @@ namespace SDDM {
  90. displayStopScript->deleteLater();
  91. displayStopScript = nullptr;
  92. - // clean up
  93. - process->deleteLater();
  94. - process = nullptr;
  95. -
  96. // remove authority file
  97. QFile::remove(m_authPath);
  98. From d11e1e987b440fa1aaa741719b92472eeee79b17 Mon Sep 17 00:00:00 2001
  99. From: Fabian Vogt <fabian@ritter-vogt.de>
  100. Date: Wed, 9 Dec 2020 19:28:41 +0100
  101. Subject: [PATCH 2/3] Explicitly stop Xorg when starting fails
  102. When Xorg starts but there is an error, stop it explicitly instead of assuming
  103. that X exits itself. This avoids a possibly lingering Xorg process in the
  104. XorgDisplayServer instance. Add a check and warning message if Xorg is
  105. restarted too early (shouldn't happen).
  106. ---
  107. src/daemon/XorgDisplayServer.cpp | 11 +++++++++--
  108. 1 file changed, 9 insertions(+), 2 deletions(-)
  109. diff --git a/src/daemon/XorgDisplayServer.cpp b/src/daemon/XorgDisplayServer.cpp
  110. index 5f40fe8c3..3a7bee0d8 100644
  111. --- a/src/daemon/XorgDisplayServer.cpp
  112. +++ b/src/daemon/XorgDisplayServer.cpp
  113. @@ -118,6 +118,11 @@ namespace SDDM {
  114. if (m_started)
  115. return false;
  116. + if (process) {
  117. + qCritical() << "Tried to start Xorg before previous instance exited";
  118. + return false;
  119. + }
  120. +
  121. // create process
  122. process = new QProcess(this);
  123. @@ -195,6 +200,7 @@ namespace SDDM {
  124. qCritical("Failed to open pipe to start X Server");
  125. close(pipeFds[0]);
  126. + stop();
  127. return false;
  128. }
  129. QByteArray displayNumber = readPipe.readLine();
  130. @@ -203,6 +209,7 @@ namespace SDDM {
  131. qCritical("Failed to read display number from pipe");
  132. close(pipeFds[0]);
  133. + stop();
  134. return false;
  135. }
  136. displayNumber.prepend(QByteArray(":"));
  137. @@ -219,6 +226,7 @@ namespace SDDM {
  138. if(m_display != QStringLiteral(":0")) {
  139. if(!addCookie(m_authPath)) {
  140. qCritical() << "Failed to write xauth file";
  141. + stop();
  142. return false;
  143. }
  144. }
  145. @@ -232,8 +240,7 @@ namespace SDDM {
  146. }
  147. void XorgDisplayServer::stop() {
  148. - // check flag
  149. - if (!m_started)
  150. + if (!process)
  151. return;
  152. // log message
  153. From 78048b22e3988d3daec9c271883fa114abc114dc Mon Sep 17 00:00:00 2001
  154. From: Fabian Vogt <fabian@ritter-vogt.de>
  155. Date: Wed, 9 Dec 2020 19:33:08 +0100
  156. Subject: [PATCH 3/3] Emit XorgDisplayServer::started only when the auth file
  157. is ready
  158. ---
  159. src/daemon/XorgDisplayServer.cpp | 4 ++--
  160. 1 file changed, 2 insertions(+), 2 deletions(-)
  161. diff --git a/src/daemon/XorgDisplayServer.cpp b/src/daemon/XorgDisplayServer.cpp
  162. index 3a7bee0d8..331adcda7 100644
  163. --- a/src/daemon/XorgDisplayServer.cpp
  164. +++ b/src/daemon/XorgDisplayServer.cpp
  165. @@ -219,8 +219,6 @@ namespace SDDM {
  166. // close our pipe
  167. close(pipeFds[0]);
  168. - emit started();
  169. -
  170. // The file is also used by the greeter, which does care about the
  171. // display number. Write the proper entry, if it's different.
  172. if(m_display != QStringLiteral(":0")) {
  173. @@ -232,6 +230,8 @@ namespace SDDM {
  174. }
  175. changeOwner(m_authPath);
  176. + emit started();
  177. +
  178. // set flag
  179. m_started = true;