Close connection/remove event handler when msgbuf_write() hits an
authorkrw <krw@openbsd.org>
Sun, 13 Jul 2014 12:07:59 +0000 (12:07 +0000)
committerkrw <krw@openbsd.org>
Sun, 13 Jul 2014 12:07:59 +0000 (12:07 +0000)
EOF.

ok jmatthew@ claudio@

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

index bf564c2..e315969 100644 (file)
@@ -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 {
index 08ff6ef..27208c1 100644 (file)
@@ -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 {
index 06e13f9..677b03a 100644 (file)
@@ -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 {