Commit Graph

25 Commits

Author SHA1 Message Date
Gary Guo 4a065818c4 Document shell approach for Xwayland launching 2021-02-14 21:15:49 +01:00
Gary Guo 4d25153397 Use sh to handle SIGUSR1 and replace fork+exec with spawn 2021-02-14 21:15:49 +01:00
Uli Schlachter 4d012e17a0
XWayland: Use a fork helper process to launch Xwayland (#250)
* xwayland: Add LaunchHelper

Calling fork() in a multi-threaded process is a bad idea. I am getting
crashes at exit() and "man fork" says that only async-signal-safe
functions can be called after forking in a multi-threaded process.
exit() is not async-signal safe. Thus, forking needs to happen before
any threads are created.

This commit adds a LaunchHelper to the public API. This is a handle to a
forked child process. So far this does not do much, but the intention is
to use this later instead of fork()ing directly.

Signed-off-by: Uli Schlachter <psychon@znc.in>

* xwayland: Move the fork dance to LaunchHelper

No functional changes intended. This only moves the code over and does
not actually use the LaunchHelper for anything.

Signed-off-by: Uli Schlachter <psychon@znc.in>

* Move checking the launch status to LaunchHelper

This should again have no functional changes, but the error log output
might change slightly, since an IOError instead of a NixError is
returned.

Signed-off-by: Uli Schlachter <psychon@znc.in>

* xwayland: Set $DISPLAY earlier

This way, the WM already gets the correct value of $DISPLAY.

Signed-off-by: Uli Schlachter <psychon@znc.in>

* xwayland: Use the launch helper process

FD passing is now used to give the display number and the sockets to the
launch helper process. That process then forks of the actual process
that spawns Xwayland. Once Xwayland started, this is reported back with
another write on the pipe.

Signed-off-by: Uli Schlachter <psychon@znc.in>

* Add to the comment explaining Xwayland startup

Signed-off-by: Uli Schlachter <psychon@znc.in>

* Please rustfmt

Signed-off-by: Uli Schlachter <psychon@znc.in>

* Make clippy happy

Signed-off-by: Uli Schlachter <psychon@znc.in>
2020-12-29 15:41:29 +01:00
Uli Schlachter 06c44ede55 xwayland: Unlink X11 socket before binding to it
When starting xwayland with smithay, the first time I would get the
following output (do not ask what happens with displays 0, 1, 2. That's
not important right now):

Dec 29 14:13:31.031 DEBG Attempting to aquire an X11 display lock, D: 3, smithay_module: XWayland
Dec 29 14:13:31.032 DEBG X11 lock aquired, D: 3, smithay_module: XWayland
Dec 29 14:13:31.032 INFO Initialization completed, starting the main loop.

When killing the process with ctrl-c and starting it again, this
happened:

Dec 29 14:13:29.138 DEBG Attempting to aquire an X11 display lock, D: 3, smithay_module: XWayland
Dec 29 14:13:29.138 DEBG Failed to acquire lock, D: 3, smithay_module: XWayland
Dec 29 14:13:29.138 DEBG Lock was blocked by a defunct X11 server, trying again, D: 3, smithay_module: XWayland
Dec 29 14:13:29.139 DEBG Attempting to aquire an X11 display lock, D: 3, smithay_module: XWayland
Dec 29 14:13:29.139 DEBG X11 lock aquired, D: 3, smithay_module: XWayland
Dec 29 14:13:29.139 INFO Cleaning up X11 lock., smithay_module: XWayland
Dec 29 14:13:29.139 DEBG Attempting to aquire an X11 display lock, D: 4, smithay_module: XWayland
Dec 29 14:13:29.139 DEBG X11 lock aquired, D: 4, smithay_module: XWayland
Dec 29 14:13:29.139 INFO Initialization completed, starting the main loop.

The reason for the above behaviour is the
smithay::xwayland::x11_sockets::open_x11_sockets_for_display() failed.
The code successfully acquired the lock file, but then could not bind
the sockets. More specifically, the concrete socket in /tmp/.X11-unix/
already existed and thus bind() failed with EADDRINUSE.

(The code in X11Lock::grab() would then drop the already acquired
X11Lock and its Drop impl deleted the socket. Thus, when I started
things again, this time it successfully acquired display 3.)

Fix this removing the socket before trying to bind it.

This is also done by wlroots: In xwayland/sockets.x, the function
open_socket() has the same job as smithay's open_socket() function.
However, for non-abstract sockets, it would first unlink the target
before trying to bind:

        if (addr->sun_path[0]) {
                unlink(addr->sun_path);
        }

Signed-off-by: Uli Schlachter <psychon@znc.in>
2020-12-29 14:42:42 +01:00
Uli Schlachter 0f2faf6e91 Fix a typo in a log message
Signed-off-by: Uli Schlachter <psychon@znc.in>
2020-12-29 14:42:19 +01:00
Uli Schlachter 9e14e43bd8 Fix writing /tmp/.X{}.lock
Here is a lock file not created by smithay:

$ xxd /tmp/.X0-lock
00000000: 2020 2020 2020 2035 3537 0a                     557.

And this is a lock file created by smithay:

$ xxd /tmp/.X23-lock
00000000: 2020 2020 3130 3733 3332                     107332

As you see, the difference is a trailing newline (0x0a).

Lock files 1 to 22 where also created by smithay, because I started it a
couple of times. Reading these lock files fails, since the code expects
a file with at least 11 bytes of content: It uses read_exact() with a
buffer of length 11 in the Err()-branch of the match that this commit
modifies.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2020-12-26 14:21:29 +01:00
Uli Schlachter e427787353 xwayland: Use pipe instead of signal
Handling SIGUSR1 requires setting a signal handler, which is a global
resource. This can also cause problems in the presence of threads, since
every thread needs to set up a signal handler. This commit instead
changes the code to use a pipe instead (actually a UnixStream). When the
child closes the pipe, the parent wakes up and knows "to do something".

Fixes: https://github.com/Smithay/smithay/issues/246
Signed-off-by: Uli Schlachter <psychon@znc.in>
2020-12-25 22:29:39 +01:00
Eric Anholt 78d28165c3
Update nix to 0.19 (#237) 2020-10-31 18:33:18 +01:00
Victor Berger 1871b5ddae Make slog-stdlog into an optional dependency
slog-stdlog has a significant dependency tree and is basically unsued if
the downstream crate of Smithay always provides a logger (like anvil),
so it is not really needed.
2020-07-12 16:38:05 +02:00
Victor Berger b3aae074e4 Update calloop to 0.6 2020-04-28 11:13:25 +02:00
Victor Berger 8ab34f0081 Update dependencies. 2020-04-15 11:24:50 +02:00
Victor Berger b54d95c15d
Fix most clippy warnings (#185)
* Add missing documentation

* Fix most clippy warnings
2020-04-15 09:28:22 +02:00
Jonas Platte b8c20ebf30
Update wayland-rs to 0.25 (#171)
Update wayland-rs to 0.25 and calloop to 0.5

Co-authored-by: Victor Berger <victor.berger@m4x.org>
2020-04-05 19:01:08 +02:00
Victor Brekenfeld e5f8c351c7 Check for rust_2018_idioms 2018-12-16 19:31:38 +01:00
Victor Brekenfeld 71bd64a6bf Fix source code for 2018 edition 2018-12-16 19:31:38 +01:00
Victor Brekenfeld a3acd48cc3 fmt: rust 1.31 2018-12-08 18:31:08 +01:00
Colin Benner 734d2ce996 Fmt, spelling and capitalisation fixes (#113)
* Rename priviledged to privileged in backend/drm/mod.rs

* Fix a number of typos in comments

* Fix typos in string literals

* Wrap identifiers with backticks in doc comments

* Spelling and capitalisation in doc comments

* Use XWayland in comments

This seems to be the standard capitalisation, even though the executable
is called `Xwayland`.

* Use Glium instead of glium in comments

* Use DRM and API in comments

* Fix remaining occurrence of 'priviledged'

* Reformat code to appease Travis' rustfmt
2018-10-30 13:56:30 +01:00
Jonas Platte a77e29d9b5 lib: Use nested imports 2018-10-07 22:39:18 +02:00
Victor Berger 605895e30f update to wayland-rs 0.21 2018-09-25 00:31:58 +02:00
Colin Benner 6d31e9e5ff address more clippy warnings
Not sure how much of an improvement these are.
2018-06-29 12:30:42 +02:00
Colin Benner 4598ba0b48 address a bunch of clippy warnings 2018-06-28 11:33:49 +02:00
Victor Berger ff63209a17 XWayland: add logging 2018-05-04 10:55:31 +02:00
Victor Berger 2d8653d9d7 xwayland: take advantage of RAII for X11 lockfile 2018-05-01 12:08:01 +02:00
Victor Berger 5ae34d2613 xwayland: Use Rust's UnixStream instead of RawFd
THis allows us to take advantage of RAII for cleanup, among others.
2018-05-01 11:56:32 +02:00
Victor Berger d2cbadc670 xwayland: core infrastructure 2018-04-30 21:28:17 +02:00