tevent: Rename wakeup fds
authorVolker Lendecke <vl@samba.org>
Wed, 7 Sep 2016 17:17:21 +0000 (19:17 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 4 Oct 2016 22:06:21 +0000 (00:06 +0200)
This makes the reading end of the signalling pipe special: If we have eventfd,
this is the same as the write fd. Without eventfd, it will have to be a
separate fd. This moves the requirement to #ifdef from the writing end to the
reading end. Why? We'll use the writing end somewhere else too soon, and this
patch avoids an #ifdef in that new place.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/tevent/tevent.c
lib/tevent/tevent_internal.h

index 331be0eb11089c71f2a892e30680ab5c17a3a396..87776ec1bb4f48e0e74e7b7e77047d49b207405e 100644 (file)
@@ -860,7 +860,7 @@ static void wakeup_pipe_handler(struct tevent_context *ev,
 
 int tevent_common_wakeup_init(struct tevent_context *ev)
 {
-       int ret;
+       int ret, read_fd;
 
        if (ev->wakeup_fde != NULL) {
                return 0;
@@ -871,7 +871,7 @@ int tevent_common_wakeup_init(struct tevent_context *ev)
        if (ret == -1) {
                return errno;
        }
-       ev->wakeup_fd = ret;
+       read_fd = ev->wakeup_fd = ret;
 #else
        {
                int pipe_fds[2];
@@ -879,21 +879,22 @@ int tevent_common_wakeup_init(struct tevent_context *ev)
                if (ret == -1) {
                        return errno;
                }
-               ev->wakeup_fd = pipe_fds[0];
-               ev->wakeup_write_fd = pipe_fds[1];
+               ev->wakeup_fd = pipe_fds[1];
+               ev->wakeup_read_fd = pipe_fds[0];
 
                ev_set_blocking(ev->wakeup_fd, false);
-               ev_set_blocking(ev->wakeup_write_fd, false);
+               ev_set_blocking(ev->wakeup_read_fd, false);
+
+               read_fd = ev->wakeup_read_fd;
        }
 #endif
 
-       ev->wakeup_fde = tevent_add_fd(ev, ev, ev->wakeup_fd,
-                                    TEVENT_FD_READ,
+       ev->wakeup_fde = tevent_add_fd(ev, ev, read_fd, TEVENT_FD_READ,
                                     wakeup_pipe_handler, NULL);
        if (ev->wakeup_fde == NULL) {
                close(ev->wakeup_fd);
 #ifndef HAVE_EVENTFD
-               close(ev->wakeup_write_fd);
+               close(ev->wakeup_read_fd);
 #endif
                return ENOMEM;
        }
@@ -915,7 +916,7 @@ int tevent_common_wakeup(struct tevent_context *ev)
                ret = write(ev->wakeup_fd, &val, sizeof(val));
 #else
                char c = '\0';
-               ret = write(ev->wakeup_write_fd, &c, 1);
+               ret = write(ev->wakeup_fd, &c, 1);
 #endif
        } while ((ret == -1) && (errno == EINTR));
 
@@ -932,6 +933,6 @@ static void tevent_common_wakeup_fini(struct tevent_context *ev)
 
        close(ev->wakeup_fd);
 #ifndef HAVE_EVENTFD
-       close(ev->wakeup_write_fd);
+       close(ev->wakeup_read_fd);
 #endif
 }
index d960544970816d9740705a2748a7afe3fc4f81d8..84ae5bcfc850bbe432d69b4ccb319d168c306f76 100644 (file)
@@ -277,9 +277,9 @@ struct tevent_context {
 
        /* pipe hack used with signal handlers */
        struct tevent_fd *wakeup_fde;
-       int wakeup_fd;
+       int wakeup_fd;          /* fd to write into */
 #ifndef HAVE_EVENT_FD
-       int wakeup_write_fd;
+       int wakeup_read_fd;
 #endif
 
        /* debugging operations */