forked from external/yambar
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 <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
@ -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 *
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <poll.h>
|
||||
#include <sys/time.h>
|
||||
|
@ -67,7 +68,6 @@ content(struct module *mod)
|
|||
return exposable;
|
||||
}
|
||||
|
||||
#include <pthread.h>
|
||||
static int
|
||||
run(struct module *mod)
|
||||
{
|
||||
|
@ -75,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);
|
||||
|
@ -120,19 +122,28 @@ 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 *
|
||||
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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
while (!aborted) {
|
||||
struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}};
|
||||
int res = poll(fds, 1, 10 * 1000);
|
||||
int res = poll(fds, sizeof(fds) / sizeof(fds[0]), 10 * 1000);
|
||||
|
||||
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 {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <poll.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -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 *
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <threads.h>
|
||||
#include <libgen.h>
|
||||
|
@ -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 *
|
||||
|
|
Loading…
Add table
Reference in a new issue