swaywm / swaylock

Screen locker for Wayland
MIT License
853 stars 202 forks source link

Swaylock red screens or doesn't work with udev rules #323

Open notmentaloutlaw opened 1 year ago

notmentaloutlaw commented 1 year ago

When using a udev rule that triggers as I remove my yubikey I made it run a script that will trigger swaylock.

Here is that script:

#!/bin/sh
su - myuser -c "env WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/1000 swaylock -c 00000000"

When I run that as root everything is fine and swaylock just works as normal. However when udev rules trigger that script sure swaylock opens but I can't get passed the lock screen the correct password does not work. Now if you had -f along with -c you will get another issue where after you type and press enter swaylock enters a red screen mode.

I am using swaylock 1.7.2 and I am on gentoo with openrc but I think this is reproducible in other distributions as well.

I am not sure what the root of the problem is but this would be a great if it does work.

notmentaloutlaw commented 1 year ago

Just for context my 99-usb-remove.rules in /etc/udev/rules.d/ is

ENV{DEVTYPE}=="usb_device",
ACTION=="remove",
SUBSYSTEM=="usb",
ENV{idVendor}=="[redacted]",
ENV{idProduct}=="[redacted]",
RUN+="/path/to/script"
mstoeckl commented 10 months ago

Now if you had -f along with -c you will get another issue where after you type and press enter swaylock enters a red screen mode.

I don't have any guesses as to why exactly the correct password is not working, but the red screen mode is something that Sway does when the lockscreen crashes, exits without unlocking, or makes a Wayland protocol error. Running with the --debug flag and looking at standard output/error, or checking if there was a core dump, will probably tell you which happened.

dragospe commented 4 months ago

Also seeing this issue on NixOS and the same swaylock version, running with a similar script. The relevant configuration is

       extraRules = ''
       ACTION=="remove",\
       ENV{ID_BUS}=="usb",\
       ENV{ID_MODEL_ID}=="0407",\
       ENV{ID_VENDOR_ID}=="1050",\
       ENV{ID_VENDOR}=="Yubico",\
       RUN+="${pkgs.coreutils}/bin/env WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/1000 ${pkgs.swaylock}/bin/swaylock -c 00000000 -d"
       '';

might dig into this some more with the debug flag once I figure out where everything is getting logged.

kennylevinsen commented 4 months ago

Red screen still means "lockscreen crashed". The udev rule should cause swaylock to run as your user, not as root.

One way to do that would be to write this as a small monitoring script (e.g., using python's udev package) which can be started from your sway config, rather than as a udev rule.

BreakingTV commented 1 week ago

Also seeing this issue on NixOS and the same swaylock version, running with a similar script. The relevant configuration is

       extraRules = ''
       ACTION=="remove",\
       ENV{ID_BUS}=="usb",\
       ENV{ID_MODEL_ID}=="0407",\
       ENV{ID_VENDOR_ID}=="1050",\
       ENV{ID_VENDOR}=="Yubico",\
       RUN+="${pkgs.coreutils}/bin/env WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/1000 ${pkgs.swaylock}/bin/swaylock -c 00000000 -d"
       '';

might dig into this some more with the debug flag once I figure out where everything is getting logged.

Do you found a way to fix it? Having the same error...

mstoeckl commented 1 week ago

Having the same error...

  1. Is swaylock crashing (red screen) for you when triggered by udev, or just not recognizing a correct password?
  2. The issue is still open, so a fix probably wasn't found yet. To help move this forward, could you please record the output with the --debug flag on (for example, by modifying the script to do something like swaylock --debug 2> /tmp/swaylock_log); or if there's a crash, get a stack trace from the coredump?