loginDialog: Don't assume this._user is always defined

There are cases where this._user might be null when a session
is opened. This is because the user is not selected via GDM but
it is set through PAM. This happens when logging with smart card
or with credential managers, for example.

Given the session-id of the opened session, look for the owner.
This fixes the following error:
```
gnome-shell[153293]: TypeError: this._user is null

                     Stack trace:
                     _findConflictingSession@resource:///org/gnome/shell/gdm/loginDialog.js:1219:26
                     _onSessionOpened@resource:///org/gnome/shell/gdm/loginDialog.js:1254:51
                     @resource:///org/gnome/shell/ui/init.js:21:20
```

Fixes: df84854d9 ("loginDialog: On login, allow logout a conflicting session")
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7526
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3448>
This commit is contained in:
Alessandro Bono 2024-08-19 18:08:42 +02:00
parent 647747fbd6
commit e5d9a0fec8

View File

@ -1137,15 +1137,15 @@ export const LoginDialog = GObject.registerClass({
});
}
async _findConflictingSession(ignoreSessionId) {
const userName = this._user.get_user_name();
async _findConflictingSession(startingSessionId) {
const loginManager = LoginManager.getLoginManager();
const sessions = await loginManager.listSessions();
const [, , startingSessionOwner, ,] = sessions.find(([id, , , ,]) => id === startingSessionId);
for (const session of sessions.map(([id, , user, , path]) => ({id, user, path}))) {
if (ignoreSessionId === session.id)
if (startingSessionId === session.id)
continue;
if (userName !== session.user)
if (startingSessionOwner !== session.user)
continue;
const sessionProxy = loginManager.getSession(session.path);