aboutsummaryrefslogtreecommitdiff
path: root/swaybar
diff options
context:
space:
mode:
authorLuke Drummond <ldrumm@rtps.co>2020-06-11 01:29:07 +0100
committerSimon Ser <contact@emersion.fr>2020-06-12 14:45:40 +0200
commitc22caa54a8b40e152b141c18d32f3bad383d9d1c (patch)
tree3cfe6163f09beb36adbf6c84e371c43ecec6a577 /swaybar
parentbf8d23a836dcb307f151b20dbd8dfb04a6d9b275 (diff)
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.
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c9
-rw-r--r--swaybar/status_line.c3
2 files changed, 8 insertions, 4 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index f4dd4405..231c1ad7 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -413,10 +413,6 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
if (!ipc_initialize(bar)) {
return false;
}
- if (bar->config->status_command) {
- bar->status = status_line_init(bar->config->status_command);
- bar->status->bar = bar;
- }
bar->display = wl_display_connect(NULL);
if (!bar->display) {
@@ -445,6 +441,11 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
assert(pointer->cursor_surface);
}
+ if (bar->config->status_command) {
+ bar->status = status_line_init(bar->config->status_command);
+ bar->status->bar = bar;
+ }
+
#if HAVE_TRAY
if (!bar->config->tray_hidden) {
bar->tray = create_tray(bar);
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 <assert.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <json.h>
@@ -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);