Catch unexpected socket polling errors.

The poll(2) system call may set POLLERR in the returned events.  Normally
no errors are returned unless specifically requested by setting an
appropriate socket option.  Nevertheless, the poll(2) API is quite generic,
and there is no guarantee that the kernel networking stack might push an
error event one day.  This patch adds defensive code in order to catch any
unexpected error condition.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2020-06-24 08:59:31 -07:00
parent b6fa222201
commit cb3fbc1010
1 changed files with 8 additions and 2 deletions

10
clock.c
View File

@ -1559,8 +1559,14 @@ int clock_poll(struct clock *c)
LIST_FOREACH(p, &c->ports, list) { LIST_FOREACH(p, &c->ports, list) {
/* Let the ports handle their events. */ /* Let the ports handle their events. */
for (i = 0; i < N_POLLFD; i++) { for (i = 0; i < N_POLLFD; i++) {
if (cur[i].revents & (POLLIN|POLLPRI)) { if (cur[i].revents & (POLLIN|POLLPRI|POLLERR)) {
event = port_event(p, i); if (cur[i].revents & POLLERR) {
pr_err("port %d: unexpected socket error",
port_number(p));
event = EV_FAULT_DETECTED;
} else {
event = port_event(p, i);
}
if (EV_STATE_DECISION_EVENT == event) { if (EV_STATE_DECISION_EVENT == event) {
c->sde = 1; c->sde = 1;
} }