mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 00:16:22 +01:00
Merge pull request #3692 from ianyfan/swaybar
Fix crash and memory leak on bar termination
This commit is contained in:
commit
cdbf8e8b25
4 changed files with 13 additions and 15 deletions
|
@ -46,6 +46,8 @@ struct swaybar {
|
||||||
#if HAVE_TRAY
|
#if HAVE_TRAY
|
||||||
struct swaybar_tray *tray;
|
struct swaybar_tray *tray;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool running;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct swaybar_output {
|
struct swaybar_output {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
@ -403,8 +404,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
|
||||||
static void display_in(int fd, short mask, void *data) {
|
static void display_in(int fd, short mask, void *data) {
|
||||||
struct swaybar *bar = data;
|
struct swaybar *bar = data;
|
||||||
if (wl_display_dispatch(bar->display) == -1) {
|
if (wl_display_dispatch(bar->display) == -1) {
|
||||||
bar_teardown(bar);
|
bar->running = false;
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ void bar_run(struct swaybar *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->tray->bus);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
while (1) {
|
while (bar->running) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (wl_display_flush(bar->display) == -1 && errno != EAGAIN) {
|
if (wl_display_flush(bar->display) == -1 && errno != EAGAIN) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -11,13 +11,7 @@
|
||||||
static struct swaybar swaybar;
|
static struct swaybar swaybar;
|
||||||
|
|
||||||
void sig_handler(int signal) {
|
void sig_handler(int signal) {
|
||||||
bar_teardown(&swaybar);
|
swaybar.running = false;
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sway_terminate(int code) {
|
|
||||||
bar_teardown(&swaybar);
|
|
||||||
exit(code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
@ -93,8 +87,6 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGTERM, sig_handler);
|
|
||||||
|
|
||||||
if (!bar_setup(&swaybar, socket_path)) {
|
if (!bar_setup(&swaybar, socket_path)) {
|
||||||
free(socket_path);
|
free(socket_path);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -102,6 +94,10 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
free(socket_path);
|
free(socket_path);
|
||||||
|
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
signal(SIGTERM, sig_handler);
|
||||||
|
|
||||||
|
swaybar.running = true;
|
||||||
bar_run(&swaybar);
|
bar_run(&swaybar);
|
||||||
bar_teardown(&swaybar);
|
bar_teardown(&swaybar);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -189,9 +189,9 @@ bool init_host(struct swaybar_host *host, char *protocol,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
sd_bus_slot_set_floating(reg_slot, 1);
|
sd_bus_slot_set_floating(reg_slot, 0);
|
||||||
sd_bus_slot_set_floating(unreg_slot, 1);
|
sd_bus_slot_set_floating(unreg_slot, 0);
|
||||||
sd_bus_slot_set_floating(watcher_slot, 1);
|
sd_bus_slot_set_floating(watcher_slot, 0);
|
||||||
|
|
||||||
sway_log(SWAY_DEBUG, "Registered %s", host->service);
|
sway_log(SWAY_DEBUG, "Registered %s", host->service);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue