aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2024-09-25 06:35:30 -0500
committerFurkan Sahin <furkan-dev@proton.me>2024-09-25 06:35:30 -0500
commit27529807557ea760c12458d1da212639ce839329 (patch)
tree409c60835e65dc6d85da58c72f1d0f29058c2c80
parent59f2a53be9b2a75d954f96842b16386e49be9ad5 (diff)
swaybar: Fix 100% cpu usage if dbus dies.
Currently, swaybar does not gracefully die if it detects that the dbus connection was lost. Although it's not recommended to restart dbus without restarting the compositor, it can very easily happen. In the case it does, compositor's tray should not consume 100% cpu until it has to be force killed. apply suggestions just setting the bar to not running will call teardown and unref the dbus. (cherry picked from commit 00e9a941523baa4afa1f9c077235aa7aa5e8aeab)
-rw-r--r--swaybar/bar.c2
-rw-r--r--swaybar/ipc.c3
-rw-r--r--swaybar/tray/tray.c12
3 files changed, 12 insertions, 5 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 5b1213a8..4d20f20f 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -508,7 +508,7 @@ void bar_run(struct swaybar *bar) {
}
#if HAVE_TRAY
if (bar->tray) {
- loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar->tray->bus);
+ loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar);
}
#endif
while (bar->running) {
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 03500bdf..71c9a4c5 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -518,8 +518,7 @@ static bool handle_barconfig_update(struct swaybar *bar, const char *payload,
#if HAVE_TRAY
if (oldcfg->tray_hidden && !newcfg->tray_hidden) {
bar->tray = create_tray(bar);
- loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in,
- bar->tray->bus);
+ loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar);
} else if (bar->tray && newcfg->tray_hidden) {
loop_remove_fd(bar->eventloop, bar->tray->fd);
destroy_tray(bar->tray);
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c
index b0545f4a..a4f382bf 100644
--- a/swaybar/tray/tray.c
+++ b/swaybar/tray/tray.c
@@ -1,4 +1,5 @@
#include <cairo.h>
+#include <poll.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -90,9 +91,16 @@ void destroy_tray(struct swaybar_tray *tray) {
}
void tray_in(int fd, short mask, void *data) {
- sd_bus *bus = data;
+ struct swaybar *bar = data;
int ret;
- while ((ret = sd_bus_process(bus, NULL)) > 0) {
+
+ if (mask & (POLLHUP | POLLERR)) {
+ sway_log(SWAY_ERROR, "D-Bus connection closed unexpectedly");
+ bar->running = false;
+ return;
+ }
+
+ while ((ret = sd_bus_process(bar->tray->bus, NULL)) > 0) {
// This space intentionally left blank
}
if (ret < 0) {