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.
This commit is contained in:
Max Gautier 2023-03-09 14:13:57 +01:00
parent c13495e26e
commit e18a2f2adb
No known key found for this signature in database
2 changed files with 14 additions and 6 deletions

View file

@ -371,16 +371,19 @@ main(int argc, char *const *argv)
const char *xdg_runtime = getenv("XDG_RUNTIME_DIR"); const char *xdg_runtime = getenv("XDG_RUNTIME_DIR");
if (xdg_runtime != NULL) { if (xdg_runtime != NULL) {
const char *wayland_display = getenv("WAYLAND_DISPLAY"); const char *wayland_display = getenv("WAYLAND_DISPLAY");
if (wayland_display != NULL) if (wayland_display != NULL) {
snprintf(addr.sun_path, sizeof(addr.sun_path), snprintf(addr.sun_path, sizeof(addr.sun_path),
"%s/foot-%s.sock", xdg_runtime, wayland_display); "%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), snprintf(addr.sun_path, sizeof(addr.sun_path),
"%s/foot.sock", xdg_runtime); "%s/foot.sock", xdg_runtime);
connected = (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0);
if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0) }
connected = true; if (!connected)
else
LOG_WARN("%s: failed to connect, will now try /tmp/foot.sock", addr.sun_path); LOG_WARN("%s: failed to connect, will now try /tmp/foot.sock", addr.sun_path);
} }

View file

@ -146,6 +146,11 @@ terminfo entries manually, by copying *foot* and *foot-direct* to
Used to construct the default _PATH_ for the *--server-socket* Used to construct the default _PATH_ for the *--server-socket*
option, when no explicit argument is given (see above). 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 ## Variables set in the child process
*TERM* *TERM*