SIGALRM
is triggering an EINTR
error in select(2)
call. You must check whether the system call is returning a timeout, a file descriptor event or an error (and which kind of error too):
while (!finish) {
int s;
FD_ZERO(&in_fd);
FD_SET(dpy_fd, &in_fd);
s = select(dpy_fd+1, &in_fd, 0, 0, &tv)
if (s > 0) {
printf("Event Received!\n");
XNextEvent(disp->dpy, &e);
/* do something */
} else if (s == 0) {
/* This is probably where we should break the loop or reset the
* select(2) timeout, so... I chose to break it. If you don't
* do something about it you're gonna end up in a busy wait. */
break;
} else {
if (errno == EINTR) {
/* We've been interrupted by another signal, and it might be
* because of the alarm(3) (using the SIGALRM) or any other
* signal we have received externally. */
continue;
}
perror("Select failed");
/* Handle the error properly. */
}
}