diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2014-07-13 12:08:00 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2014-07-13 12:08:00 +0000 |
commit | f1b98cae21f0f62799fbbc23fee97381c77bda62 (patch) | |
tree | 76c0d1f12ba252aa2d7d35e563b4d8887ed38bd8 | |
parent | c8394eebdedf4c4216a1b55c1b7b59ab8cbc8b52 (diff) |
Close connection/remove event handler when msgbuf_write() hits an
EOF.
ok jmatthew@ claudio@
-rw-r--r-- | usr.sbin/ypldap/ldapclient.c | 19 | ||||
-rw-r--r-- | usr.sbin/ypldap/ypldap.c | 12 | ||||
-rw-r--r-- | usr.sbin/ypldap/ypldap_dns.c | 11 |
3 files changed, 27 insertions, 15 deletions
diff --git a/usr.sbin/ypldap/ldapclient.c b/usr.sbin/ypldap/ldapclient.c index bf564c2214f..e31596929aa 100644 --- a/usr.sbin/ypldap/ldapclient.c +++ b/usr.sbin/ypldap/ldapclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldapclient.c,v 1.28 2013/11/26 12:02:59 henning Exp $ */ +/* $OpenBSD: ldapclient.c,v 1.29 2014/07/13 12:07:59 krw Exp $ */ /* * Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org> @@ -174,10 +174,11 @@ client_dispatch_dns(int fd, short event, void *p) shut = 1; break; case EV_WRITE: - if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN) + if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN) fatal("msgbuf_write"); - imsg_event_add(iev); - return; + if (n == 0) + shut = 1; + goto done; default: fatalx("unknown event"); } @@ -248,6 +249,7 @@ client_dispatch_dns(int fd, short event, void *p) imsg_compose_event(env->sc_iev, IMSG_END_UPDATE, 0, 0, -1, NULL, 0); +done: if (!shut) imsg_event_add(iev); else { @@ -276,10 +278,11 @@ client_dispatch_parent(int fd, short event, void *p) shut = 1; break; case EV_WRITE: - if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN) + if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN) fatal("msgbuf_write"); - imsg_event_add(iev); - return; + if (n == 0) + shut = 1; + goto done; default: fatalx("unknown event"); } @@ -332,6 +335,8 @@ client_dispatch_parent(int fd, short event, void *p) } imsg_free(&imsg); } + +done: if (!shut) imsg_event_add(iev); else { diff --git a/usr.sbin/ypldap/ypldap.c b/usr.sbin/ypldap/ypldap.c index 08ff6efdb60..27208c14640 100644 --- a/usr.sbin/ypldap/ypldap.c +++ b/usr.sbin/ypldap/ypldap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypldap.c,v 1.12 2012/03/15 01:44:22 jmatthew Exp $ */ +/* $OpenBSD: ypldap.c,v 1.13 2014/07/13 12:07:59 krw Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -27,6 +27,7 @@ #include <arpa/inet.h> #include <err.h> +#include <errno.h> #include <event.h> #include <fcntl.h> #include <unistd.h> @@ -363,10 +364,11 @@ main_dispatch_client(int fd, short event, void *p) shut = 1; break; case EV_WRITE: - if (msgbuf_write(&ibuf->w) == -1) + if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN) fatal("msgbuf_write"); - imsg_event_add(iev); - return; + if (n == 0) + shut = 1; + goto done; default: fatalx("unknown event"); } @@ -447,6 +449,8 @@ main_dispatch_client(int fd, short event, void *p) } imsg_free(&imsg); } + +done: if (!shut) imsg_event_add(iev); else { diff --git a/usr.sbin/ypldap/ypldap_dns.c b/usr.sbin/ypldap/ypldap_dns.c index 06e13f9f11b..677b03aa042 100644 --- a/usr.sbin/ypldap/ypldap_dns.c +++ b/usr.sbin/ypldap/ypldap_dns.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypldap_dns.c,v 1.5 2012/03/16 01:57:42 jmatthew Exp $ */ +/* $OpenBSD: ypldap_dns.c,v 1.6 2014/07/13 12:07:59 krw Exp $ */ /* * Copyright (c) 2003-2008 Henning Brauer <henning@openbsd.org> @@ -142,10 +142,11 @@ dns_dispatch_imsg(int fd, short event, void *p) shut = 1; break; case EV_WRITE: - if (msgbuf_write(&ibuf->w) == -1) + if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN) fatal("msgbuf_write"); - imsg_event_add(iev); - return; + if (n == 0) + shut = 1; + goto done; default: fatalx("unknown event"); } @@ -189,6 +190,8 @@ dns_dispatch_imsg(int fd, short event, void *p) } imsg_free(&imsg); } + +done: if (!shut) imsg_event_add(iev); else { |