From 71b0582584ac5de97141ea207ddf17f7c938b2df Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 26 Jul 2017 16:12:30 +0200 Subject: axwrapper: Compute nfds argument of select() instead of using a constant. In particular this remove reliance on how file descriptors are assigned and ensures we don't pass an unnecessarily high nfds argument to select. Signed-off-by: Ralf Baechle --- ax25/axwrapper.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ax25/axwrapper.c') diff --git a/ax25/axwrapper.c b/ax25/axwrapper.c index e9dcff4..8f2390b 100644 --- a/ax25/axwrapper.c +++ b/ax25/axwrapper.c @@ -161,13 +161,22 @@ int main(int argc, char **argv) while (1) { FD_ZERO(&fdset); + int maxfd = -1; + FD_SET(STDIN_FILENO, &fdset); + if (STDIN_FILENO > maxfd) + maxfd = STDIN_FILENO + 1; FD_SET(pipe_out[0], &fdset); + if (pipe_out[0] > maxfd) + maxfd = pipe_out[0] + 1; FD_SET(pipe_err[0], &fdset); + if (pipe_err[0] > maxfd) + maxfd = pipe_err[0] + 1; + tv.tv_sec = 0; tv.tv_usec = FLUSHTIMEOUT; - len = select(256, &fdset, NULL, NULL, &tv); + len = select(maxfd, &fdset, NULL, NULL, &tv); if (len == -1) { if (errno == EINTR) continue; -- cgit v1.2.3