From: krw Date: Sun, 13 Jul 2014 12:07:59 +0000 (+0000) Subject: Close connection/remove event handler when msgbuf_write() hits an X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=42a8b0bc20639c0d611f5b2933656aea801878e5;p=openbsd Close connection/remove event handler when msgbuf_write() hits an EOF. ok jmatthew@ claudio@ --- 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 @@ -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 @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -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 @@ -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 {