complexlogic / flex-launcher

A customizable HTPC application launcher for Windows and Linux
https://complexlogic.github.io/flex-launcher/
The Unlicense
226 stars 13 forks source link

Seg Fault with system-sleep script #23

Open smoores-dev opened 1 year ago

smoores-dev commented 1 year ago

I'm on Ubuntu 22.10. I've added a script to send some CEC commands to /usr/lib/systemd/system-sleep/cec-control.sh:

#!/usr/bin/env bash

if [ "${1}" == "pre" ]; then
  /bin/echo "standby '0'" | /usr/bin/cec-client -s
fi

And I also have a hotkey set to :sleep.

When I hit the hotkey, for some reason Flex Launcher crashes with a Segmentation Fault. The script itself runs just fine, and I don't see anything in the Flex Launcher logs. But if I comment out the script, Flex Launcher doesn't crash.

I'm not sure how best to debug more, but please let me know if there's any other information I can provide!

complexlogic commented 1 year ago

How are you executing the script? Can you post the relevant part of your config file?

smoores-dev commented 1 year ago

The script is being executed by systemd just by virtue of being in that directory. The only relevant part of my config (at least, I think) is:

[Hotkeys]
Hotkey1=#40000065;:sleep
smoores-dev commented 1 year ago

More info about system-sleep if you're interested!

smoores-dev commented 1 year ago

I tried a few more things out just to have some more data points.

If I have a script like this:

# ~/.bin/suspend.sh
#!/usr/bin/env bash

/usr/bin/systemctl suspend

And leave the system-sleep script as above, and configure Flex Launcher with:

Hotkey1=#40000065;/home/<username>/.bin/suspend.sh

Flex Launcher also crashes.

If I instead include the cec command in the script itself (and remove the system-sleep script):

# ~/.bin/cec-suspend.sh
#!/usr/bin/env bash

/bin/echo 'standby 0' | /usr/bin/cec-client -s
/usr/bin/systemctl suspend
Hotkey1=#40000065;/home/<username>/.bin/cec-suspend.sh

Then I need to run flex-launcher as root (so that cec-client has the permissions it needs) ... and that also gets a crash.

It's weird because in all of these scenarios, the scripts all execute successfully (the cec-client turns off the TV and the computer is out to sleep), but then Flex Launcher gets a seg fault!

complexlogic commented 1 year ago

It would help you you could use gdb to trace the segfault, which may assist in diagnosis. Build Flex Launcher from source, but pass -DCMAKE_BUILD_TYPE=Debug during the CMake generation step which will retain the debug symbols in the executable. Then, execute the following:

  1. gdb /path/to/flex-launcher
  2. run -d
  3. Reproduce the segfault
  4. backtrace

Then post the output.

smoores-dev commented 1 year ago
Thread 1 "flex-launcher" received signal SIGSEGV, Segmentation fault.
0x00007ffff7cfcf48 in decoration_frame_configure (frame=0x5555556b58a0, configuration=0x555555ec6030, user_data=0x5555555e1ba0) at ./src/video/wayland/SDL_waylandwindow.c:782
782        ./src/video/wayland/SDL_waylandwindow.c: Directory not empty.
(gdb) backtrace
#0    0x00007ffff7cfcf48 in decoration_frame_configure
      (frame=0x5555556b58a0, configuration=0x555555ec6030, user_data=0x5555555e1ba0)  at ./src/video/wayland/SDL_waylandwindow.c:782
#1    0x00007ffff74027ec in xdg_surface_configure
      (user_data=0x5555556b58a0, xdg_surface=<optimized out>, serial=355)
#2    0x00007ffff6faae2e in ffi_call_unix64 () at ../src/x86/unix64.S:105
#3    0x00007ffff6fa7493 in ffi_call_int
      (cif=<optimized out>, fn=<optimized out>, rvalue=<optimized out>, avalue=<optimized out>, closure=<optimized out>) at ../src/x86/ffi64.c:672
complexlogic commented 1 year ago

Thanks. Looks like it's actually an issue in SDL, then. Could you try to run SDL_VIDEODRIVER=x11 flex-launcher and try to reproduce again? That will enable XWayland compatibility mode, which would confirm it's an issue with the SDL Wayland backend if the segfault can not be reproduced.

smoores-dev commented 1 year ago

Interestingly, I still see a seg fault (and still seemingly in SDL):

Thread 1 "flex-launcher" received signal SIGSEGV, Segmentation fault.
0x00007ffff7cfcf5c in SDL_IBus_UpdateTextRect (rect=0x5555555f3c370), at ./src/core/linux/SDL_ibus.c:667
667      ./src/core/linux/SDL_ibus.c: Directory not empty.
(gdb) backtrace
#0    0x00007ffff7cfcf5c in SDL_IBus_UpdateTextRect (rect=0x5555555f3c370 at ./src/core/linux/SDL_ibus.c:667
#1    0x00007ffff7dd1086 in SDL_IME_UpdateTextRect (rect=0x0) at ./src/core/linux/SDL_ime.c:142
#2    X11_DispatchEvent (_this=0x5555555abde0, _this@entry=<error reading variable: Cannot access memory at address 0x7fffffffdcb8, xevent=0x7fffffffdce0, xevent@entry=<error reading variable: Cannot access memory at address 0x7fffffffdca8)
      at ./src/video/x11/SDL_x11events.c:1169
#3    0x00007ffff7dd297b in X11_PumpEvents (_this=<error reading variable: Cannot access memory at address 0x7fffffffdcb8)
      at ./src/video/x11/SDL_x11events.c:1715
Backtrace stopped: Cannot access memory at address 0x7fffffffddd8