Skip to content

Commit b3ceaa7

Browse files
committed
feat: Starting X11 dde-session using ddm
This commit modifies X11DisplayServerType to start X11 with ddm. It use treeland as greeter to handle user login. Once user logged in, it kills the wayland compositor and start the X11 server. To test, change the General -> DisplayServer field of /etc/ddm.conf to "x11".
1 parent b0bf6e9 commit b3ceaa7

File tree

9 files changed

+107
-21
lines changed

9 files changed

+107
-21
lines changed

data/scripts/Xsetup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22
# Xsetup - run as root before the login dialog appears
3-
3+
xhost +

src/auth/Auth.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ namespace DDM {
6565
QLocalSocket *socket { nullptr };
6666
QString displayServerCmd;
6767
QString sessionPath { };
68+
Session::Type sessionType { Session::UnknownSession };
6869
QString user { };
6970
QString password { };
7071
QByteArray cookie { };
7172
bool autologin { false };
7273
bool greeter { false };
7374
bool singleMode { false };
7475
bool identifyOnly { false };
76+
bool skipAuth { false };
7577
QProcessEnvironment environment { };
7678
qint64 id { 0 };
7779
static qint64 lastId;
@@ -317,6 +319,14 @@ namespace DDM {
317319
return d->sessionId;
318320
}
319321

322+
Session::Type Auth::sessionType() const {
323+
return d->sessionType;
324+
}
325+
326+
bool Auth::isSingleMode() const {
327+
return d->singleMode;
328+
}
329+
320330
bool Auth::isActive() const {
321331
return d->child->state() != QProcess::NotRunning;
322332
}
@@ -394,6 +404,11 @@ namespace DDM {
394404
}
395405
}
396406

407+
void Auth::setSessionType(const Session::Type type) {
408+
if (type != d->sessionType)
409+
d->sessionType = type;
410+
}
411+
397412
int Auth::tty() const {
398413
return d->tty;
399414
}
@@ -424,6 +439,12 @@ namespace DDM {
424439
}
425440
}
426441

442+
void Auth::setSkipAuth(bool on) {
443+
if (on != d->skipAuth) {
444+
d->skipAuth = on;
445+
}
446+
}
447+
427448
void Auth::start() {
428449
QStringList args;
429450
args << QStringLiteral("--socket") << SocketServer::instance()->fullServerName();
@@ -442,6 +463,8 @@ namespace DDM {
442463
args << QStringLiteral("--single-mode");
443464
if (d->identifyOnly)
444465
args << QStringLiteral("--identify-only");
466+
if (d->skipAuth)
467+
args << QStringLiteral("--skip-auth");
445468
d->child->start(QStringLiteral("%1/ddm-helper").arg(QStringLiteral(LIBEXEC_INSTALL_DIR)), args);
446469
}
447470

@@ -453,7 +476,7 @@ namespace DDM {
453476
d->child->terminate();
454477

455478
// wait for finished
456-
if (!d->child->waitForFinished(5000))
479+
if (!d->child->waitForFinished(500))
457480
d->child->kill();
458481
}
459482
}

src/auth/Auth.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "AuthRequest.h"
2525
#include "AuthPrompt.h"
26+
#include "Session.h"
2627

2728
#include <QtCore/QObject>
2829
#include <QtCore/QProcessEnvironment>
@@ -97,12 +98,14 @@ namespace DDM {
9798
bool isGreeter() const;
9899
bool verbose() const;
99100
bool identifyOnly() const;
101+
bool isSingleMode() const;
100102
const QByteArray &cookie() const;
101103
const QString &user() const;
102104
const QString &session() const;
103105
const QString &password() const;
104106
AuthRequest *request();
105107
QString sessionId() const;
108+
Session::Type sessionType() const;
106109
int tty() const;
107110

108111
void setTTY(int tty);
@@ -146,6 +149,8 @@ namespace DDM {
146149
void setVerbose(bool on = true);
147150

148151
void setIdentifyOnly(bool on = false);
152+
153+
void setSkipAuth(bool on = true);
149154
/**
150155
* Sets the user which will then authenticate
151156
* @param user username
@@ -179,7 +184,9 @@ namespace DDM {
179184
*/
180185
void setSingleMode(bool on = true);
181186

182-
void setSessionId(const QString& sessionId);
187+
void setSessionId(const QString &sessionId);
188+
189+
void setSessionType(const Session::Type type);
183190

184191
public Q_SLOTS:
185192
/**

src/daemon/Display.cpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,11 +590,12 @@ namespace DDM {
590590
}
591591

592592
auth->setUser(user);
593+
auth->setSessionType(session.type());
593594
if (m_reuseSessionId.isNull()) {
594595
auth->setSession(session.exec());
595596
}
596597
auth->insertEnvironment(env);
597-
auth->setSingleMode(m_displayServerType == DisplayServerType::SingleCompositerServerType);
598+
auth->setSingleMode(session.isSingleMode());
598599
auth->start();
599600
}
600601

@@ -639,17 +640,51 @@ namespace DDM {
639640
stateConfig.Last.Session.setDefault();
640641
stateConfig.save();
641642

642-
if (m_displayServerType == DisplayServerType::SingleCompositerServerType) {
643+
if (auth->isSingleMode()) {
643644
auto* server = reinterpret_cast<SingleWaylandDisplayServer*>(m_displayServer);
644645
server->onLoginSucceeded(user);
646+
switchToUser(auth->user());
645647
} else {
646648
if (m_socket) {
647649
emit loginSucceeded(m_socket, user);
648650
daemonApp->displayManager()->setLastSession(auth->sessionId());
649651
}
650-
}
651652

652-
switchToUser(auth->user());
653+
disconnect(m_displayServer, &DisplayServer::stopped, this, &Display::stop);
654+
m_displayServer->stop();
655+
delete m_displayServer;
656+
m_greeter->stop();
657+
delete m_greeter;
658+
m_currentAuth->stop();
659+
m_socketServer->stop();
660+
delete m_socketServer;
661+
662+
m_terminalId = m_sessionTerminalId = fetchAvailableVt();
663+
m_started = false;
664+
665+
if (auth->sessionType() == Session::X11Session) {
666+
m_displayServer = new XorgDisplayServer(this);
667+
m_displayServerType = X11DisplayServerType;
668+
} else {
669+
m_displayServer = new WaylandDisplayServer(this);
670+
m_displayServerType = WaylandDisplayServerType;
671+
}
672+
connect(m_displayServer, &DisplayServer::started, this, &Display::displayServerStarted);
673+
connect(m_displayServer, &DisplayServer::stopped, this, &Display::stop);
674+
675+
m_socketServer = new SocketServer(this);
676+
677+
m_greeter = new Greeter(this);
678+
m_greeter->setDisplayServerCommand(auth->session());
679+
m_greeter->setUser(user);
680+
m_greeter->setSkipAuth();
681+
682+
connect(m_greeter, &Greeter::failed, this, &Display::stop);
683+
connect(m_greeter, &Greeter::displayServerFailed, this, &Display::displayServerFailed);
684+
connect(m_greeter, &Greeter::succeed, this, &Display::stop);
685+
686+
m_displayServer->start();
687+
}
653688
}
654689
m_socket = nullptr;
655690
}
@@ -711,7 +746,8 @@ namespace DDM {
711746
}
712747
}
713748

714-
if (status != Auth::HELPER_AUTH_ERROR && m_displayServerType != DisplayServerType::SingleCompositerServerType)
749+
// Don't restart display when ddm-helper crashed (exit code 9)
750+
if (status != Auth::HELPER_AUTH_ERROR && status != Auth::HelperExitStatus(9) && m_displayServerType != DisplayServerType::SingleCompositerServerType)
715751
stop();
716752
}
717753

@@ -730,7 +766,7 @@ namespace DDM {
730766
void Display::slotSessionStarted(bool success) {
731767
qDebug() << "Session started" << success;
732768
Auth* auth = qobject_cast<Auth*>(sender());
733-
if (m_displayServerType == SingleCompositerServerType) {
769+
if (auth->isSingleMode()) {
734770
switchToUser(auth->user());
735771
}
736772

src/daemon/Greeter.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ namespace DDM {
8383
m_singleMode = on;
8484
}
8585

86+
void Greeter::setUser(const QString &user) {
87+
m_user = user;
88+
}
89+
90+
void Greeter::setSkipAuth(bool on) {
91+
m_skipAuth = on;
92+
}
93+
8694
void Greeter::setUserActivated(bool active) {
8795
m_userActivated = active;
8896
}
@@ -226,7 +234,8 @@ namespace DDM {
226234
if (m_display->displayServerType() == Display::X11DisplayServerType) {
227235
env.insert(QStringLiteral("DISPLAY"), m_display->name());
228236
env.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("xcb"));
229-
m_auth->setCookie(qobject_cast<XorgDisplayServer*>(displayServer)->cookie());
237+
if (m_display->sessionType() == "x11")
238+
m_auth->setCookie(qobject_cast<XorgDisplayServer*>(displayServer)->cookie());
230239
} else if (m_display->displayServerType() == Display::WaylandDisplayServerType) {
231240
env.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("wayland"));
232241
env.insert(QStringLiteral("QT_WAYLAND_SHELL_INTEGRATION"), QStringLiteral("fullscreen-shell-v1"));
@@ -240,7 +249,7 @@ namespace DDM {
240249
qDebug() << "Greeter starting...";
241250

242251
// start greeter
243-
m_auth->setUser(QStringLiteral("dde"));
252+
m_auth->setUser(m_user);
244253
QString displayServerCmd = m_displayServerCmd;
245254
if (m_singleMode) {
246255
displayServerCmd += " --lockscreen";
@@ -255,6 +264,10 @@ namespace DDM {
255264
return true;
256265
}
257266

267+
if (m_skipAuth) {
268+
m_auth->setSkipAuth();
269+
}
270+
258271
m_auth->start();
259272

260273
m_tryTimer->start();
@@ -371,6 +384,8 @@ namespace DDM {
371384
Q_EMIT ttyFailed();
372385
} else if (status == Auth::HELPER_SESSION_ERROR) {
373386
Q_EMIT failed();
387+
} else if (status == Auth::HELPER_SUCCESS) {
388+
Q_EMIT succeed();
374389
}
375390
}
376391

src/daemon/Greeter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ namespace DDM {
4242
void setSocket(const QString &socket);
4343
void setTheme(const QString &theme);
4444
void setSingleMode(bool on = true);
45+
void setUser(const QString &user);
46+
void setSkipAuth(bool on = true);
4547
void setUserActivated(bool active);
4648

4749
QString displayServerCommand() const;
@@ -67,6 +69,7 @@ namespace DDM {
6769
void ttyFailed();
6870
void failed();
6971
void displayServerFailed();
72+
void succeed();
7073
void greeterStarted();
7174

7275
private:
@@ -75,6 +78,8 @@ namespace DDM {
7578
bool m_userActivated { false };
7679
int m_currentRetry { 0 };
7780
int m_maxRetry{ 3 };
81+
QString m_user = QStringLiteral("dde");
82+
bool m_skipAuth { false };
7883

7984
Display * const m_display { nullptr };
8085
QString m_socket;

src/helper/HelperApp.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ namespace DDM {
123123
m_backend->setIdentifyOnly(true);
124124
}
125125

126+
if ((pos = args.indexOf(QStringLiteral("--skip-auth"))) >= 0) {
127+
m_skipAuth = true;
128+
}
129+
126130
if (server.isEmpty() || m_id <= 0) {
127131
qCritical() << "This application is not supposed to be executed manually";
128132
exit(Auth::HELPER_OTHER_ERROR);
@@ -163,7 +167,7 @@ namespace DDM {
163167
}
164168

165169
Q_ASSERT(getuid() == 0);
166-
if (!m_backend->authenticate()) {
170+
if (!m_skipAuth && !m_backend->authenticate()) {
167171
authenticated(QString());
168172

169173
// write failed login to btmp

src/helper/HelperApp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ namespace DDM {
6767
QString m_user { };
6868
// TODO: get rid of this in a nice clean way along the way with moving to user session X server
6969
QByteArray m_cookie { };
70+
bool m_skipAuth = false;
7071

7172
/*!
7273
\brief Write utmp/wtmp/btmp records when a user logs in

src/helper/UserSession.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,9 @@ namespace DDM {
122122
}
123123

124124
qInfo() << "Starting X11 session:" << m_displayServerCmd << command;
125-
if (m_displayServerCmd.isEmpty()) {
126-
auto args = QProcess::splitCommand(command);
127-
setProgram(args.takeFirst());
128-
setArguments(args);
129-
} else {
130-
setProgram(QStringLiteral(LIBEXEC_INSTALL_DIR "/ddm-helper-start-x11user"));
131-
setArguments({m_displayServerCmd, command});
132-
}
125+
auto args = QProcess::splitCommand(m_displayServerCmd);
126+
setProgram(args.takeFirst());
127+
setArguments(args);
133128
QProcess::start();
134129

135130
} else if (env.value(QStringLiteral("XDG_SESSION_TYPE")) == QLatin1String("wayland")) {
@@ -238,7 +233,7 @@ namespace DDM {
238233

239234
// take control of the tty
240235
if (takeControl) {
241-
if (ioctl(STDIN_FILENO, TIOCSCTTY, 0) < 0) {
236+
if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) < 0) {
242237
const auto error = strerror(errno);
243238
qCritical().nospace() << "Failed to take control of " << ttyString << " (" << QFileInfo(ttyString).owner() << "): " << error;
244239
_exit(Auth::HELPER_TTY_ERROR);

0 commit comments

Comments
 (0)