#include <signal.h>
#include <sys/select.h>
+#include <errno.h>
#include <libtu/types.h>
#include <libtu/misc.h>
int nfds=0;
int ret=0;
- FD_ZERO(&rfds);
-
- set_input_fds(&rfds, &nfds);
#ifdef _POSIX_SELECT
{
sigset_t oldmask;
+
+ FD_ZERO(&rfds);
+ set_input_fds(&rfds, &nfds);
mainloop_block_signals(&oldmask);
#else
#warning "pselect() unavailable -- using dirty hacks"
{
- struct timeval tv_={0, 0}, *tv=&tv_;
+ struct timeval tv={0, 0};
/* If there are timers, make sure we return from select with
* some delay, if the timer signal happens right before
* entering select(). Race conditions with other signals
* we'll just have to ignore without pselect().
*/
- if(!libmainloop_get_timeout(tv))
- tv=NULL;
+ do{
+ FD_ZERO(&rfds);
+ set_input_fds(&rfds, &nfds);
- if(!mainloop_unhandled_signals())
- ret=select(nfds+1, &rfds, NULL, NULL, tv);
+ bool to=libmainloop_get_timeout(&tv);
+
+ if(mainloop_unhandled_signals()){
+ ret=0;
+ break;
+ }
+
+ ret=select(nfds+1, &rfds, NULL, NULL, to ? &tv : NULL);
+ }while(ret<0 && errno==EINTR && !mainloop_unhandled_signals());
}
#endif
if(ret>0)