From c22caa54a8b40e152b141c18d32f3bad383d9d1c Mon Sep 17 00:00:00 2001 From: Luke Drummond Date: Thu, 11 Jun 2020 01:29:07 +0100 Subject: swaybar: ensure correct init order for status_line `$WAYLAND_SOCKET` is unset by `wl_display_connect` after it has successfully connected to the wayland socket. However, subprocesses spawned by swaybar (status-command) don't have access to waybar's fds as $WAYLAND_SOCKET is O_CLOEXEC. This means any status command which itself tries to connect to wayland will fail if this environment variable is set. Reorder display and status-command initialization so that this variable is not set and add an assert so we can enforce this invariant in future. --- swaybar/status_line.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'swaybar/status_line.c') diff --git a/swaybar/status_line.c b/swaybar/status_line.c index fb9271f8..71ceb1d0 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c @@ -1,4 +1,5 @@ #define _POSIX_C_SOURCE 200809L +#include #include #include #include @@ -153,6 +154,8 @@ struct status_line *status_line_init(char *cmd) { exit(1); } + assert(!getenv("WAYLAND_SOCKET") && "display must be initialized before " + " starting `status-command`; WAYLAND_SOCKET should not be set"); status->pid = fork(); if (status->pid == 0) { dup2(pipe_read_fd[1], STDOUT_FILENO); -- cgit v1.2.3-54-g00ecf