Skip to content

Commit 1311685

Browse files
sahinfemersion
authored andcommitted
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 00e9a94)
1 parent 75cfed6 commit 1311685

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

swaybar/bar.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ void bar_run(struct swaybar *bar) {
508508
}
509509
#if HAVE_TRAY
510510
if (bar->tray) {
511-
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar->tray->bus);
511+
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar);
512512
}
513513
#endif
514514
while (bar->running) {

swaybar/ipc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ static bool handle_barconfig_update(struct swaybar *bar, const char *payload,
518518
#if HAVE_TRAY
519519
if (oldcfg->tray_hidden && !newcfg->tray_hidden) {
520520
bar->tray = create_tray(bar);
521-
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in,
522-
bar->tray->bus);
521+
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar);
523522
} else if (bar->tray && newcfg->tray_hidden) {
524523
loop_remove_fd(bar->eventloop, bar->tray->fd);
525524
destroy_tray(bar->tray);

swaybar/tray/tray.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <cairo.h>
2+
#include <poll.h>
23
#include <stdint.h>
34
#include <stdlib.h>
45
#include <string.h>
@@ -90,9 +91,16 @@ void destroy_tray(struct swaybar_tray *tray) {
9091
}
9192

9293
void tray_in(int fd, short mask, void *data) {
93-
sd_bus *bus = data;
94+
struct swaybar *bar = data;
9495
int ret;
95-
while ((ret = sd_bus_process(bus, NULL)) > 0) {
96+
97+
if (mask & (POLLHUP | POLLERR)) {
98+
sway_log(SWAY_ERROR, "D-Bus connection closed unexpectedly");
99+
bar->running = false;
100+
return;
101+
}
102+
103+
while ((ret = sd_bus_process(bar->tray->bus, NULL)) > 0) {
96104
// This space intentionally left blank
97105
}
98106
if (ret < 0) {

0 commit comments

Comments
 (0)