tevent: remember the errno from select(), poll() and epoll_wait()
authorStefan Metzmacher <metze@samba.org>
Fri, 15 Feb 2013 10:24:59 +0000 (11:24 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Mar 2013 09:48:38 +0000 (10:48 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
lib/tevent/tevent_epoll.c
lib/tevent/tevent_poll.c
lib/tevent/tevent_select.c

index 61a8525d2bcfb11216890a063c94f8a7cc9e415a..99d4806db082511595924de129c9de2505b0d476 100644 (file)
@@ -313,6 +313,7 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval
 #define MAXEVENTS 1
        struct epoll_event events[MAXEVENTS];
        int timeout = -1;
+       int wait_errno;
 
        if (epoll_ev->epoll_fd == -1) return -1;
 
@@ -328,15 +329,16 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval
 
        tevent_trace_point_callback(epoll_ev->ev, TEVENT_TRACE_BEFORE_WAIT);
        ret = epoll_wait(epoll_ev->epoll_fd, events, MAXEVENTS, timeout);
+       wait_errno = errno;
        tevent_trace_point_callback(epoll_ev->ev, TEVENT_TRACE_AFTER_WAIT);
 
-       if (ret == -1 && errno == EINTR && epoll_ev->ev->signal_events) {
+       if (ret == -1 && wait_errno == EINTR && epoll_ev->ev->signal_events) {
                if (tevent_common_check_signal(epoll_ev->ev)) {
                        return 0;
                }
        }
 
-       if (ret == -1 && errno != EINTR) {
+       if (ret == -1 && wait_errno != EINTR) {
                epoll_panic(epoll_ev, "epoll_wait() failed", true);
                return -1;
        }
index 89b3bbc0b3aadb11bddff381be085f5a7aa40537..81a7176f8ee1031d200038e9f556d2250ad5323f 100644 (file)
@@ -444,6 +444,7 @@ static int poll_event_loop_poll(struct tevent_context *ev,
        int timeout = -1;
        unsigned first_fd;
        unsigned i;
+       int poll_errno;
 
        if (ev->signal_events && tevent_common_check_signal(ev)) {
                return 0;
@@ -462,9 +463,10 @@ static int poll_event_loop_poll(struct tevent_context *ev,
 
        tevent_trace_point_callback(poll_ev->ev, TEVENT_TRACE_BEFORE_WAIT);
        pollrtn = poll(poll_ev->fds, poll_ev->num_fds, timeout);
+       poll_errno = errno;
        tevent_trace_point_callback(poll_ev->ev, TEVENT_TRACE_AFTER_WAIT);
 
-       if (pollrtn == -1 && errno == EINTR && ev->signal_events) {
+       if (pollrtn == -1 && poll_errno == EINTR && ev->signal_events) {
                tevent_common_check_signal(ev);
                return 0;
        }
index 7e0c927dd94b2699a1364f86687561f9f57c19b3..ffb0d18c2e9f21cb737d782eb7b44ba6f8407229 100644 (file)
@@ -144,6 +144,7 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru
        fd_set r_fds, w_fds;
        struct tevent_fd *fde;
        int selrtn;
+       int select_errno;
 
        /* we maybe need to recalculate the maxfd */
        if (select_ev->maxfd == EVENT_INVALID_MAXFD) {
@@ -175,15 +176,16 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru
 
        tevent_trace_point_callback(select_ev->ev, TEVENT_TRACE_BEFORE_WAIT);
        selrtn = select(select_ev->maxfd+1, &r_fds, &w_fds, NULL, tvalp);
+       select_errno = errno;
        tevent_trace_point_callback(select_ev->ev, TEVENT_TRACE_AFTER_WAIT);
 
-       if (selrtn == -1 && errno == EINTR && 
+       if (selrtn == -1 && select_errno == EINTR &&
            select_ev->ev->signal_events) {
                tevent_common_check_signal(select_ev->ev);
                return 0;
        }
 
-       if (selrtn == -1 && errno == EBADF) {
+       if (selrtn == -1 && select_errno == EBADF) {
                /* the socket is dead! this should never
                   happen as the socket should have first been
                   made readable and that should have removed