mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 19:35:44 +02:00
Merge branch 'poll-failures'
This commit is contained in:
commit
1bb77e59f3
7 changed files with 110 additions and 27 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -178,15 +179,24 @@ run(struct module *mod)
|
||||||
|
|
||||||
bar->refresh(bar);
|
bar->refresh(bar);
|
||||||
|
|
||||||
|
int ret = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
struct pollfd fds[] = {
|
struct pollfd fds[] = {
|
||||||
{.fd = mod->abort_fd, .events = POLLIN},
|
{.fd = mod->abort_fd, .events = POLLIN},
|
||||||
{.fd = udev_monitor_get_fd(mon), .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;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fds[0].revents & POLLIN) {
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
struct udev_device *dev = udev_monitor_receive_device(mon);
|
struct udev_device *dev = udev_monitor_receive_device(mon);
|
||||||
if (dev == NULL)
|
if (dev == NULL)
|
||||||
|
@ -209,7 +219,7 @@ run(struct module *mod)
|
||||||
udev_unref(udev);
|
udev_unref(udev);
|
||||||
|
|
||||||
close(current_fd);
|
close(current_fd);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module *
|
static struct module *
|
||||||
|
|
|
@ -428,7 +428,15 @@ run(struct module *mod)
|
||||||
{.fd = mod->abort_fd, .events = POLLIN},
|
{.fd = mod->abort_fd, .events = POLLIN},
|
||||||
{.fd = udev_monitor_get_fd(mon), .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) {
|
if (fds[0].revents & POLLIN) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -67,7 +68,6 @@ content(struct module *mod)
|
||||||
return exposable;
|
return exposable;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
static int
|
static int
|
||||||
run(struct module *mod)
|
run(struct module *mod)
|
||||||
{
|
{
|
||||||
|
@ -75,6 +75,8 @@ run(struct module *mod)
|
||||||
const struct bar *bar = mod->bar;
|
const struct bar *bar = mod->bar;
|
||||||
bar->refresh(bar);
|
bar->refresh(bar);
|
||||||
|
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
struct timespec _now;
|
struct timespec _now;
|
||||||
clock_gettime(CLOCK_REALTIME, &_now);
|
clock_gettime(CLOCK_REALTIME, &_now);
|
||||||
|
@ -120,19 +122,28 @@ run(struct module *mod)
|
||||||
now.tv_sec, now.tv_usec, timeout_ms);
|
now.tv_sec, now.tv_usec, timeout_ms);
|
||||||
|
|
||||||
struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}};
|
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;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fds[0].revents & POLLIN) {
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
bar->refresh(bar);
|
bar->refresh(bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module *
|
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));
|
struct private *m = calloc(1, sizeof(*m));
|
||||||
m->label = label;
|
m->label = label;
|
||||||
|
|
|
@ -251,7 +251,13 @@ wait_for_socket_create(const struct module *mod)
|
||||||
{.fd = fd, .events = POLLIN}
|
{.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) {
|
if (fds[0].revents & POLLIN) {
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -377,8 +383,9 @@ run(struct module *mod)
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
|
||||||
bool aborted = false;
|
bool aborted = false;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
while (!aborted) {
|
while (!aborted && ret == 0) {
|
||||||
|
|
||||||
if (m->conn != NULL) {
|
if (m->conn != NULL) {
|
||||||
mpd_connection_free(m->conn);
|
mpd_connection_free(m->conn);
|
||||||
|
@ -396,7 +403,7 @@ run(struct module *mod)
|
||||||
mtx_unlock(&mod->lock);
|
mtx_unlock(&mod->lock);
|
||||||
|
|
||||||
/* Keep trying to connect, until we succeed */
|
/* Keep trying to connect, until we succeed */
|
||||||
while (!aborted) {
|
while (!aborted && ret == 0) {
|
||||||
if (m->port == 0) {
|
if (m->port == 0) {
|
||||||
/* Use inotify to watch for socket creation */
|
/* Use inotify to watch for socket creation */
|
||||||
aborted = wait_for_socket_create(mod);
|
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
|
* host), wait for a while until we try to re-connect
|
||||||
* again.
|
* again.
|
||||||
*/
|
*/
|
||||||
struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}};
|
while (!aborted) {
|
||||||
int res = poll(fds, 1, 10 * 1000);
|
struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}};
|
||||||
|
int res = poll(fds, sizeof(fds) / sizeof(fds[0]), 10 * 1000);
|
||||||
|
|
||||||
if (res == 1) {
|
if (res < 0) {
|
||||||
assert(fds[0].revents & POLLIN);
|
if (errno == EINTR)
|
||||||
aborted = true;
|
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;
|
break;
|
||||||
|
|
||||||
/* Initial state (after establishing a connection) */
|
/* Initial state (after establishing a connection) */
|
||||||
|
@ -446,7 +464,14 @@ run(struct module *mod)
|
||||||
break;
|
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) {
|
if (fds[0].revents & POLLIN) {
|
||||||
aborted = true;
|
aborted = true;
|
||||||
|
@ -477,7 +502,7 @@ run(struct module *mod)
|
||||||
m->conn = NULL;
|
m->conn = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return aborted ? 0 : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct refresh_context {
|
struct refresh_context {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -547,16 +548,26 @@ run(struct module *mod)
|
||||||
* mount/unmount operations */
|
* mount/unmount operations */
|
||||||
int mount_info_fd = open("/proc/self/mountinfo", O_RDONLY);
|
int mount_info_fd = open("/proc/self/mountinfo", O_RDONLY);
|
||||||
|
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
struct pollfd fds[] = {
|
struct pollfd fds[] = {
|
||||||
{.fd = mod->abort_fd, .events = POLLIN},
|
{.fd = mod->abort_fd, .events = POLLIN},
|
||||||
{.fd = udev_monitor_get_fd(dev_mon), .events = POLLIN},
|
{.fd = udev_monitor_get_fd(dev_mon), .events = POLLIN},
|
||||||
{.fd = mount_info_fd, .events = POLLPRI},
|
{.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;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fds[0].revents & POLLIN) {
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
bool update = false;
|
bool update = false;
|
||||||
|
|
||||||
|
@ -587,7 +598,7 @@ run(struct module *mod)
|
||||||
|
|
||||||
udev_monitor_unref(dev_mon);
|
udev_monitor_unref(dev_mon);
|
||||||
udev_unref(udev);
|
udev_unref(udev);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module *
|
static struct module *
|
||||||
|
|
|
@ -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 */
|
/* 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) {
|
if (pfds[0].revents & POLLIN) {
|
||||||
ret = true;
|
ret = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -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 *
|
||||||
|
|
Loading…
Add table
Reference in a new issue