Since the event(s) passed to a callback can be a mask of all events
authorkrw <krw@openbsd.org>
Sun, 13 Jul 2014 15:38:09 +0000 (15:38 +0000)
committerkrw <krw@openbsd.org>
Sun, 13 Jul 2014 15:38:09 +0000 (15:38 +0000)
of interest and EV_WRITE is or'ed into the interesting events, it
is more correct to check both events each time. Pointed out by
Claudio.

ok henning@ claudio@

usr.sbin/ypldap/ldapclient.c
usr.sbin/ypldap/ypldap.c
usr.sbin/ypldap/ypldap_dns.c

index e315969..486cb3e 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldapclient.c,v 1.29 2014/07/13 12:07:59 krw Exp $ */
+/* $OpenBSD: ldapclient.c,v 1.30 2014/07/13 15:38:09 krw Exp $ */
 
 /*
  * Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org>
@@ -152,7 +152,7 @@ client_sig_handler(int sig, short event, void *p)
 }
 
 void
-client_dispatch_dns(int fd, short event, void *p)
+client_dispatch_dns(int fd, short events, void *p)
 {
        struct imsg              imsg;
        u_int16_t                dlen;
@@ -166,21 +166,21 @@ client_dispatch_dns(int fd, short event, void *p)
        struct imsgev           *iev = env->sc_iev_dns;
        struct imsgbuf          *ibuf = &iev->ibuf;
 
-       switch (event) {
-       case EV_READ:
+       if ((events & (EV_READ | EV_WRITE)) == 0)
+               fatalx("unknown event");
+
+       if (events & EV_READ) {
                if ((n = imsg_read(ibuf)) == -1)
                        fatal("imsg_read error");
                if (n == 0)
                        shut = 1;
-               break;
-       case EV_WRITE:
+       }
+       if (events & EV_WRITE) {
                if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
                if (n == 0)
                        shut = 1;
                goto done;
-       default:
-               fatalx("unknown event");
        }
 
        for (;;) {
@@ -260,7 +260,7 @@ done:
 }
 
 void
-client_dispatch_parent(int fd, short event, void *p)
+client_dispatch_parent(int fd, short events, void *p)
 {
        int                      n;
        int                      shut = 0;
@@ -269,22 +269,21 @@ client_dispatch_parent(int fd, short event, void *p)
        struct imsgev           *iev = env->sc_iev;
        struct imsgbuf          *ibuf = &iev->ibuf;
 
+       if ((events & (EV_READ | EV_WRITE)) == 0)
+               fatalx("unknown event");
 
-       switch (event) {
-       case EV_READ:
+       if (events & EV_READ) {
                if ((n = imsg_read(ibuf)) == -1)
                        fatal("imsg_read error");
                if (n == 0)
                        shut = 1;
-               break;
-       case EV_WRITE:
+       }
+       if (events & EV_WRITE) {
                if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
                if (n == 0)
                        shut = 1;
                goto done;
-       default:
-               fatalx("unknown event");
        }
 
        for (;;) {
index 27208c1..5f7b479 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ypldap.c,v 1.13 2014/07/13 12:07:59 krw Exp $ */
+/*     $OpenBSD: ypldap.c,v 1.14 2014/07/13 15:38:09 krw Exp $ */
 
 /*
  * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -346,7 +346,7 @@ make_uids:
 }
 
 void
-main_dispatch_client(int fd, short event, void *p)
+main_dispatch_client(int fd, short events, void *p)
 {
        int              n;
        int              shut = 0;
@@ -356,21 +356,21 @@ main_dispatch_client(int fd, short event, void *p)
        struct idm_req   ir;
        struct imsg      imsg;
 
-       switch (event) {
-       case EV_READ:
+       if ((events & (EV_READ | EV_WRITE)) == 0)
+               fatalx("unknown event");
+
+       if (events & EV_READ) {
                if ((n = imsg_read(ibuf)) == -1)
                        fatal("imsg_read error");
                if (n == 0)
                        shut = 1;
-               break;
-       case EV_WRITE:
+       }
+       if (events & EV_WRITE) {
                if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
                if (n == 0)
                        shut = 1;
                goto done;
-       default:
-               fatalx("unknown event");
        }
 
        for (;;) {
index 677b03a..1e4aa6b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ypldap_dns.c,v 1.6 2014/07/13 12:07:59 krw Exp $ */
+/*     $OpenBSD: ypldap_dns.c,v 1.7 2014/07/13 15:38:09 krw Exp $ */
 
 /*
  * Copyright (c) 2003-2008 Henning Brauer <henning@openbsd.org>
@@ -122,7 +122,7 @@ ypldap_dns(int pipe_ntp[2], struct passwd *pw)
 }
 
 void
-dns_dispatch_imsg(int fd, short event, void *p)
+dns_dispatch_imsg(int fd, short events, void *p)
 {
        struct imsg              imsg;
        int                      n, cnt;
@@ -134,21 +134,21 @@ dns_dispatch_imsg(int fd, short event, void *p)
        struct imsgbuf          *ibuf = &iev->ibuf;
        int                      shut = 0;
 
-       switch (event) {
-       case EV_READ:
+       if ((events & (EV_READ | EV_WRITE)) == 0)
+               fatalx("unknown event");
+
+       if (events & EV_READ) {
                if ((n = imsg_read(ibuf)) == -1)
                        fatal("imsg_read error");
                if (n == 0)
                        shut = 1;
-               break;
-       case EV_WRITE:
+       }
+       if (events & EV_WRITE) {
                if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
                if (n == 0)
                        shut = 1;
                goto done;
-       default:
-               fatalx("unknown event");
        }
 
        for (;;) {