diff options
| author | Furkan Sahin <furkansahin824@proton.me> | 2024-09-25 06:35:30 -0500 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2024-09-28 16:23:21 +0200 |
| commit | 00e9a941523baa4afa1f9c077235aa7aa5e8aeab (patch) | |
| tree | 1107e55b125e0ce45a342e3a0ffed85c1af19bed /swaybar/tray | |
| parent | 63345977e2c411359a049c40cf2c1044a22b4f4a (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.
Diffstat (limited to 'swaybar/tray')
| -rw-r--r-- | swaybar/tray/tray.c | 12 |
1 files changed, 10 insertions, 2 deletions
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) { |
