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

Crash when DISPLAY is unset #22

Open
eras opened this issue May 24, 2021 · 3 comments
Open

Crash when DISPLAY is unset #22

eras opened this issue May 24, 2021 · 3 comments

Comments

@eras
Copy link

eras commented May 24, 2021

I wrote https://github.com/eras/ClickMuteJack/ using this and noticed that it crashes if I start it with an empty DISPLAY:

% DISPLAY= target/debug/click_mute
Loaded config from click_mute.ini
XOpenDisplay() failed!

zsh: segmentation fault  DISPLAY= target/debug/click_mute

Doesn't seem like there's a way to handle this problem in user code.

Similar crash happens with non-empty DISPLAY but no permission for the server, which is how I noticed this issue in the first place. The gui code is here: https://github.com/eras/ClickMuteJack/blob/master/src/gui.rs

@eras
Copy link
Author

eras commented May 24, 2021

gdb backtrace:

XOpenDisplay() failed!


Thread 2 "click_mute" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff66f2700 (LWP 3588334)]
0x00005555556df887 in <std::ffi::c_str::CString as core::ops::drop::Drop>::drop (
    self=0x7ffff66f0e88)
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/ffi/c_str.rs:770
770	/rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/ffi/c_str.rs: No such file or directory.
(gdb) bt
#0  0x00005555556df887 in <std::ffi::c_str::CString as core::ops::drop::Drop>::drop (
    self=0x7ffff66f0e88)
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/ffi/c_str.rs:770
#1  0x00005555556da553 in core::ptr::drop_in_place<std::ffi::c_str::CString> ()
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/core/src/ptr/mod.rs:192
#2  0x00005555556d4da5 in sapp_linux::_sapp_fail (
    msg=0x5555559496f3 "XOpenDisplay() failed!\n")
    at /home/flux/.cargo/registry/src/github.com-1ecc6299db9ec823/sapp-linux-0.1.12/src/lib.rs:1150
#3  0x00005555556d7bd0 in sapp_linux::sapp_run (desc=0x7ffff66f10d8)
    at /home/flux/.cargo/registry/src/github.com-1ecc6299db9ec823/sapp-linux-0.1.12/src/lib.rs:2731
#4  0x00005555555e363e in miniquad::start (conf=..., f=...)
    at /home/flux/.cargo/registry/src/github.com-1ecc6299db9ec823/miniquad-0.3.0-alpha.30/src/lib.rs:432
#5  0x0000555555604369 in click_mute::gui::main (quit=..., click_info=..., config=..., 
    control=...) at src/gui.rs:389
#6  0x000055555561d7e6 in click_mute::main::{{closure}} () at src/main.rs:40
#7  0x00005555555df770 in std::sys_common::backtrace::__rust_begin_short_backtrace (
    f=...)
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/sys_common/backtrace.rs:125
#8  0x0000555555626a2c in std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}} () at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/thread/mod.rs:481
#9  0x00005555555da2b0 in <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once (self=..., _args=())
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/panic.rs:346
#10 0x000055555561c967 in std::panicking::try::do_call (
    data=0x7ffff66f1b68 "\300\205\266UUU\000")
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/panicking.rs:401
#11 0x000055555561cc0d in __rust_try ()
#12 0x000055555561c6c1 in std::panicking::try (f=...)
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/panicking.rs:365
#13 0x00005555555da370 in std::panic::catch_unwind (f=...)
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/panic.rs:433
#14 0x00005555556264bc in std::thread::Builder::spawn_unchecked::{{closure}} ()
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/std/src/thread/mod.rs:480
#15 0x00005555555fa2ce in core::ops::function::FnOnce::call_once{{vtable-shim}} ()
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/core/src/ops/function.rs:227
#16 0x000055555591b727 in <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once ()
    at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/alloc/src/boxed.rs:1575
--Type <RET> for more, q to quit, c to continue without paging--c
#17 <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rustc/3e99439f4dacc8ba0d2ca48d221694362d587927/library/alloc/src/boxed.rs:1575
#18 std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:71
#19 0x00007ffff7b1efa3 in start_thread (arg=<optimized out>) at pthread_create.c:486
#20 0x00007ffff78cc4cf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) 

@not-fl3
Copy link
Owner

not-fl3 commented May 24, 2021

What is the expected behavior here? No DISPLAY means no X server running and miniquad depends on X
Any other X apps do not work without DISPLAY either:

> DISPLAY= xterm
xterm: Xt error: Can't open display: 
xterm: DISPLAY is not set

@not-fl3
Copy link
Owner

not-fl3 commented May 24, 2021

Made a small fix and now it properly exits without a segfault: not-fl3/miniquad#208
It would be better if miniquad::start would return an error instead of just exit(0), so lets keep this issue open

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

2 participants