From 311d12feef63f165cd6c235986cdb9a85019aa15 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Thu, 29 Sep 2011 15:01:48 +0000 Subject: [PATCH] Make a copy of the provided timeout before calling select(2). --- libnfc/buses/uart_posix.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libnfc/buses/uart_posix.c b/libnfc/buses/uart_posix.c index 044e9c9..78cf67b 100644 --- a/libnfc/buses/uart_posix.c +++ b/libnfc/buses/uart_posix.c @@ -267,6 +267,16 @@ select: FD_SET (iAbortFd, &rfds); } + /* + * Some implementations (e.g. Linux) of select(2) will update *timeout. + * Make a copy so that it will be updated on these systems, + */ + struct timeval fixed_timeout; + if (timeout) { + fixed_timeout = *timeout; + timeout = &fixed_timeout; + } + res = select (MAX(((serial_port_unix *) sp)->fd, iAbortFd) + 1, &rfds, NULL, NULL, timeout); if ((res < 0) && (EINTR == errno)) {