Skip to content

Commit 27a323f

Browse files
committed
sss: mark closed fds as -1 in poll array
When a pin's file descriptor is closed after reading, it must be removed from the poll set. Unlike epoll (which automatically removes closed fds), poll() will return immediately with POLLNVAL for closed fds, creating an infinite loop since we only check for POLLIN/POLLPRI. Setting the fd to -1 causes poll() to ignore it, matching epoll behavior.
1 parent 726fcdc commit 27a323f

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/pins/sss/clevis-decrypt-sss.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ main(int argc, char *argv[])
227227
}
228228
if (pi >= nfds)
229229
continue;
230+
231+
/* Handle errors and hangups by closing the pin */
232+
if (pollfds[pi].revents & (POLLERR | POLLHUP | POLLNVAL)) {
233+
fclose(pin->file);
234+
pin->file = NULL;
235+
pollfds[pi].fd = -1;
236+
waitpid(pin->pid, NULL, 0);
237+
pin->pid = 0;
238+
pin->next->prev = pin->prev;
239+
pin->prev->next = pin->next;
240+
free(pin);
241+
break;
242+
}
243+
230244
if (!(pollfds[pi].revents & (POLLIN | POLLPRI)))
231245
continue;
232246

@@ -260,6 +274,8 @@ main(int argc, char *argv[])
260274

261275
fclose(pin->file);
262276
pin->file = NULL;
277+
/* Remove closed fd from poll set (poll ignores negative fds) */
278+
pollfds[pi].fd = -1;
263279

264280
waitpid(pin->pid, NULL, 0);
265281
pin->pid = 0;

0 commit comments

Comments
 (0)