Close connections when msgbuf_write() returns 0.
authorkrw <krw@openbsd.org>
Sat, 12 Jul 2014 20:16:38 +0000 (20:16 +0000)
committerkrw <krw@openbsd.org>
Sat, 12 Jul 2014 20:16:38 +0000 (20:16 +0000)
ok claudio@

12 files changed:
usr.sbin/ldpd/lde.c
usr.sbin/ldpd/ldpd.c
usr.sbin/ldpd/ldpe.c
usr.sbin/ospf6d/ospf6d.c
usr.sbin/ospf6d/ospfe.c
usr.sbin/ospf6d/rde.c
usr.sbin/ospfd/ospfd.c
usr.sbin/ospfd/ospfe.c
usr.sbin/ospfd/rde.c
usr.sbin/ripd/rde.c
usr.sbin/ripd/ripd.c
usr.sbin/ripd/ripe.c

index c089ca2..99fd3b4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lde.c,v 1.28 2013/11/26 11:59:38 henning Exp $ */
+/*     $OpenBSD: lde.c,v 1.29 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -211,8 +211,10 @@ lde_dispatch_imsg(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        clock_gettime(CLOCK_MONOTONIC, &tp);
@@ -367,8 +369,10 @@ lde_dispatch_parent(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index a590ee4..621ff71 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ldpd.c,v 1.19 2013/11/26 11:59:38 henning Exp $ */
+/*     $OpenBSD: ldpd.c,v 1.20 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -339,8 +339,10 @@ main_dispatch_ldpe(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)
+                       shut = 1;
        }
 
        for (;;) {
@@ -415,8 +417,10 @@ main_dispatch_lde(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)
+                       shut = 1;
        }
 
        for (;;) {
index 47ac0dc..565da95 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ldpe.c,v 1.23 2013/11/26 11:59:38 henning Exp $ */
+/*     $OpenBSD: ldpe.c,v 1.24 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -330,8 +330,10 @@ ldpe_dispatch_main(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("ldpe_dispatch_main: msgbuf_write");
+               if (n == 0)
+                       shut = 1;
        }
 
        for (;;) {
@@ -470,8 +472,10 @@ ldpe_dispatch_lde(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("ldpe_dispatch_lde: msgbuf_write");
+               if (n == 0)
+                       shut = 1;
        }
 
        for (;;) {
index 6effc98..4478b52 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ospf6d.c,v 1.24 2013/11/13 20:49:49 benno Exp $ */
+/*     $OpenBSD: ospf6d.c,v 1.25 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -366,8 +366,10 @@ main_dispatch_ospfe(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
@@ -438,8 +440,10 @@ main_dispatch_rde(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index 7722637..38c705a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ospfe.c,v 1.42 2013/11/13 20:49:49 benno Exp $ */
+/*     $OpenBSD: ospfe.c,v 1.43 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -266,8 +266,10 @@ ospfe_dispatch_main(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
@@ -446,8 +448,10 @@ ospfe_dispatch_rde(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index cdd5dc9..b60d263 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rde.c,v 1.61 2013/11/13 20:49:49 benno Exp $ */
+/*     $OpenBSD: rde.c,v 1.62 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -266,8 +266,10 @@ rde_dispatch_imsg(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        clock_gettime(CLOCK_MONOTONIC, &tp);
@@ -638,8 +640,10 @@ rde_dispatch_parent(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index 5a18ea2..f24d947 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ospfd.c,v 1.80 2013/11/13 20:43:00 benno Exp $ */
+/*     $OpenBSD: ospfd.c,v 1.81 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -384,8 +384,10 @@ main_dispatch_ospfe(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
@@ -469,8 +471,10 @@ main_dispatch_rde(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index e7749c9..c4e5e1f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ospfe.c,v 1.87 2013/11/13 20:43:00 benno Exp $ */
+/*     $OpenBSD: ospfe.c,v 1.88 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -279,8 +279,10 @@ ospfe_dispatch_main(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
@@ -439,8 +441,10 @@ ospfe_dispatch_rde(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index 2441639..c1fa9f5 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rde.c,v 1.95 2013/11/13 20:43:00 benno Exp $ */
+/*     $OpenBSD: rde.c,v 1.96 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -261,8 +261,10 @@ rde_dispatch_imsg(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        clock_gettime(CLOCK_MONOTONIC, &tp);
@@ -624,8 +626,10 @@ rde_dispatch_parent(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index 8f03f5b..6915add 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rde.c,v 1.16 2013/11/19 22:25:32 benno Exp $ */
+/*     $OpenBSD: rde.c,v 1.17 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -198,8 +198,10 @@ rde_dispatch_imsg(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
@@ -298,8 +300,10 @@ rde_dispatch_parent(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index 3e08399..9ba92b9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ripd.c,v 1.22 2013/11/19 22:25:32 benno Exp $ */
+/*     $OpenBSD: ripd.c,v 1.23 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -353,8 +353,10 @@ main_dispatch_ripe(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
@@ -430,8 +432,10 @@ main_dispatch_rde(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
index ca6b7a8..6d9a8ad 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ripe.c,v 1.15 2013/11/26 12:00:19 henning Exp $ */
+/*     $OpenBSD: ripe.c,v 1.16 2014/07/12 20:16:38 krw Exp $ */
 
 /*
  * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -240,8 +240,10 @@ ripe_dispatch_main(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {
@@ -318,8 +320,10 @@ ripe_dispatch_rde(int fd, short event, void *bula)
                        shut = 1;
        }
        if (event & EV_WRITE) {
-               if (msgbuf_write(&ibuf->w) == -1 && errno != EAGAIN)
+               if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
                        fatal("msgbuf_write");
+               if (n == 0)     /* connection closed */
+                       shut = 1;
        }
 
        for (;;) {