Skip to content

Conversation

@calsys456
Copy link
Collaborator

@calsys456 calsys456 commented Jan 4, 2026

The reason of crash is that the treeland cannot find fullServerName for default WSocket. We should provide an always-available WSocket in defaultWaylandSocket() method, instead of the socket of current session.

Summary by Sourcery

Ensure the default Wayland socket lookup uses a reserved, always-available socket instead of the active session socket to prevent crashes on logout.

Bug Fixes:

  • Fix crash on logout by resolving the default Wayland socket from a dedicated user-specific socket rather than the active session socket.

Enhancements:

  • Mark Helper socket and XWayland lookup methods as const-qualified for safer read-only access.

The reason of crash is that the treeland cannot find fullServerName for
default WSocket. We should provide an always-available WSocket in
defaultWaylandSocket() method, instead of the socket of current session.
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts Helper’s Wayland/XWayland accessors to be const-correct and changes the "default" Wayland socket to a reserved, always-available socket for the fixed user instead of the active session’s socket, preventing crashes when logging out.

Sequence diagram for resolving the default Wayland socket on logout

sequenceDiagram
    actor Compositor
    participant Helper
    participant C_Library as C_Library_getpwnam
    participant SessionManager as Session_manager
    participant Session
    participant WSocket

    Compositor->>Helper: defaultWaylandSocket()
    activate Helper
    Helper->>C_Library: getpwnam(dde)
    C_Library-->>Helper: passwd_struct_with_uid
    Helper->>Helper: waylandSocketForUid(uid)
    Helper->>SessionManager: sessionForUid(uid)
    SessionManager-->>Helper: Session
    Helper->>Session: access socket
    Session-->>Helper: WSocket
    Helper-->>Compositor: WSocket
    deactivate Helper
Loading

Class diagram for Helper and session socket accessors

classDiagram
    class Helper {
        +addSocket(socket WSocket*) void
        +removeXWayland(xwayland WXWayland*) void
        +removeSession(session std_shared_ptr_Session) void
        +xwaylandForUid(uid uid_t) WXWayland* const
        +waylandSocketForUid(uid uid_t) WSocket* const
        +sessionForUid(uid uid_t) std_shared_ptr_Session const
        +sessionForXWayland(xwayland WXWayland*) std_shared_ptr_Session const
        +sessionForSocket(socket WSocket*) std_shared_ptr_Session const
        +defaultWaylandSocket() WSocket* const
        -m_activeSession std_weak_ptr_Session
    }

    class Session {
        +xwayland WXWayland*
        +socket WSocket*
    }

    class WSocket
    class WXWayland

    Helper "1" --> "*" Session : manages
    Session "1" --> "1" WSocket : socket
    Session "1" --> "1" WXWayland : xwayland

    Helper ..> WSocket : returns
    Helper ..> WXWayland : returns
Loading

File-Level Changes

Change Details Files
Make Helper’s XWayland and Wayland socket lookup methods const-correct to reflect that they do not mutate state.
  • Changed xwaylandForUid to be a const member function in the header and implementation.
  • Changed waylandSocketForUid to be a const member function in the header and implementation.
src/seat/helper.cpp
src/seat/helper.h
Redefine the default Wayland socket to use a reserved, non-session-bound socket for a specific user to ensure it remains available during logout.
  • Updated the documentation comment for defaultWaylandSocket to describe the reserved, always-available socket semantics instead of the active session’s socket.
  • Reimplemented defaultWaylandSocket to return the socket for the fixed user "dde" via waylandSocketForUid(getpwnam("dde")->pw_uid) instead of using the active session’s socket pointer.
src/seat/helper.cpp

Possibly linked issues

  • #crash-30629: PR changes defaultWaylandSocket to always-available dde WSocket, matching the reported Treeland wl_event_loop_dispatch crash.

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 - I've found 1 issue, and left some high level feedback:

  • In defaultWaylandSocket(), calling getpwnam("dde")->pw_uid without checking for a null return from getpwnam can itself cause a crash; add a null check and a safe fallback path if the user does not exist.
  • Relying on a hard‑coded username "dde" in defaultWaylandSocket() may be brittle in customized deployments; consider making this user configurable or deriving it from existing configuration/state instead of hard‑coding.
  • If Helper is used from multiple threads, the use of getpwnam (which is not thread‑safe) in defaultWaylandSocket() could introduce data races; consider using getpwnam_r or resolving and caching the UID at startup.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `defaultWaylandSocket()`, calling `getpwnam("dde")->pw_uid` without checking for a null return from `getpwnam` can itself cause a crash; add a null check and a safe fallback path if the user does not exist.
- Relying on a hard‑coded username "dde" in `defaultWaylandSocket()` may be brittle in customized deployments; consider making this user configurable or deriving it from existing configuration/state instead of hard‑coding.
- If `Helper` is used from multiple threads, the use of `getpwnam` (which is not thread‑safe) in `defaultWaylandSocket()` could introduce data races; consider using `getpwnam_r` or resolving and caching the UID at startup.

## Individual Comments

### Comment 1
<location> `src/seat/helper.cpp:2382` </location>
<code_context>
-    if (ptr && ptr->socket)
-        return ptr->socket;
-    return nullptr;
+    return waylandSocketForUid(getpwnam("dde")->pw_uid);
 }

</code_context>

<issue_to_address>
**issue (bug_risk):** Guard against `getpwnam("dde")` returning `nullptr` before dereferencing.

If `getpwnam("dde")` returns `nullptr` (e.g. user missing or misconfigured), this will dereference a null pointer and crash. Store the result in a local variable, check for `nullptr`, and return `nullptr` or another fallback if the lookup fails.
</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.

@zccrs zccrs merged commit 4acd34f into linuxdeepin:master Jan 4, 2026
8 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants