mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-24 04:45:41 +02:00
module/mpd: handle poll() failures
This commit is contained in:
parent
8a11a3fbe5
commit
5d09e59f11
1 changed files with 36 additions and 11 deletions
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
while (!aborted) {
|
||||||
struct pollfd fds[] = {{.fd = mod->abort_fd, .events = POLLIN}};
|
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) {
|
if (res == 1) {
|
||||||
assert(fds[0].revents & POLLIN);
|
assert(fds[0].revents & POLLIN);
|
||||||
aborted = true;
|
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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue