Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ add_subdirectory(data)
add_subdirectory(services)
add_subdirectory(src)

include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()

# Display feature summary
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)

Expand Down
8 changes: 4 additions & 4 deletions data/dconfig/org.deepin.dde.ddm.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@
"visibility": "private"
},
"singleSessionCommand": {
"value": "@WAYLAND_SESSION_COMMAND@",
"serial": 0,
"value": "",
"serial": 1,
"flags": [],
"name": "Single Session Command",
"name[zh_CN]": "单例会话命令",
"description": "Path to a script to execute when starting the Treeland user session.",
"description[zh_CN]": "启动 Treeland 用户会话时执行的脚本路径。",
"description": "Optional additional user-session wrapper after DA prepares the login environment. Empty starts the desktop command directly.",
"description[zh_CN]": "DA 准备登录环境后执行的可选用户会话包装程序。留空时直接启动桌面命令。",
"permissions": "readwrite",
"visibility": "private"
},
Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Depends: ${shlibs:Depends},
${misc:Depends},
dde-seatd,
dde-dconfig-daemon,
deepin-authenticate,
treeland,
libpam-systemd,
Recommends: deepin-keyring-whitebox,
Expand Down
4 changes: 2 additions & 2 deletions services/ddm.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Description=Deepin Display Manager
Documentation=man:ddm(1)
Conflicts=getty@tty${DDM_INITIAL_VT}.service
After=systemd-user-sessions.service getty@tty${DDM_INITIAL_VT}.service plymouth-quit.service systemd-logind.service dde-seatd.service dde-dconfig-daemon.service
After=systemd-user-sessions.service getty@tty${DDM_INITIAL_VT}.service plymouth-quit.service systemd-logind.service dde-seatd.service dde-dconfig-daemon.service deepin-session-service.service
PartOf=graphical.target
StartLimitIntervalSec=30
StartLimitBurst=2

Requires=dde-seatd.service
Wants=dde-dconfig-daemon.service
Wants=dde-dconfig-daemon.service deepin-session-service.service

[Service]
ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/ddm
Expand Down
149 changes: 145 additions & 4 deletions src/daemon/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QDataStream>
#include <QDebug>
#include <QProcess>
#include <QTimer>

namespace DDM {

Expand Down Expand Up @@ -76,6 +77,8 @@ namespace DDM {
QProcess *helper { nullptr };
// Buffer for streaming replies from the helper.
QByteArray recvBuffer;
DASessionClient *da { nullptr };
bool busy { false };
};

Auth::Auth(QObject *parent, QString user)
Expand All @@ -84,6 +87,12 @@ namespace DDM {
, d(new AuthPrivate(this)) {}

Auth::~Auth() {
if (type == Display::Treeland) {
// DASessionClient cancels unfinished attempts and detaches running sessions.
delete d->da;
d->da = nullptr;
return;
}
if (sessionOpened) {
if (sessionPid > 0)
kill(sessionPid, SIGTERM);
Expand Down Expand Up @@ -220,6 +229,10 @@ namespace DDM {
}

bool Auth::authenticate(const QByteArray &secret) {
if (type == Display::Treeland) {
qWarning() << "[Auth] Treeland requires asynchronous DA authentication";
return false;
}
Q_ASSERT(!user.isEmpty());

qInfo() << "[Auth] Starting...";
Expand Down Expand Up @@ -260,6 +273,10 @@ namespace DDM {
QString Auth::openSession(const QString &command,
QProcessEnvironment env,
const QByteArray &cookie) {
if (type == Display::Treeland) {
qWarning() << "[Auth] Treeland requires asynchronous DA session start";
return {};
}
Q_ASSERT(authenticated);

// Everything the helper needs to run the session comes from the
Expand All @@ -269,10 +286,6 @@ namespace DDM {
QString sessionCommand;
QString sessionLogFile;
switch (type) {
case Display::Treeland:
sessionCommand = mainConfig()->singleSessionCommand();
sessionLogFile = mainConfig()->waylandSessionLogFile();
break;
case Display::X11:
sessionCommand = mainConfig()->x11SessionCommand();
sessionLogFile = mainConfig()->x11SessionLogFile();
Expand Down Expand Up @@ -356,6 +369,8 @@ namespace DDM {
}

bool Auth::closeSession() {
if (type == Display::Treeland)
return d->da && d->da->stop();
if (!sessionOpened) {
qWarning() << "[Auth] closeSession: Session was not opened.";
return true;
Expand All @@ -376,6 +391,132 @@ namespace DDM {
qInfo() << "[Auth] Session closed.";
return true;
}
DASessionClient *Auth::ensureDAClient()
{
if (d->da)
return d->da;
d->da = new DASessionClient(this);
connect(d->da, &DASessionClient::authenticationFinished, this, [this](bool success) {
sessionId = d->da->sessionId();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Grouped VT loses its session identity

When a Treeland login succeeds through DA, prepareUserSession() creates the grouped VT with the generated auth->sessionId, then the authentication callback replaces that ID with the DA object-path ID. registerSession and cleanup use the replacement, so seatd/VT ownership lookups cannot match the registered session and cleanup can miss the grouped VT.

Keep the session ID used to create the grouped VT consistent with the ID used for DA registration and cleanup.

Also at src/daemon/Display.cpp:346.

Prompt for AI agents
In `src/daemon/Auth.cpp` at line 400:

**Grouped VT loses its session identity**

When a Treeland login succeeds through DA, `prepareUserSession()` creates the grouped VT with the generated `auth->sessionId`, then the authentication callback replaces that ID with the DA object-path ID. `registerSession` and cleanup use the replacement, so seatd/VT ownership lookups cannot match the registered session and cleanup can miss the grouped VT.

Keep the session ID used to create the grouped VT consistent with the ID used for DA registration and cleanup.

Also at `src/daemon/Display.cpp:346`.

authenticated = success;
Q_EMIT authenticationFinished(success);
});
connect(d->da, &DASessionClient::sessionStarted, this, [this] {
const auto info = d->da->info();
xdgSessionId = info.logindSessionId;
sessionPid = info.pid;
sessionOpened = true;
Q_EMIT sessionStarted();
});
connect(d->da, &DASessionClient::sessionStartFailed, this, [this] {
authenticated = false;
Q_EMIT sessionStartFailed();
});
connect(d->da, &DASessionClient::sessionFinished, this, [this] {
sessionOpened = false;
authenticated = false;
Q_EMIT sessionFinished();
});
connect(d->da, &DASessionClient::informationMessage, this, &Auth::informationMessage);
return d->da;
}

bool Auth::isBusy() const
{
return d->busy || (d->da && d->da->isBusy());
}

void Auth::authenticateAsync(const QByteArray &secret)
{
if (isBusy() || authenticated || sessionOpened || d->da)
return;
if (type == Display::Treeland) {
ensureDAClient()->authenticate(user, pamService == QLatin1String("ddm-autologin")
? QStringLiteral("autologin") : QStringLiteral("login"),
seat, tty > 0 ? static_cast<quint32>(tty) : 0, secret);
return;
Comment on lines +434 to +437

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Low · Treeland bypasses documented UserSession path

When a login uses Treeland, for Treeland, Auth::authenticateAsync authenticates through DASessionClient, and openSessionAsync launches through DA instead of UserSession, so the documented login path is false for every Treeland login.

Update kb-965847 to describe DA-managed Treeland authentication and session launch while retaining the UserSession path for other display types.

Also at src/daemon/Auth.cpp:490.

Prompt for AI agents
In `src/daemon/Auth.cpp` at lines 434-437:

**Treeland bypasses documented UserSession path**

When a login uses Treeland, for Treeland, `Auth::authenticateAsync` authenticates through `DASessionClient`, and `openSessionAsync` launches through DA instead of `UserSession`, so the documented login path is false for every Treeland login.

Update kb-965847 to describe DA-managed Treeland authentication and session launch while retaining the `UserSession` path for other display types.

Also at `src/daemon/Auth.cpp:490`.

From .github/copilot-instructions.md L17:

        - When user login, Auth will startup UserSession, which will call PAM to open session, as well as starting up desktop environment.

}
d->busy = true;
QTimer::singleShot(0, this, [this, secret] {
const bool success = authenticate(secret);
d->busy = false;
Q_EMIT authenticationFinished(success);
});
}

void Auth::openSessionAsync(const QString &command, QProcessEnvironment env, const QByteArray &cookie)
{
if (isBusy() || !authenticated || sessionOpened)
return;
if (type != Display::Treeland) {
d->busy = true;
QTimer::singleShot(0, this, [this, command, env, cookie] {
const bool success = !openSession(command, env, cookie).isEmpty();
d->busy = false;
if (success)
Q_EMIT sessionStarted();
else
Q_EMIT sessionStartFailed();
});
return;
}
if (!d->da)
return;
if (!daemonApp->seatdControl()->requestSwitchVt(tty)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Failed launch hides greeter

When DA rejects the start or the launch fails after the user VT has been selected, requestSwitchVt(tty) moves the display to the user VT before DA accepts the session start. If the start then fails, failLogin sends ShowGreeter without switching back to the greeter VT, so the greeter remains off-screen.

Switch back to the greeter VT when a Treeland launch fails and the greeter connection is still active.

Prompt for AI agents
In `src/daemon/Auth.cpp` at line 465:

**Failed launch hides greeter**

When DA rejects the start or the launch fails after the user VT has been selected, `requestSwitchVt(tty)` moves the display to the user VT before DA accepts the session start. If the start then fails, `failLogin` sends `ShowGreeter` without switching back to the greeter VT, so the greeter remains off-screen.

Switch back to the greeter VT when a Treeland launch fails and the greeter connection is still active.

d->da->cancel();
authenticated = false;
Q_EMIT sessionStartFailed();
return;
}
QStringList argv;
const QString wrapper = mainConfig()->singleSessionCommand();
if (wrapper.isEmpty()) {
argv = QProcess::splitCommand(command);
} else {
argv = QProcess::splitCommand(wrapper);
argv.append(command);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Wrapped desktops fail to launch

When singleSessionCommand is configured and the desktop command contains arguments, openSessionAsync appends the entire desktop command as one argument to the wrapper. When the desktop command contains arguments and the wrapper executes its arguments as an argv vector, it receives a single executable name containing spaces and the DA session fails to start.

Append QProcess::splitCommand(command) to the wrapper argv, or explicitly implement and test the wrapper’s intended command-string interface.

Prompt for AI agents
In `src/daemon/Auth.cpp` at line 478:

**Wrapped desktops fail to launch**

When `singleSessionCommand` is configured and the desktop command contains arguments, `openSessionAsync` appends the entire desktop command as one argument to the wrapper. When the desktop command contains arguments and the wrapper executes its arguments as an argv vector, it receives a single executable name containing spaces and the DA session fails to start.

Append `QProcess::splitCommand(command)` to the wrapper argv, or explicitly implement and test the wrapper’s intended command-string interface.

DAEnvironment environment;
for (const auto &key : env.keys()) {
if (!DASessionClient::reservedEnvironmentKey(key))
environment.insert(key, env.value(key));
}
QStringList namespaces;
const auto configured = mainConfig()->namespaces();
namespaces.reserve(configured.size());
for (const QVariant &path : configured)
namespaces.append(path.toString());
d->da->start(argv, environment, namespaces, mainConfig()->waylandSessionLogFile());
}

QList<ManagedSessionInfo> Auth::managedSessions(const QString &seat)
{
return DASessionClient::managedSessions(seat);
}

bool Auth::adoptManagedSession(const ManagedSessionInfo &info)
{
if (isBusy() || authenticated || sessionOpened || d->da)
return false;
if (!ensureDAClient()->adopt(info))
return false;
type = Display::Treeland;
seat = info.seat;
user = info.user;
tty = static_cast<int>(info.vt);
sessionId = d->da->sessionId();
xdgSessionId = info.logindSessionId;
sessionPid = info.pid;
authenticated = true;
sessionOpened = true;
return true;
}

QString Auth::managedSessionPath() const
{
return d->da ? d->da->objectPath() : QString();
}

} // namespace DDM

#include "Auth.moc"
20 changes: 20 additions & 0 deletions src/daemon/Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define DDM_AUTH_H

#include "Display.h"
#include "DASessionClient.h"

#include <QObject>
#include <QProcess>
Expand Down Expand Up @@ -43,6 +44,9 @@ namespace DDM {
/** X Display identifier (e.g. :0), if presents */
QString display{};

/** Seat bound to the DA login object. */
QString seat{};

/** Virtual terminal number (e.g. 7 for tty7) */
int tty{ 0 };

Expand All @@ -52,7 +56,16 @@ namespace DDM {
/** PID of the session process started by session helper. Positive values are valid */
qint64 sessionPid{ 0 };

bool isBusy() const;
static QList<ManagedSessionInfo> managedSessions(const QString &seat);
bool adoptManagedSession(const ManagedSessionInfo &info);
QString managedSessionPath() const;

public Q_SLOTS:
void authenticateAsync(const QByteArray &secret);
void openSessionAsync(const QString &command, QProcessEnvironment env,
const QByteArray &cookie = QByteArray());

/**
* Sets up the environment and starts the authentication.
*
Expand Down Expand Up @@ -81,12 +94,19 @@ namespace DDM {
bool closeSession();

Q_SIGNALS:
void authenticationFinished(bool success);
void sessionStarted();
void sessionStartFailed();
void informationMessage(const QString &message);

/**
* Emitted when the session process ends.
*/
void sessionFinished();

private:
DASessionClient *ensureDAClient();

/** Ensure the session helper is spawned and connected. */
bool ensureHelper();

Expand Down
1 change: 1 addition & 0 deletions src/daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dtk_add_config_to_cpp(DDM_CONFIG_HEADER

set(DAEMON_SOURCES
Auth.cpp
DASessionClient.cpp
Configuration.cpp
DaemonApp.cpp
DdeSeatdControl.cpp
Expand Down
Loading
Loading