From 6612a9af9f7a9aece96629e6032a5600a1704777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:23:59 +0100 Subject: [PATCH 1/9] module/backlight: handle poll() failures --- modules/backlight.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/backlight.c b/modules/backlight.c index 292b067..af58280 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -178,15 +179,24 @@ run(struct module *mod) bar->refresh(bar); + int ret = 1; while (true) { struct pollfd fds[] = { {.fd = mod->abort_fd, .events = POLLIN}, {.fd = udev_monitor_get_fd(mon), .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; + } + + if (fds[0].revents & POLLIN) { + ret = 0; + break; + } struct udev_device *dev = udev_monitor_receive_device(mon); if (dev == NULL) @@ -209,7 +219,7 @@ run(struct module *mod) udev_unref(udev); close(current_fd); - return 0; + return ret; } static struct module * From f9229734501aca189c946479031c2b5e74fb9993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:25:37 +0100 Subject: [PATCH 2/9] module/battery: handle poll() failures --- modules/battery.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/battery.c b/modules/battery.c index e6526f5..0833310 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -428,7 +428,15 @@ run(struct module *mod) {.fd = mod->abort_fd, .events = POLLIN}, {.fd = udev_monitor_get_fd(mon), .events = POLLIN}, }; - poll(fds, 2, m->poll_interval > 0 ? m->poll_interval * 1000 : -1); + if (poll(fds, sizeof(fds) / sizeof(fds[0]), + m->poll_interval > 0 ? m->poll_interval * 1000 : -1) < 0) + { + if (errno == EINTR) + continue; + + LOG_ERRNO("failed to poll"); + break; + } if (fds[0].revents & POLLIN) { ret = 0; From 82ef48f666a55c1f09be92431481951bb36b19bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:27:53 +0100 Subject: [PATCH 3/9] module/clock: remove unused include --- modules/clock.c | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/clock.c b/modules/clock.c index 2956a40..eddc7be 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -67,7 +67,6 @@ content(struct module *mod) return exposable; } -#include static int run(struct module *mod) { From cdd0b5b4f06be3434b13205aa26be807282ab578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:28:05 +0100 Subject: [PATCH 4/9] module/clock: fold long line --- modules/clock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/clock.c b/modules/clock.c index eddc7be..49b832e 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -131,7 +131,8 @@ run(struct module *mod) } static struct module * -clock_new(struct particle *label, const char *date_format, const char *time_format, bool utc) +clock_new(struct particle *label, const char *date_format, + const char *time_format, bool utc) { struct private *m = calloc(1, sizeof(*m)); m->label = label; From 8a11a3fbe5a8094857d8df001ceaff9906847870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:28:14 +0100 Subject: [PATCH 5/9] module/clock: handle poll() failures --- modules/clock.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/clock.c b/modules/clock.c index 49b832e..15392aa 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -74,6 +75,8 @@ run(struct module *mod) const struct bar *bar = mod->bar; bar->refresh(bar); + int ret = 1; + while (true) { struct timespec _now; clock_gettime(CLOCK_REALTIME, &_now); @@ -119,15 +122,23 @@ run(struct module *mod) now.tv_sec, now.tv_usec, timeout_ms); struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}}; - poll(fds, 1, timeout_ms); + if (poll(fds, 1, timeout_ms) < 0) { + if (errno == EINTR) + continue; - if (fds[0].revents & POLLIN) + LOG_ERRNO("failed to poll"); break; + } + + if (fds[0].revents & POLLIN) { + ret = 0; + break; + } bar->refresh(bar); } - return 0; + return ret; } static struct module * From 5d09e59f111c6a053697852e218cefea280cf58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:29:26 +0100 Subject: [PATCH 6/9] module/mpd: handle poll() failures --- modules/mpd.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/modules/mpd.c b/modules/mpd.c index 274fdc8..b2e9e6e 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -251,7 +251,13 @@ wait_for_socket_create(const struct module *mod) {.fd = fd, .events = POLLIN} }; - poll(fds, 2, -1); + if (poll(fds, sizeof(fds) / sizeof(fds[0]), -1) < 0) { + if (errno == EINTR) + continue; + + LOG_ERRNO("failed to poll"); + break; + } if (fds[0].revents & POLLIN) { ret = true; @@ -377,8 +383,9 @@ run(struct module *mod) struct private *m = mod->private; bool aborted = false; + int ret = 0; - while (!aborted) { + while (!aborted && ret == 0) { if (m->conn != NULL) { mpd_connection_free(m->conn); @@ -396,7 +403,7 @@ run(struct module *mod) mtx_unlock(&mod->lock); /* Keep trying to connect, until we succeed */ - while (!aborted) { + while (!aborted && ret == 0) { if (m->port == 0) { /* Use inotify to watch for socket creation */ aborted = wait_for_socket_create(mod); @@ -414,16 +421,27 @@ run(struct module *mod) * host), wait for a while until we try to re-connect * again. */ - struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}}; - int res = poll(fds, 1, 10 * 1000); + while (!aborted) { + struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}}; + int res = poll(fds, sizeof(fds) / sizeof(fds[0]), 10 * 1000); - if (res == 1) { - assert(fds[0].revents & POLLIN); - aborted = true; + if (res < 0) { + if (errno == EINTR) + continue; + + LOG_ERRNO("failed to poll"); + ret = 1; + break; + } + + if (res == 1) { + assert(fds[0].revents & POLLIN); + aborted = true; + } } } - if (aborted) + if (aborted || ret != 0) break; /* Initial state (after establishing a connection) */ @@ -446,7 +464,14 @@ run(struct module *mod) break; } - poll(fds, 2, -1); + if (poll(fds, sizeof(fds) / sizeof(fds[0]), -1) < 0) { + if (errno == EINTR) + continue; + + LOG_ERRNO("failed to poll"); + ret = 1; + break; + } if (fds[0].revents & POLLIN) { aborted = true; @@ -477,7 +502,7 @@ run(struct module *mod) m->conn = NULL; } - return 0; + return aborted ? 0 : ret; } struct refresh_context { From ffa86d84a5546c5a20f463b8eb3276c88415f885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:40:12 +0100 Subject: [PATCH 7/9] module/removables: handle poll() failures --- modules/removables.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/removables.c b/modules/removables.c index 3a54379..736317f 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -547,16 +548,26 @@ run(struct module *mod) * mount/unmount operations */ int mount_info_fd = open("/proc/self/mountinfo", O_RDONLY); + int ret = 1; + while (true) { struct pollfd fds[] = { {.fd = mod->abort_fd, .events = POLLIN}, {.fd = udev_monitor_get_fd(dev_mon), .events = POLLIN}, {.fd = mount_info_fd, .events = POLLPRI}, }; - poll(fds, 3, -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; + } + + if (fds[0].revents & POLLIN) { + ret = 0; + break; + } bool update = false; @@ -587,7 +598,7 @@ run(struct module *mod) udev_monitor_unref(dev_mon); udev_unref(udev); - return 0; + return ret; } static struct module * From 96c75b7f73697c1f2cd84f24fbec8aa240ae0570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:42:53 +0100 Subject: [PATCH 8/9] module/xkb: handle poll() failures --- modules/xkb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/xkb.c b/modules/xkb.c index 5c2c1f9..965664d 100644 --- a/modules/xkb.c +++ b/modules/xkb.c @@ -399,7 +399,14 @@ event_loop(struct module *mod, xcb_connection_t *conn, int xkb_event_base) }; /* Use poll() since xcb_wait_for_events() doesn't return on signals */ - poll(pfds, sizeof(pfds) / sizeof(pfds[0]), -1); + if (poll(pfds, sizeof(pfds) / sizeof(pfds[0]), -1) < 0) { + if (errno == EINTR) + continue; + + LOG_ERRNO("failed to poll"); + break; + } + if (pfds[0].revents & POLLIN) { ret = true; break; From 9cff50a39ef757074ebec258aad2b20e27bc61af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 17 Dec 2021 11:42:59 +0100 Subject: [PATCH 9/9] module/xwindow: handle poll() failures --- modules/xwindow.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/xwindow.c b/modules/xwindow.c index 3925f4f..baf1239 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -247,14 +248,24 @@ run(struct module *mod) update_title(mod); mod->bar->refresh(mod->bar); + int ret = 1; + int xcb_fd = xcb_get_file_descriptor(m->conn); while (true) { struct pollfd fds[] = {{.fd = mod->abort_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; + } + + if (fds[0].revents & POLLIN) { + ret = 0; + break; + } for (xcb_generic_event_t *_e = xcb_wait_for_event(m->conn); _e != NULL; @@ -293,7 +304,7 @@ run(struct module *mod) xcb_destroy_window(m->conn, m->monitor_win); xcb_disconnect(m->conn); - return 0; + return ret; } static struct exposable *