Merge pull request #336 from weidmueller/feature/fix-poll-function-calls

Fix error detection of poll function calls
pull/339/head
Marc Kleine-Budde 2022-01-27 16:05:50 +01:00 committed by GitHub
commit 4bd649d73a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 10 deletions

View File

@ -503,8 +503,11 @@ resend:
return 1;
}
if (polltimeout) {
int ret;
/* wait for the write socket (with timeout) */
if (poll(&fds, 1, polltimeout) < 0) {
ret = poll(&fds, 1, polltimeout);
if (ret == 0 || (ret == -1 && errno != -EINTR)) {
perror("poll");
return 1;
}

View File

@ -216,7 +216,7 @@ static void do_send()
}
err = poll(fds, 1, 1000);
if (err == -1 && errno != -EINTR) {
if (err == 0 || (err == -1 && errno != -EINTR)) {
perror("poll()");
exit(EXIT_FAILURE);
}

View File

@ -368,10 +368,12 @@ static int j1939cat_send_loop(struct j1939cat_priv *priv, int out_fd, char *buf,
int ret;
ret = poll(&fds, 1, priv->polltimeout);
if (ret == -EINTR)
continue;
if (ret < 0)
return -errno;
if (ret == -1) {
if (errno == -EINTR)
continue;
else
return -errno;
}
if (!ret)
return -ETIME;
if (!(fds.revents & events)) {
@ -572,10 +574,12 @@ static int j1939cat_recv(struct j1939cat_priv *priv)
int ret;
ret = poll(&fds, 1, priv->polltimeout);
if (ret == -EINTR)
continue;
if (ret < 0)
return -errno;
if (ret == -1) {
if (errno == -EINTR)
continue;
else
return -errno;
}
if (!ret)
continue;
if (!(fds.revents & events)) {