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

Panic in user service on logout from desktop environment #47

Open
Majiir opened this issue Oct 6, 2023 · 3 comments
Open

Panic in user service on logout from desktop environment #47

Majiir opened this issue Oct 6, 2023 · 3 comments

Comments

@Majiir
Copy link

Majiir commented Oct 6, 2023

I use the systemd user service to run yubikey-touch-detector. I'm using NixOS 23.05 with GNOME 44.2.

When I log out of GNOME, the service logs the following and crashes:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x544e51]
goroutine 67 [running]:
github.com/esiqveland/notify.notifier.handleSignal({0xc00022a000, 0xc00028e540, 0xc0002ea000, 0xc000292160, 0x5d4710, 0xc0002e6c50, {0x602180, 0xc00011c000}}, 0x0)
        github.com/esiqveland/notify@v0.11.0/notification.go:274 +0x51
github.com/esiqveland/notify.notifier.eventLoop({0xc00022a000, 0xc00028e540, 0xc0002ea000, 0xc000292160, 0x5d4710, 0xc0002e6c50, {0x602180, 0xc00011c000}})
        github.com/esiqveland/notify@v0.11.0/notification.go:264 +0x109
created by github.com/esiqveland/notify.New
        github.com/esiqveland/notify@v0.11.0/notification.go:253 +0x391

This only happens when I log out from a GNOME session. If I log in or out of another TTY, the service continues to run.

The service stays in this failed state when logging back in.

@maximbaz
Copy link
Owner

maximbaz commented Oct 6, 2023

Interesting bug! I think this happens because you are using libnotify, which in turn obviously requires a graphical session to be running. There are two ways to fix it, either updating the systemd service to stop yubikey-touch-detector when you exit GNOME, or to update the libnotify detector to gracefully handle presence or absence of graphical session.

For the former, I suppose you'd want something like this:

[Unit]
Description=Detects when your YubiKey is waiting for a touch
Requires=yubikey-touch-detector.socket
PartOf=graphical-session.target
After=graphical-session.target

[Service]
ExecStart=/usr/bin/yubikey-touch-detector
Restart=always
EnvironmentFile=-%E/yubikey-touch-detector/service.conf

[Install]
Also=yubikey-touch-detector.socket
WantedBy=graphical-session.target

See if it helps you, we can't have that merged though, because libnotify is not a required dependency, so it would be wrong to enforce dependency on graphical-session onto everyone (also it would make it impossible to use the app purely in TTY).

Otherwise, I can merge a PR for a graceful handling of presence or absence of a graphical session, but since I don't use the libnotify functionality, I won't be the one implementing it.

@Majiir
Copy link
Author

Majiir commented Oct 7, 2023

Thanks for the tip!

  • Adding WantedBy=graphical-session.target ensures the service comes back on the next graphical login, although the panic is still logged.

  • Adding PartOf=graphical-session.target causes the service to stop properly on logout instead of panicking.

@thomaseizinger
Copy link

thomaseizinger commented Dec 19, 2023

I'm using NixOS 23.05

I ran into the same thing. Here is how I applied the above:

# File: configuration.nix

  systemd.packages = [ pkgs.yubikey-touch-detector ];
  systemd.user.services.yubikey-touch-detector = {
    path = [ pkgs.gnupg ];
    wantedBy = [ "graphical-session.target" ];
    partOf = [ "graphical-session.target" ]; # Otherwise the program segfaults in libnotify: https://github.com/maximbaz/yubikey-touch-detector/issues/47
  };

I think a proper fix would be to bundle the systemd config with https://github.com/NixOS/nixpkgs/blob/nixos-23.11/pkgs/tools/security/yubikey-touch-detector/default.nix but I don't (yet) know how to do that :)

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

No branches or pull requests

3 participants