Skip to content

dm-tool switch-to-user myuser fails with NULL pointer error if myuser has never logged in via the greeter #431

@codethief

Description

@codethief

I just created a new user and tried to switch to it from my current session:

$ dm-tool switch-to-user testuser
Unable to switch to user testuser: GDBus.Error:org.freedesktop.DBus.Error.Failed: Failed to switch to user

journalctl -u display-manager shows:

Mar 21 20:38:03 myhostname lightdm[2059]: invalid (NULL) pointer instance
Mar 21 20:38:03 myhostname lightdm[2059]: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
Mar 21 20:38:03 myhostname lightdm[2059]: session_set_pam_service: assertion 'session != NULL' failed
Mar 21 20:38:03 myhostname lightdm[2059]: session_start: assertion 'session != NULL' failed

I had Claude take a look at https://github.com/ubuntu/lightdm/blob/main/src/display-manager-service.c , where the error message "Failed to switch to user" originates from, and at the definition of seat_switch_to_user() in https://github.com/ubuntu/lightdm/blob/main/src/seat.c#L1529 and it suggested:

In seat_switch_to_user:

session = create_user_session(seat, username, FALSE);
// No NULL check here! ← BUG
g_signal_connect(session, ...);          // → "invalid (NULL) pointer instance"
session_set_pam_service(session, ...);   // → "assertion 'session != NULL' failed"
return session_start(session);           // → "assertion 'session != NULL' failed"

[…]

Most likely, testuser has never logged in via the greeter, so there's no default session stored, and dm-tool switch-to-user
doesn't pass a session name (it passes empty string → NULL), causing the session config lookup to fail.

Indeed, after logging in as testuser by hand (through the greeter), dm-tool switch-to-user testuser now works. (Interestingly, dm-tool switch-to-user testuser somesession did not do the trick. I really had to log in by hand.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions