module/xwindow: handle poll() failures

This commit is contained in:
Daniel Eklöf 2021-12-17 11:42:59 +01:00
parent 96c75b7f73
commit 9cff50a39e
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <threads.h> #include <threads.h>
#include <libgen.h> #include <libgen.h>
@ -247,14 +248,24 @@ run(struct module *mod)
update_title(mod); update_title(mod);
mod->bar->refresh(mod->bar); mod->bar->refresh(mod->bar);
int ret = 1;
int xcb_fd = xcb_get_file_descriptor(m->conn); int xcb_fd = xcb_get_file_descriptor(m->conn);
while (true) { while (true) {
struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}, struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN},
{.fd = xcb_fd, .events = POLLIN}}; {.fd = xcb_fd, .events = POLLIN}};
poll(fds, 2, -1); if (poll(fds, sizeof(fds) / sizeof(fds[0]), -1) < 0) {
if (errno == EINTR)
continue;
if (fds[0].revents & POLLIN) LOG_ERRNO("failed to poll");
break; break;
}
if (fds[0].revents & POLLIN) {
ret = 0;
break;
}
for (xcb_generic_event_t *_e = xcb_wait_for_event(m->conn); for (xcb_generic_event_t *_e = xcb_wait_for_event(m->conn);
_e != NULL; _e != NULL;
@ -293,7 +304,7 @@ run(struct module *mod)
xcb_destroy_window(m->conn, m->monitor_win); xcb_destroy_window(m->conn, m->monitor_win);
xcb_disconnect(m->conn); xcb_disconnect(m->conn);
return 0; return ret;
} }
static struct exposable * static struct exposable *