diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-05-31 16:58:55 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-05-31 16:58:55 +0000 |
commit | 7d1f2c0f4081cb1890ce2e37232c553b3254f57d (patch) | |
tree | 2fa6cbfc1c199415697488914609a00722b59959 /usr.sbin/ospfd | |
parent | 5e93ce8f9b526e75ec999ac853aeff75ed226a9f (diff) |
The libevent callback function may be called with EV_READ and EV_WRITE
set at the same time so using a switch to do read or write is a bad idea.
Problem noticed by Eygene Ryabinkin on FreeBSD for some reasons it is not
triggered on OpenBSD.
Fix aggreed by a most other libevent hackers
Diffstat (limited to 'usr.sbin/ospfd')
-rw-r--r-- | usr.sbin/ospfd/control.c | 14 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.c | 22 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.c | 22 | ||||
-rw-r--r-- | usr.sbin/ospfd/rde.c | 22 |
4 files changed, 26 insertions, 54 deletions
diff --git a/usr.sbin/ospfd/control.c b/usr.sbin/ospfd/control.c index d4269f8d518..49b37ae1a3f 100644 --- a/usr.sbin/ospfd/control.c +++ b/usr.sbin/ospfd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.23 2009/04/07 14:57:33 reyk Exp $ */ +/* $OpenBSD: control.c,v 1.24 2009/05/31 16:58:54 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -198,22 +198,18 @@ control_dispatch_imsg(int fd, short event, void *bula) return; } - switch (event) { - case EV_READ: + if (event & EV_READ) { if ((n = imsg_read(&c->ibuf)) == -1 || n == 0) { control_close(fd); return; } - break; - case EV_WRITE: - if (msgbuf_write(&c->ibuf.w) < 0) { + } + if (event & EV_WRITE) { + if (msgbuf_write(&c->ibuf.w) == -1) { control_close(fd); return; } imsg_event_add(&c->ibuf); - return; - default: - fatalx("unknown event"); } for (;;) { diff --git a/usr.sbin/ospfd/ospfd.c b/usr.sbin/ospfd/ospfd.c index 4c7a12dea90..7c9cc6a1b1d 100644 --- a/usr.sbin/ospfd/ospfd.c +++ b/usr.sbin/ospfd/ospfd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.c,v 1.65 2009/05/15 15:55:07 mpf Exp $ */ +/* $OpenBSD: ospfd.c,v 1.66 2009/05/31 16:58:54 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -365,20 +365,16 @@ main_dispatch_ospfe(int fd, short event, void *bula) ssize_t n; int shut = 0; - switch (event) { - case EV_READ: + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) /* connection closed */ shut = 1; - break; - case EV_WRITE: + } + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("msgbuf_write"); imsg_event_add(ibuf); - return; - default: - fatalx("unknown event"); } for (;;) { @@ -444,20 +440,16 @@ main_dispatch_rde(int fd, short event, void *bula) ssize_t n; int count, shut = 0; - switch (event) { - case EV_READ: + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) /* connection closed */ shut = 1; - break; - case EV_WRITE: + } + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("msgbuf_write"); imsg_event_add(ibuf); - return; - default: - fatalx("unknown event"); } for (;;) { diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c index 068568dd117..95dc22d8d94 100644 --- a/usr.sbin/ospfd/ospfe.c +++ b/usr.sbin/ospfd/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.65 2009/04/26 12:48:06 sthen Exp $ */ +/* $OpenBSD: ospfe.c,v 1.66 2009/05/31 16:58:54 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -265,20 +265,16 @@ ospfe_dispatch_main(int fd, short event, void *bula) struct auth_md md; int n, link_ok, stub_changed, shut = 0; - switch (event) { - case EV_READ: + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) /* connection closed */ shut = 1; - break; - case EV_WRITE: + } + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("msgbuf_write"); imsg_event_add(ibuf); - return; - default: - fatalx("unknown event"); } for (;;) { @@ -411,20 +407,16 @@ ospfe_dispatch_rde(int fd, short event, void *bula) int n, noack = 0, shut = 0; u_int16_t l, age; - switch (event) { - case EV_READ: + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) /* connection closed */ shut = 1; - break; - case EV_WRITE: + } + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("msgbuf_write"); imsg_event_add(ibuf); - return; - default: - fatalx("unknown event"); } for (;;) { diff --git a/usr.sbin/ospfd/rde.c b/usr.sbin/ospfd/rde.c index 2e90bb51ed9..020bb99040f 100644 --- a/usr.sbin/ospfd/rde.c +++ b/usr.sbin/ospfd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.77 2009/01/27 12:45:52 michele Exp $ */ +/* $OpenBSD: rde.c,v 1.78 2009/05/31 16:58:54 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -239,20 +239,16 @@ rde_dispatch_imsg(int fd, short event, void *bula) int r, state, self, error, shut = 0; u_int16_t l; - switch (event) { - case EV_READ: + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) /* connection closed */ shut = 1; - break; - case EV_WRITE: + } + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("msgbuf_write"); imsg_event_add(ibuf); - return; - default: - fatalx("unknown event"); } clock_gettime(CLOCK_MONOTONIC, &tp); @@ -592,20 +588,16 @@ rde_dispatch_parent(int fd, short event, void *bula) ssize_t n; int shut = 0; - switch (event) { - case EV_READ: + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) /* connection closed */ shut = 1; - break; - case EV_WRITE: + } + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("msgbuf_write"); imsg_event_add(ibuf); - return; - default: - fatalx("unknown event"); } for (;;) { |