zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
47.87k stars 2.81k forks source link

Linux: On wayland ZED tries to use XOrg when started with elevated permissions #12414

Open a-usr opened 4 months ago

a-usr commented 4 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Just as the title describes, if zed is started using sudo or directly from the root user it will try to connect to a XOrg server, even if that server is not running (because wayland is used instead).

Environment

Zed: v1.0.0 (Zed) OS: Linux 1.0.0 Memory: 31.2 GiB Architecture: x86_64

( I am using nixos )

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No log, but here is the output for when zed is run using sudo or from the root user:

Authorization required, but no authorization protocol specified

thread 'main' panicked at crates/gpui/src/platform/linux/x11/client.rs:123:75:
called `Result::unwrap()` on an `Err` value: IoError(Custom { kind: Other, error: UnknownError })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
jansol commented 4 months ago

This is probably because sudo resets environment variables, including WAYLAND_DISPLAY. There is not much Zed itself can do about that AFAIK. Some workarounds do exist though: https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo

mikayla-maki commented 4 months ago

Perhaps, rather than checking WAYLAND_DISPLAY ourselves, we should let libwayland figure it out and if it errors fallback to X11?

apricotbucket28 commented 4 months ago

Just as the title describes, if zed is started using sudo or directly from the root user it will try to connect to a XOrg server, even if that server is not running (because wayland is used instead).

Even for the very few GUI programs in my system that let me run them with sudo, they all start with X11 because sudo resets all environment variables. Use the -E flag with sudo to keep the current environment.

Asides, there's really no good reason to allow a GUI program to run as the super user: Firefox, Dolphin, KWrite, VSCode all prevent me from doing it. It causes many issues (like this one) and is a great security risk. In case we need to edit files with elevated privileges, we can use polkit.

ReillyBrogan commented 3 months ago

This would be solved by #13585 as it would no longer be necessary to open zed with elevated permissions when it can simply user an authenticated helper service to save system files in the first place.