Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't log to another user after logout #187

Open
vigiraud opened this issue Dec 2, 2023 · 14 comments
Open

Can't log to another user after logout #187

vigiraud opened this issue Dec 2, 2023 · 14 comments
Labels
bug Something isn't working investigation-needed This issue needs more investigation

Comments

@vigiraud
Copy link

vigiraud commented Dec 2, 2023

Hi, thanks for this project !
I just did a fresh installation of Arch with XFCE. I need to have two different users, let's say alice and bob.
So I followed the instructions, and after booting my computer, Lemurs works perfectly fine and I can easily log into any user. Once I have logged out, I get back to Lemurs as expected. If I try to log to the same user, it will work fine once again. However, if I try to log to the other user, I get to a screen with nothing but this :
IMG_20231202_200541
Which translates to :

Cannot contact configuration server. Cannot connect : permission denied.

I can't find my mouse, and the keyboard becomes unresponsive on this tty.

Here's what I have in my journalctl -xeu lemurs:

déc. 02 19:55:28 hostname systemd[1]: Started Lemurs.
░░ Subject: L'unité (unit) lemurs.service a terminé son démarrage
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ L'unité (unit) lemurs.service a terminé son démarrage, avec le résultat done.
déc. 02 19:55:38 hostname lemurs[561]: pam_loginuid(lemurs:session): Error writing /proc/self/loginuid: Operation not permitted
déc. 02 19:55:38 hostname lemurs[561]: pam_loginuid(lemurs:session): set_loginuid failed
déc. 02 19:55:38 hostname lemurs[561]: pam_unix(lemurs:session): session opened for user alice(uid=1001) by (uid=0)

The errors about pam_loginuid happen when I log in for the first time, where it seemingly work without problems.

I tried to disable lemurs, and to switch between users without any display manager, on the same tty, by launching XFCE just with the startxfce4 script. It works without issues.

Here is the /var/log/lemurs.log I obtain when I first succesfully log as alice, logout, and then fail to log as bob:

[2023-12-02T21:55:46Z INFO  lemurs] Main lemurs logger is running
[2023-12-02T21:55:46Z INFO  lemurs] Switching to tty 2
[2023-12-02T21:55:46Z INFO  lemurs] UI booted up
[2023-12-02T21:55:46Z WARN  lemurs::post_login] Failed to read from the wayland folder '/etc/lemurs/wayland'
[2023-12-02T21:55:46Z INFO  lemurs::info_caching] Attempting to get a cached information from '/var/cache/lemurs'
[2023-12-02T21:55:46Z INFO  lemurs::info_caching] Read cache file and found environment 'XFCE' and username 'alice'
[2023-12-02T21:55:46Z INFO  lemurs::ui] Loading username 'alice' from cache
[2023-12-02T21:55:46Z INFO  lemurs::ui] Loading environment 'XFCE' from cache
[2023-12-02T21:56:22Z INFO  lemurs] Starting new session for 'alice' in environment 'X { xinitrc_path: "/etc/lemurs/wms/XFCE" }'
[2023-12-02T21:56:22Z INFO  lemurs::post_login::env_variables] Setting Display
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'DISPLAY' to ':1'
[2023-12-02T21:56:22Z INFO  lemurs::post_login::env_variables] Setting XDG Session Parameters
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XDG_SESSION_CLASS' to 'user'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XDG_SESSION_TYPE' to 'x11'
[2023-12-02T21:56:22Z INFO  lemurs::post_login::env_variables] Clearing XDG preemptively to set later
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Preemptively removed environment variable 'XDG_SESSION_CLASS'
[2023-12-02T21:56:22Z INFO  lemurs::auth] Login attempt for 'alice'
[2023-12-02T21:56:22Z INFO  lemurs::auth::pam] Started opening session
[2023-12-02T21:56:22Z INFO  lemurs::auth::pam] Gotten Authenticator
[2023-12-02T21:56:22Z INFO  lemurs::auth::pam] Got handler
[2023-12-02T21:56:22Z INFO  lemurs::auth::pam] Validated account
[2023-12-02T21:56:22Z INFO  lemurs::auth::pam] Opened session
[2023-12-02T21:56:22Z INFO  lemurs::ui] Setting cached information
[2023-12-02T21:56:22Z INFO  lemurs::info_caching] Attempting to set cache
[2023-12-02T21:56:22Z INFO  lemurs::info_caching] Successfully set username in cache file
[2023-12-02T21:56:22Z INFO  lemurs::post_login::env_variables] Setting XDG Seat Variables
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Skipped setting environment variable 'XDG_SEAT'. It was already set to 'seat0'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Skipped setting environment variable 'XDG_VTNR'. It was already set to '2'
[2023-12-02T21:56:22Z INFO  lemurs::post_login::env_variables] Setting XDG Session Variables
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Skipped setting environment variable 'XDG_RUNTIME_DIR'. It was already set to '/run/user/1000'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Skipped setting environment variable 'XDG_SESSION_ID'. It was already set to 'c1'
[2023-12-02T21:56:22Z INFO  lemurs::post_login::env_variables] Setting Basic Environment Variables
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Successfully changed working directory to /home/alice!
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'HOME' to '/home/alice'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'SHELL' to '/usr/bin/bash'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'USER' to 'alice'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'LOGNAME' to 'alice'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'PATH' to '/usr/local/sbin:/usr/local/bin:/usr/bin'
[2023-12-02T21:56:22Z INFO  lemurs::post_login::env_variables] Setting XDG Common Paths
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XDG_CONFIG_HOME' to '/home/alice/.config'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XDG_CACHE_HOME' to '/home/alice/.cache'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XDG_DATA_HOME' to '/home/alice/.local/share'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XDG_STATE_HOME' to '/home/alice/.local/state'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XDG_DATA_DIRS' to '/usr/local/share:/usr/share'
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XDG_CONFIG_DIRS' to '/etc/xdg'
[2023-12-02T21:56:22Z INFO  lemurs::post_login] Starting X11 session
[2023-12-02T21:56:22Z INFO  lemurs::post_login::x] Start setup of X server
[2023-12-02T21:56:22Z INFO  lemurs::post_login::x] Filling `.Xauthority` file at `/home/alice/.config/.Xauthority`
[2023-12-02T21:56:22Z INFO  lemurs::env_container] Set environment variable 'XAUTHORITY' to '/home/alice/.config/.Xauthority'
[2023-12-02T21:56:23Z INFO  lemurs::post_login::x] It took X server 1201ms to start
[2023-12-02T21:56:23Z INFO  lemurs::post_login::x] X server is running
[2023-12-02T21:56:23Z INFO  lemurs::auth::utmpx] Adding UTMPX record
[2023-12-02T21:56:23Z INFO  lemurs::auth::utmpx] Added UTMPX record
[2023-12-02T21:56:23Z INFO  lemurs::env_container] Removing session environment variables
[2023-12-02T21:56:23Z INFO  lemurs::env_container] Reverting to environment before session
[2023-12-02T21:56:23Z INFO  lemurs::env_container] Reverting to environment before session
[2023-12-02T21:56:23Z INFO  lemurs] Waiting for environment to terminate
[2023-12-02T21:56:23Z INFO  lemurs::post_login] Waiting for client to exit
[2023-12-02T21:58:40Z INFO  lemurs::post_login::wait_with_log] Joining with logging thread.
[2023-12-02T21:58:40Z INFO  lemurs::post_login] Client exited with exit code `exit status: 0`
[2023-12-02T21:58:40Z INFO  lemurs::post_login] Telling X server to shut down
[2023-12-02T21:58:40Z INFO  lemurs::post_login] Waiting for X server
[2023-12-02T21:58:40Z INFO  lemurs::post_login::wait_with_log] Joining with logging thread.
[2023-12-02T21:58:40Z INFO  lemurs] Environment terminated. Returning to Lemurs...
[2023-12-02T21:58:40Z INFO  lemurs::auth::utmpx] Removing UTMPX record
[2023-12-02T21:58:47Z INFO  lemurs] Starting new session for 'bob' in environment 'X { xinitrc_path: "/etc/lemurs/wms/XFCE" }'
[2023-12-02T21:58:47Z INFO  lemurs::post_login::env_variables] Setting Display
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'DISPLAY' to ':1'
[2023-12-02T21:58:47Z INFO  lemurs::post_login::env_variables] Setting XDG Session Parameters
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_SESSION_CLASS' to 'user'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_SESSION_TYPE' to 'x11'
[2023-12-02T21:58:47Z INFO  lemurs::post_login::env_variables] Clearing XDG preemptively to set later
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Preemptively removed environment variable 'XDG_SESSION_CLASS'
[2023-12-02T21:58:47Z INFO  lemurs::auth] Login attempt for 'bob'
[2023-12-02T21:58:47Z INFO  lemurs::auth::pam] Started opening session
[2023-12-02T21:58:47Z INFO  lemurs::auth::pam] Gotten Authenticator
[2023-12-02T21:58:47Z INFO  lemurs::auth::pam] Got handler
[2023-12-02T21:58:47Z INFO  lemurs::auth::pam] Validated account
[2023-12-02T21:58:47Z INFO  lemurs::auth::pam] Opened session
[2023-12-02T21:58:47Z INFO  lemurs::ui] Setting cached information
[2023-12-02T21:58:47Z INFO  lemurs::info_caching] Attempting to set cache
[2023-12-02T21:58:47Z INFO  lemurs::info_caching] Successfully set username in cache file
[2023-12-02T21:58:47Z INFO  lemurs::post_login::env_variables] Setting XDG Seat Variables
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_SEAT' to 'seat0'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_VTNR' to '2'
[2023-12-02T21:58:47Z INFO  lemurs::post_login::env_variables] Setting XDG Session Variables
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_RUNTIME_DIR' to '/run/user/1001'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_SESSION_ID' to '1'
[2023-12-02T21:58:47Z INFO  lemurs::post_login::env_variables] Setting Basic Environment Variables
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Successfully changed working directory to /home/bob!
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'HOME' to '/home/bob'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'SHELL' to '/usr/bin/bash'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'USER' to 'bob'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'LOGNAME' to 'bob'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'PATH' to '/usr/local/sbin:/usr/local/bin:/usr/bin'
[2023-12-02T21:58:47Z INFO  lemurs::post_login::env_variables] Setting XDG Common Paths
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_CONFIG_HOME' to '/home/bob/.config'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_CACHE_HOME' to '/home/bob/.cache'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_DATA_HOME' to '/home/bob/.local/share'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_STATE_HOME' to '/home/bob/.local/state'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_DATA_DIRS' to '/usr/local/share:/usr/share'
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XDG_CONFIG_DIRS' to '/etc/xdg'
[2023-12-02T21:58:47Z INFO  lemurs::post_login] Starting X11 session
[2023-12-02T21:58:47Z INFO  lemurs::post_login::x] Start setup of X server
[2023-12-02T21:58:47Z INFO  lemurs::post_login::x] Filling `.Xauthority` file at `/home/bob/.config/.Xauthority`
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Set environment variable 'XAUTHORITY' to '/home/bob/.config/.Xauthority'
[2023-12-02T21:58:47Z INFO  lemurs::post_login::x] It took X server 0ms to start
[2023-12-02T21:58:47Z INFO  lemurs::post_login::x] X server is running
[2023-12-02T21:58:47Z INFO  lemurs::auth::utmpx] Adding UTMPX record
[2023-12-02T21:58:47Z INFO  lemurs::auth::utmpx] Added UTMPX record
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Removing session environment variables
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Reverting to environment before session
[2023-12-02T21:58:47Z INFO  lemurs::env_container] Reverting to environment before session
[2023-12-02T21:58:47Z INFO  lemurs] Waiting for environment to terminate
[2023-12-02T21:58:47Z INFO  lemurs::post_login] Waiting for client to exit

lemurs.client.log and lemurs.xorg.log are empty.
Something strange that I noticed is that when I boot my computer, successfully log in a alice for example, then logout to go back to lemurs, if I go to another tty and type loginctl, this is what I get:

SESSION  UID USER        SEAT  TTY  STATE   IDLE SINCE
      2    0 root        seat0 tty3 active  no   
     c1 1001 alice       seat0 tty2 closing no   

2 sessions listed.

Where we can see that the session which is supposed to be closed, is stuck in the closing state...
I don't know what to do, I'm not even sure where the problem comes from. Was a multi-users setup tested on lemurs ?
Thanks.

@coastalwhite
Copy link
Owner

Thank you for the report.

This seems like a new problem, I appreciate all the investigative work. I am guessing somehow the work we are doing on loginctl is correct. I am not 100% sure what that problem is.

@coastalwhite coastalwhite added bug Something isn't working investigation-needed This issue needs more investigation labels Dec 3, 2023
@dvzrv
Copy link

dvzrv commented May 28, 2024

I am met with the same issue (currently testing with sway, but it happens with other sessions too).

When trying to start sway for the 2nd time I get:

Started Tiling Wayland compositor and replacement for the i3 window manager.
00:00:00.002 [ERROR] [wlr] [libseat] [libseat/backend/logind.c:642] Could not check if session was active: No such device or address
00:00:00.002 [ERROR] [wlr] [libseat] [libseat/libseat.c:79] No backend was able to open a seat
00:00:00.002 [ERROR] [wlr] [backend/session/session.c:83] Unable to create seat: Function not implemented
00:00:00.002 [ERROR] [wlr] [backend/session/session.c:248] Failed to load session backend
00:00:00.002 [ERROR] [wlr] [backend/backend.c:79] Failed to start a session
00:00:00.002 [ERROR] [wlr] [backend/backend.c:359] Failed to start a DRM session
00:00:00.002 [ERROR] [sway/server.c:137] Unable to create backend
sway.service: Main process exited, code=exited, status=1/FAILURE
sway.service: Failed with result 'exit-code'.

This issue can only be solved by restarting lemurs.

My assumption is lemurs is either blocking the logind access for sway or is otherwise making it impossible for sway to check the user's active session.

@dvzrv
Copy link

dvzrv commented May 28, 2024

Looking deeper into this I think I found the culprit:
Lemur never fully closes the seat for the user after the user attempts to end the session and the seat remains in state "closing".

$ loginctl show-session c2
Id=c2
User=1000
Name=user
Timestamp=Tue 2024-05-28 08:48:23 CEST
TimestampMonotonic=632170501
VTNr=2
Seat=seat0
TTY=tty2
Remote=no
Service=lemurs
Scope=session-c2.scope
Leader=3017
Audit=4294967295
Type=wayland
Class=user
Active=no
State=closing
IdleHint=no
IdleSinceHint=0
IdleSinceHintMonotonic=0
LockedHint=no

When looking at the user's status it becomes clear that lemurs lowered itself into the session scope, but never exited (the below omits non-useful data) and is the only process keeping that seat alive:

$ loginctl user-status 1000
user (1000)
   Since: Tue 2024-05-28 08:38:15 CEST; 38min ago
   State: active
Sessions: *4 c2
  Linger: no
    Unit: user-1000.slice
          ├─session-4.scope
          │ ├─3063 "login -- user"
          │ ├─5394 -zsh
          │ └─6038 loginctl user-status 1000
          ├─session-c2.scope
          │ └─3017 /usr/bin/lemurs
[..]

@dvzrv
Copy link

dvzrv commented May 28, 2024

Looking at the above, my assumption would be, that lemurs needs to exit at that point in time to free the seat, or lower a process into that seat (for handling) which may exit.

When choosing the first route I guess lemurs.service would have to be able to automatically restart.

As is, lemurs blocks a login after an initial login and logout, because the lemurs presented to the user at that point runs in the scope of the session that the previous user exited.

@Freyert
Copy link

Freyert commented Sep 7, 2024

@dvzrv when lemurs isn't working to log back in is there a way to drop to a shell to debug? I get locked out like this whenever my laptop hibernates and the logs are gone when I power off and restart.

@mattpetters
Copy link

Lol just hit this problem this morning...so happy to help fix :)

@mattpetters
Copy link

Wellp, in my case I actually just figured it out. My binary for hyprland was Hyprland with a capital H so lemurs was trying (because I configured it to) to use the hyprland command which obviously didn't work. No idea if that will help anyone else but it helped me. Also in Arch ctrl+alt+f2 gets you to a text based shell at the DM so you can get around it.

@Freyert
Copy link

Freyert commented Sep 27, 2024

Maybe related: #210

I've also submitted a fix to append the logs so you should be able to debug this better: #211

@Freyert
Copy link

Freyert commented Sep 27, 2024

@dvzrv I can confirm the same behavior. Lemurs is sitting on the scope being closed.

          ├─session-c1.scope
          │ └─702 /usr/bin/lemurs

To be honest, the only thing I can tell Lemurs does at this point is write to the logs. So I think it should actually just exit? I don't know why it needs to exist after you log in.


Apparently it does lower the execution to the user scope: https://github.com/coastalwhite/lemurs/blob/main/src/post_login/mod.rs#L72-L97

I'm not great with this stuff, but it does look like there's some spawning issues.

flax% pstree -p 702
lemurs(702)───{lemurs}(706)
loginctl user-status X
          ├─session-c1.scope
          │ └─702 /usr/bin/lemurs

So 702 is in the old session, whereas 706 is a child in the new session. I performed kill -9 702 and the old session closed.


I think this happens because we spawn a child process (script) and that may not be receiving the SIGTERM.

https://github.com/coastalwhite/lemurs/blob/main/src/post_login/wait_with_log.rs#L88-L92


At this point I'm stumped. Also note: I'm using wayland.

@Freyert
Copy link

Freyert commented Sep 28, 2024

OK, new hunch. Looking through my logs I noticed the following log:

[2024-09-27T00:18:13Z INFO  lemurs::auth::utmpx] Removing UTMPX record

which comes from https://github.com/coastalwhite/lemurs/blob/main/src/auth/utmpx.rs#L94

this is called in the main method https://github.com/coastalwhite/lemurs/blob/main/src/main.rs#L352

and you'll notice immediately after there is a call to drop the auth_session which does not implement a special drop function.

Actually it does:

lemurs/src/auth/mod.rs

Lines 11 to 12 in 1d4be7d

// This is used to keep the user session. If the struct is dropped then the user session is
// also automatically dropped.


Or that the UI thread keeps looping after a successful login 🤔 https://github.com/coastalwhite/lemurs/blob/main/src/ui/mod.rs#L463

Adding a break there really mucks things up.

@Freyert
Copy link

Freyert commented Sep 28, 2024

Was playing around with lldb and strace

[flax]# strace -p 687
strace: Process 687 
futex(0x60d4de057a58, FUTEX_WAIT_BITSET_PRIVATE, 4294967295, NULL, FUTEX_BITSET_MATCH_ANY) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=19799, si_uid=0} ---
+++ killed by SIGTERM +++

Seems like it just sits on this futex until I send it a sigterm.

@labre
Copy link

labre commented Dec 11, 2024

I’ve also hit this and found a workaround. I’ve just provided init scripts for non-systemd init systems like OpenRC, sysvinit and s6 with #217 and am using a slightly improved OpenRC script based on the one in the Gentoo user repository. The OpenRC script automatically restarts lemurs after kills.

I have noticed that quite a few processes remain after closing my sway session, so I figured, that I need to kill those sticky processes. Otherwise I would duplicate them on relogin. With that setup I use the following to stop my Sway session.

# /etc/sudoers
user hostname = NOPASSWD: /home/user/scripts/stopSession.sh
#!/bin/bash
# Make sure this is and its directory is owned by root.
# ~/scripts/stopSession.sh
killall process1
killall process2
# ...
chvt 1
pkill lemurs

Apparently it is also required to change the vt for lemurs to be able to restart. Probably the tty can’t be taken over by openvt otherwise.

With this setup I can reliably relogin after logout. Maybe this helps someone. In my experience other display managers usually restart on logout. Maybe lemurs should do something similar. I somehow doubt, that the session otherwise can be closed properly.

@diggit
Copy link

diggit commented Dec 27, 2024

@coastalwhite did you have opportunity to look into this issue?

@DianaNites
Copy link

I also cannot log back in as the same user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigation-needed This issue needs more investigation
Projects
None yet
Development

No branches or pull requests

8 participants