From 3ab1db85542a692f5b2a65ad72f992a2d19953c5 Mon Sep 17 00:00:00 2001 From: Boian Bonev Date: Mon, 21 May 2012 14:23:16 +0300 Subject: [PATCH] always recreate FD_SETs for select after EINTR; do not rely on select changing timeout because it is not portable --- src/fping.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/fping.c b/src/fping.c index 464193d..f047d93 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2584,11 +2584,12 @@ char * sprint_tm( int t ) void u_sleep( int u_sec ) { int nfound; - struct timeval to; + struct timeval to, tokeep; fd_set readset, writeset; to.tv_sec = u_sec / 1000000; to.tv_usec = u_sec - ( to.tv_sec * 1000000 ); + tokeep = to; FD_ZERO( &readset ); FD_ZERO( &writeset ); @@ -2598,6 +2599,10 @@ select_again: if(nfound < 0) { if(errno == EINTR) { /* interrupted system call: redo the select */ + to = tokeep; + + FD_ZERO( &readset ); + FD_ZERO( &writeset ); goto select_again; } else { @@ -2632,7 +2637,7 @@ int recvfrom_wto( int s, char *buf, int len, FPING_SOCKADDR *saddr, long timo ) { unsigned int slen; int nfound, n; - struct timeval to; + struct timeval to, tokeep; fd_set readset, writeset; to.tv_sec = 0; @@ -2641,6 +2646,7 @@ int recvfrom_wto( int s, char *buf, int len, FPING_SOCKADDR *saddr, long timo ) to.tv_sec++; to.tv_usec -= 1000000; } + tokeep = to; FD_ZERO( &readset ); FD_ZERO( &writeset ); @@ -2651,6 +2657,11 @@ select_again: if(nfound < 0) { if(errno == EINTR) { /* interrupted system call: redo the select */ + to = tokeep; + + FD_ZERO( &readset ); + FD_ZERO( &writeset ); + FD_SET( s, &readset ); goto select_again; } else {