From c12db68363131d189d8410bf2994d70919229021 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Thu, 9 Mar 2023 14:13:57 +0100 Subject: [PATCH 1/4] footclient: fallback logic when socket paths don't exist Even if WAYLAND_DISPLAY / XDG_RUNTIME_DIR are defined, if we can't find the corresponding socket, we fallback to the path used when they are not defined. --- client.c | 15 +++++++++------ doc/footclient.1.scd | 5 +++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/client.c b/client.c index 99c7c1e8..41be68a9 100644 --- a/client.c +++ b/client.c @@ -374,16 +374,19 @@ main(int argc, char *const *argv) const char *xdg_runtime = getenv("XDG_RUNTIME_DIR"); if (xdg_runtime != NULL) { const char *wayland_display = getenv("WAYLAND_DISPLAY"); - if (wayland_display != NULL) + if (wayland_display != NULL) { snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot-%s.sock", xdg_runtime, wayland_display); - else + connected = (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0); + } + if (!connected) { + LOG_WARN("%s: failed to connect, will now try %s/foot.sock", + addr.sun_path, xdg_runtime); snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot.sock", xdg_runtime); - - if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0) - connected = true; - else + connected = (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0); + } + if (!connected) LOG_WARN("%s: failed to connect, will now try /tmp/foot.sock", addr.sun_path); } diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd index 1464700c..7d89b9ed 100644 --- a/doc/footclient.1.scd +++ b/doc/footclient.1.scd @@ -146,6 +146,11 @@ terminfo entries manually, by copying *foot* and *foot-direct* to Used to construct the default _PATH_ for the *--server-socket* option, when no explicit argument is given (see above). +If the socket at default _PATH_ does not exist, *footclient* will +fallback to the less specific path, with the following priority: +*$XDG\_RUNTIME\_DIR/foot-$WAYLAND\_DISPLAY.sock*, +*$XDG\_RUNTIME\_DIR/foot.sock*, */tmp/foot.sock*. + ## Variables set in the child process *TERM* From d3ffb0bde1a8c7a7eff43d1e32a38d314c5adc8a Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Tue, 14 Feb 2023 09:49:32 +0100 Subject: [PATCH 2/4] Ties systemd units to graphical-session.target - wayland-instance template target was a mistake. Systemd does not support simultaneous same user session, so stop trying to go against that. - Only start systemd units in Wayland environments. --- foot-server@.service.in => foot-server.service.in | 6 +++--- foot-server.socket | 9 +++++++++ foot-server@.socket | 5 ----- meson.build | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) rename foot-server@.service.in => foot-server.service.in (58%) create mode 100644 foot-server.socket delete mode 100644 foot-server@.socket diff --git a/foot-server@.service.in b/foot-server.service.in similarity index 58% rename from foot-server@.service.in rename to foot-server.service.in index c40bb454..47b81267 100644 --- a/foot-server@.service.in +++ b/foot-server.service.in @@ -1,13 +1,13 @@ [Service] ExecStart=@bindir@/foot --server=3 -Environment=WAYLAND_DISPLAY=%i UnsetEnvironment=LISTEN_PID LISTEN_FDS LISTEN_FDNAMES NonBlocking=true [Unit] Requires=%N.socket -Description=Foot terminal server mode for WAYLAND_DISPLAY=%i +Description=Foot terminal server mode Documentation=man:foot(1) +PartOf=graphical-session.target [Install] -WantedBy=wayland-instance@.target +WantedBy=graphical-session.target diff --git a/foot-server.socket b/foot-server.socket new file mode 100644 index 00000000..997e4363 --- /dev/null +++ b/foot-server.socket @@ -0,0 +1,9 @@ +[Socket] +ListenStream=%t/foot.sock + +[Unit] +PartOf=graphical-session.target +ConditionEnvironment=WAYLAND_DISPLAY + +[Install] +WantedBy=graphical-session.target diff --git a/foot-server@.socket b/foot-server@.socket deleted file mode 100644 index 71db51cb..00000000 --- a/foot-server@.socket +++ /dev/null @@ -1,5 +0,0 @@ -[Socket] -ListenStream=%t/foot-%i.sock - -[Install] -WantedBy=wayland-instance@.target diff --git a/meson.build b/meson.build index 1a00153c..cdccfa7e 100644 --- a/meson.build +++ b/meson.build @@ -329,13 +329,13 @@ if systemd.found() or custom_systemd_units_dir != '' configure_file( configuration: configuration, - input: 'foot-server@.service.in', + input: 'foot-server.service.in', output: '@BASENAME@', install_dir: systemd_units_dir ) install_data( - 'foot-server@.socket', + 'foot-server.socket', install_dir: systemd_units_dir) endif From 555edd60d45b987fb77792356fc2cfdd00a52ce7 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Tue, 14 Feb 2023 12:11:40 +0100 Subject: [PATCH 3/4] Update documentation regarding systemd units --- doc/foot.1.scd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/foot.1.scd b/doc/foot.1.scd index 770c7f32..3da6fd7e 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -121,14 +121,14 @@ the foot command line of a socket provided by a supervision daemon (such as systemd or s6), and use that socket as it's own. - Two systemd units (foot-server@.{service,socket}) are provided to use that - feature with systemd. They need to be instantiated with the value of - $WAYLAND_DISPLAY (multiples instances can co-exists). + Two systemd units (foot-server.{service,socket}) are provided to use that + feature with systemd. To use socket activation, only enable the + socket unit. Note that starting *foot --server* as a systemd service will use - the environment of the systemd user instance; thus, if you need specific - environment variables, you'll need to import them using *systemctl --user - import-environment* or use a drop-in for the foot-server service. + the environment of the systemd user instance; thus, you'll need + to import *$WAYLAND_DISPLAY* in it using *systemctl --user + import-environment WAYLAND_DISPLAY*. *-H*,*--hold* Remain open after child process exits. From 478474d0ceb10c0151a2ba3684d6e95cd0bf75ff Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Tue, 14 Feb 2023 12:04:26 +0100 Subject: [PATCH 4/4] Changelog: standard system target + footclient fallback --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ef784f2..29380684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,9 +53,16 @@ * Starlight theme (the default theme) updated to [V4][starlight-v4] * Background transparency (alpha) is now disabled in fullscreened windows ([#1416][1416]). +* Foot server systemd units now use the standard + graphical-session.target ([#1281][1281]). +* If `$XDG_RUNTIME_DIR/foot-$WAYLAND_DISPLAY.sock` does not exist, + `footclient` now tries `$XDG_RUNTIME_DIR/foot.sock`, then + `/tmp/foot.sock`, even if `$WAYLAND_DISPLAY` and/or + `$XDG_RUNTIME_DIR` are defined ([#1281][1281]). [starlight-v4]: https://github.com/CosmicToast/starlight/blob/v4/CHANGELOG.md#v4 [1416]: https://codeberg.org/dnkl/foot/issues/1416 +[1281]: https://codeberg.org/dnkl/foot/pulls/1281 ### Deprecated