Skip to content

refactor: proper session initialization#247

Open
CertainLach wants to merge 8 commits into
coastalwhite:mainfrom
CertainLach:refactor/proper-session-init
Open

refactor: proper session initialization#247
CertainLach wants to merge 8 commits into
coastalwhite:mainfrom
CertainLach:refactor/proper-session-init

Conversation

@CertainLach

@CertainLach CertainLach commented Feb 18, 2026

Copy link
Copy Markdown

Fixes: #166
Fixes: #228

Comment thread src/main.rs
}
set_session_params(&mut process_env, post_login_env);
remove_xdg(&mut process_env);
set_seat_vars(&mut process_env, config.tty);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Previously, seat_vars were reset before calling try_auth, but this is not correct: pam-systemd wants to know XDG_VTNR, XDG_SEAT, source:

https://www.freedesktop.org/software/systemd/man/latest/pam_systemd.html

If not set, pam_systemd will initialize $XDG_SEAT and $XDG_VTNR based on the $DISPLAY variable (if the latter is set).

(it only works for xorg, and is an ugly fallback in any case)

Also: https://systemd.io/WRITING_DISPLAY_MANAGERS/

Comment thread src/main.rs Outdated
Ok(l) => l,
Err(_) => break,
};
match line.as_str() {

@CertainLach CertainLach Feb 18, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Such command interface is required for proper pam support

While username/password approach is the only valid auth way for the https://docs.rs/pam/latest/pam/, I would like to switch to https://docs.rs/pam-client/latest/pam_client/ for the proper callback-based interface (see https://docs.rs/pam-client/latest/pam_client/trait.ConversationHandler.html), and using callbacks it would be possible to support things like fido/fingerprint auth

Comment thread src/main.rs Outdated
post_login_env: &PostLoginEnvironment,
hooks: &Hooks<'_>,
config: &Config,
config_path: Option<&Path>,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't like passing both, but I haven't decided if I want to pass serialized config to the client through the stdio...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would be more comfortable doing that after I switch from line-based stdio communication

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Dropped that, config is now serialized/deserialized... And I hate it. I would like to create a separate struct for childprocess config, but it needs refactoring much more things than I want...

Comment thread src/main.rs Outdated
Comment thread src/main.rs Outdated
@CertainLach

CertainLach commented Feb 20, 2026

Copy link
Copy Markdown
Author

Changes after refactor: proper session initialization have little-to-no testing yet, I'm still figuring out the codebase and how should it work, trying to switch it to pam-client

@CertainLach

Copy link
Copy Markdown
Author

Oh, pam crate does support custom authenticators...

@CertainLach

CertainLach commented Feb 20, 2026

Copy link
Copy Markdown
Author

I'll postpone pam refactor for now, the basics for parent-child communications are there, everything else can be implemented on top of that

Wayland/shell sessions are working properly, but I don't have a machine with Xorg to test it

@CertainLach
CertainLach marked this pull request as ready for review February 20, 2026 02:44
@coastalwhite

Copy link
Copy Markdown
Owner

Thank you for the patches. I will see if I can have a look somewhere this week.

@0x7fmyr

0x7fmyr commented Apr 26, 2026

Copy link
Copy Markdown

Tested this PR on Arch (CachyOS) , lemur reads sessions form /usr/share/wayland-sessions
Results from login > use > logout > login again:

*Plasma on wayland: works
*Hyprland (hyprland.desktop, Exec=/usr/bin/start-hyprland): works
*Hyprland(hyprland-uwsm.desktop, Exec=uwsm start -e -D Hyprland hyprland.desktop, TryExec=uwsm): subprocess error on relogin attempt.

Confirms this fixes #184 for cases that work. Without the patch lemurs sits inside session-c1.scope, so logind waits indefinitely om session close and subsequent logins (including SSH) hang for several minutes. With the patch lemurs stays out of the user session scope and relogin is immediate.

Maybe the uswm path is a seperate issue. Happy to grab logs and open a followup issue if useful.

Thanks for writing this.

@0x7fmyr

0x7fmyr commented Apr 26, 2026

Copy link
Copy Markdown

Update: tracked down the uswm issue. Fix here: CertainLach#1

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.

Authentication error with PAM: Error writing /proc/self/loginuid pam_open_session should be called by another subprocess and not lemurs itself

3 participants