diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2023-06-05 00:16:26 +0200 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2023-06-05 01:27:41 +0200 |
commit | 4ae6735c9f899815325a100a4019a7b385662bb4 (patch) | |
tree | 844ffd28393f1394abee6c8fe8c0fda045f36cea | |
parent | b7316c5cc1a6b272bbba84c9f93aa49a1e7efb0e (diff) | |
download | klibc-4ae6735c9f899815325a100a4019a7b385662bb4.tar.gz |
[klibc] ipconfig: Handle error events from poll
When poll returns events for a socket other than POLLRDNORM, such as
POLLERR, we do not read from the socket but keep polling on it. This
results in busy-polling while the error state persists.
In case some other event is returned, put the device into DEVST_ERROR
state for 1 second.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | usr/kinit/ipconfig/main.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c index 32e3dd1f3bfc86..d45be3548cd040 100644 --- a/usr/kinit/ipconfig/main.c +++ b/usr/kinit/ipconfig/main.c @@ -404,6 +404,12 @@ static void process_timeout_event(struct state *s, time_t now) } } +static void process_error_event(struct state *s, time_t now) +{ + s->state = DEVST_ERROR; + s->expire = now + 1; +} + static struct state *slist; struct netdev *ifaces; @@ -420,8 +426,11 @@ static int do_pkt_recv(int nr, struct pollfd *fds, time_t now) for (i = 0, s = slist; s && nr; s = s->next) { if (s->dev->pkt_fd != fds[i].fd) continue; - if (fds[i].revents & POLLRDNORM) { - ret |= process_receive_event(s, now); + if (fds[i].revents) { + if (fds[i].revents & POLLRDNORM) + ret |= process_receive_event(s, now); + else + process_error_event(s, now); nr--; } i++; |