mirror of
https://github.com/swaywm/sway.git
synced 2024-11-10 12:33:50 +01:00
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.
This commit is contained in:
parent
bf8d23a836
commit
c22caa54a8
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user