Skip to content

Conversation

@calsys456
Copy link
Contributor

@calsys456 calsys456 commented Nov 7, 2025

This commit exposes an interface to treeland to terminate systemd session with priviledge.

Summary by Sourcery

Add a logout cleanup feature by extending the IPC protocol with a Logout message, wiring it through the daemon, and using the systemd logind D-Bus API to terminate the user’s active sessions on logout.

New Features:

  • Add Logout IPC message and connect logout signal in SocketServer and Display
  • Implement Display::logout to query systemd logind for user sessions and terminate active sessions via D-Bus

This commit exposes an interface to treeland to terminate systemd session with priviledge.
@deepin-ci-robot
Copy link

Hi @calsys456. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 7, 2025

Reviewer's Guide

This PR adds a privileged logout workflow by wiring a new Logout message from the greeter through SocketServer to Display, where a D-Bus-based cleanup terminates the user’s systemd sessions.

Sequence diagram for the new privileged logout workflow

sequenceDiagram
    actor Greeter
    participant SocketServer
    participant Display
    participant "org.freedesktop.login1.Manager"
    participant "org.freedesktop.login1.Session"
    Greeter->>SocketServer: Send Logout message (with username)
    SocketServer->>Display: emit logout(socket, user)
    Display->>"org.freedesktop.login1.Manager": ListSessions()
    "org.freedesktop.login1.Manager"-->>Display: Return sessions
    loop For each session of user
        Display->>"org.freedesktop.login1.Session": Terminate (if session is active)
    end
Loading

Entity relationship diagram for GreeterMessages enum update

erDiagram
    GreeterMessages {
        int ActivateUser
        int BackToNormal
        int Unlock
        int Logout
    }
Loading

Class diagram for updated Display and SocketServer classes

classDiagram
    class SocketServer {
        +login(QLocalSocket*, QString, QString, Session)
        +logout(QLocalSocket*, QString)
        +unlock(QLocalSocket*, QString, QString)
        +connected(QLocalSocket*)
        <<signal>> logout(QLocalSocket*, QString)
    }
    class Display {
        +login(QLocalSocket*, QString, QString, Session)
        +logout(QLocalSocket*, QString)
        +unlock(QLocalSocket*, QString, QString)
        +attemptAutologin()
        +logout(QLocalSocket*, QString)  // new method
    }
    class org_freedesktop_login1_Manager
    class org_freedesktop_login1_Session
    SocketServer --> Display : emits logout signal
    Display ..> org_freedesktop_login1_Manager : uses D-Bus interface
    Display ..> org_freedesktop_login1_Session : uses D-Bus interface
Loading

File-Level Changes

Change Details Files
Implement logout logic in Display
  • Connect the logout signal in the Display constructor
  • Add Display::logout method to query and sort user sessions via QDBus
  • Terminate active sessions through the systemd login1 D-Bus interface
src/daemon/Display.cpp
Handle Logout message in SocketServer
  • Add a case for GreeterMessages::Logout in the message loop
  • Log receipt of the Logout message and read the username
  • Emit the logout signal with the socket and user
src/daemon/SocketServer.cpp
Expose logout slots in headers
  • Declare logout(QLocalSocket*, const QString&) in Display.h
  • Declare logout(QLocalSocket*, const QString&) in SocketServer.h
src/daemon/Display.h
src/daemon/SocketServer.h
Add Logout message enum
  • Introduce a Logout entry in the Messages enum
src/common/Messages.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/daemon/Display.cpp:402-403` </location>
<code_context>
         startAuth(user, password, session);
     }

+    void Display::logout([[maybe_unused]] QLocalSocket *socket, const QString &user) {
+        struct passwd *pw = getpwnam(user.toLocal8Bit().data());
+        QDBusInterface managerInterface("org.freedesktop.login1",
+                                        "/org/freedesktop/login1",
</code_context>

<issue_to_address>
**issue (bug_risk):** Check for null return value from getpwnam to avoid possible crash.

Add a null check for pw after getpwnam and handle the error to prevent undefined behavior.
</issue_to_address>

### Comment 2
<location> `src/daemon/Display.cpp:408-410` </location>
<code_context>
+                                        "/org/freedesktop/login1",
+                                        "org.freedesktop.login1.Manager",
+                                        QDBusConnection::systemBus());
+        QDBusReply<QList<SessionInfo>> sessions = managerInterface.call("ListSessions");
+        QStringList userSessions;
+        for (const SessionInfo &session : sessions.value())
+            // TODO multiple seats.
+            if (session.userId == pw->pw_uid && !session.seatId.isEmpty())
</code_context>

<issue_to_address>
**issue (bug_risk):** Handle possible DBus call failure for ListSessions.

Check sessions.isValid() before using sessions.value() to prevent issues if the DBus call fails.
</issue_to_address>

### Comment 3
<location> `src/daemon/Display.cpp:422-423` </location>
<code_context>
+                                            sessionPath,
+                                            "org.freedesktop.login1.Session",
+                                            QDBusConnection::systemBus());
+            if (sessionInterface.property("Active").toBool())
+                sessionInterface.call("Terminate");
+        }
+    }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Check for DBus call success when terminating sessions.

Check the result of sessionInterface.call("Terminate") and handle any errors to improve reliability.

```suggestion
            if (sessionInterface.property("Active").toBool()) {
                QDBusReply<void> terminateReply = sessionInterface.call("Terminate");
                if (!terminateReply.isValid()) {
                    qWarning() << "Failed to terminate session at" << sessionPath << ":" << terminateReply.error().message();
                }
            }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

In this commit we extract systemd-logind session ID after user logged in, and send it to treeland as a necessary info for current user session.

And we fixed some misbehaviour btw.
@zccrs zccrs merged commit af8ccc7 into linuxdeepin:master Nov 12, 2025
6 checks passed
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: calsys456, zccrs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants