From 57a4c5a772d575909ce181d00e9cd115f96c8cc0 Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Tue, 2 Jun 2009 11:33:07 +0000 Subject: Libevent may do an upcall with both EV_READ and EV_WRITE set. So change the code accordingly to allow that. Found by claudio@ in ospfd --- usr.sbin/relayd/control.c | 14 +++++--------- usr.sbin/relayd/hce.c | 24 +++++++++++------------- usr.sbin/relayd/pfe.c | 36 +++++++++++++++++------------------- usr.sbin/relayd/relay.c | 24 +++++++++++------------- usr.sbin/relayd/relayd.c | 35 ++++++++++++++++------------------- 5 files changed, 60 insertions(+), 73 deletions(-) diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c index 7a7e5d5cba1..b7575cdb7b6 100644 --- a/usr.sbin/relayd/control.c +++ b/usr.sbin/relayd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.27 2009/02/25 17:09:55 claudio Exp $ */ +/* $OpenBSD: control.c,v 1.28 2009/06/02 11:33:06 reyk Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -201,22 +201,18 @@ control_dispatch_imsg(int fd, short event, void *arg) 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 (event & EV_WRITE) { if (msgbuf_write(&c->ibuf.w) < 0) { control_close(fd); return; } - imsg_event_add(&c->ibuf); - return; - default: - fatalx("unknown event"); } for (;;) { diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c index d02134ac9a9..748073189dd 100644 --- a/usr.sbin/relayd/hce.c +++ b/usr.sbin/relayd/hce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hce.c,v 1.47 2009/04/17 09:47:06 reyk Exp $ */ +/* $OpenBSD: hce.c,v 1.48 2009/06/02 11:33:06 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard @@ -367,8 +367,8 @@ hce_dispatch_imsg(int fd, short event, void *ptr) struct table *table; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("hce_dispatch_imsg: imsg_read_error"); if (n == 0) { @@ -377,14 +377,13 @@ hce_dispatch_imsg(int fd, short event, void *ptr) event_loopexit(NULL); return; } - break; - case EV_WRITE: + } + + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("hce_dispatch_imsg: msgbuf_write"); imsg_event_add(ibuf); return; - default: - fatalx("hce_dispatch_imsg: unknown event"); } for (;;) { @@ -456,8 +455,8 @@ hce_dispatch_parent(int fd, short event, void * ptr) struct host *host, *parent; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("hce_dispatch_parent: imsg_read error"); if (n == 0) { @@ -466,14 +465,13 @@ hce_dispatch_parent(int fd, short event, void * ptr) event_loopexit(NULL); return; } - break; - case EV_WRITE: + } + + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("hce_dispatch_parent: msgbuf_write"); imsg_event_add(ibuf); return; - default: - fatalx("hce_dispatch_parent: unknown event"); } for (;;) { diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c index 0d1c45831f1..c46471e265e 100644 --- a/usr.sbin/relayd/pfe.c +++ b/usr.sbin/relayd/pfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe.c,v 1.55 2009/04/17 09:47:06 reyk Exp $ */ +/* $OpenBSD: pfe.c,v 1.56 2009/06/02 11:33:06 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard @@ -229,8 +229,8 @@ pfe_dispatch_imsg(int fd, short event, void *ptr) struct ctl_status st; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("pfe_dispatch_imsg: imsg_read_error"); if (n == 0) { @@ -239,14 +239,13 @@ pfe_dispatch_imsg(int fd, short event, void *ptr) event_loopexit(NULL); return; } - break; - case EV_WRITE: + } + + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("pfe_dispatch_imsg: msgbuf_write"); imsg_event_add(ibuf); return; - default: - fatalx("pfe_dispatch_imsg: unknown event"); } for (;;) { @@ -338,8 +337,8 @@ pfe_dispatch_parent(int fd, short event, void * ptr) struct address *virt; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) { @@ -348,14 +347,14 @@ pfe_dispatch_parent(int fd, short event, void * ptr) event_loopexit(NULL); return; } - break; - case EV_WRITE: + } + + + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("msgbuf_write"); imsg_event_add(ibuf); return; - default: - fatalx("pfe_dispatch_parent: unknown event"); } for (;;) { @@ -461,8 +460,8 @@ pfe_dispatch_relay(int fd, short event, void * ptr) struct relay *rlay; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) { @@ -471,14 +470,13 @@ pfe_dispatch_relay(int fd, short event, void * ptr) event_loopexit(NULL); return; } - 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/relayd/relay.c b/usr.sbin/relayd/relay.c index 73cd73aa762..3dab40350c4 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.110 2009/04/24 13:22:01 pyr Exp $ */ +/* $OpenBSD: relay.c,v 1.111 2009/06/02 11:33:06 reyk Exp $ */ /* * Copyright (c) 2006, 2007, 2008 Reyk Floeter @@ -2404,8 +2404,8 @@ relay_dispatch_pfe(int fd, short event, void *ptr) objid_t id; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("relay_dispatch_pfe: imsg_read_error"); if (n == 0) { @@ -2414,14 +2414,13 @@ relay_dispatch_pfe(int fd, short event, void *ptr) event_loopexit(NULL); return; } - break; - case EV_WRITE: + } + + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("relay_dispatch_pfe: msgbuf_write"); imsg_event_add(ibuf); return; - default: - fatalx("relay_dispatch_pfe: unknown event"); } for (;;) { @@ -2526,8 +2525,8 @@ relay_dispatch_parent(int fd, short event, void * ptr) objid_t id; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("relay_dispatch_parent: imsg_read error"); if (n == 0) { @@ -2536,14 +2535,13 @@ relay_dispatch_parent(int fd, short event, void * ptr) event_loopexit(NULL); return; } - break; - case EV_WRITE: + } + + if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) fatal("relay_dispatch_parent: msgbuf_write"); imsg_event_add(ibuf); return; - default: - fatalx("relay_dispatch_parent: unknown event"); } for (;;) { diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c index e7e58bb29d6..e1daba0705e 100644 --- a/usr.sbin/relayd/relayd.c +++ b/usr.sbin/relayd/relayd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.c,v 1.83 2008/09/29 15:12:22 reyk Exp $ */ +/* $OpenBSD: relayd.c,v 1.84 2009/06/02 11:33:06 reyk Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter @@ -593,8 +593,8 @@ main_dispatch_pfe(int fd, short event, void *ptr) struct ctl_demote demote; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read_error"); if (n == 0) { @@ -603,14 +603,13 @@ main_dispatch_pfe(int fd, short event, void *ptr) event_loopexit(NULL); return; } - 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 (;;) { @@ -655,8 +654,8 @@ main_dispatch_hce(int fd, short event, void * ptr) env = relayd_env; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) { @@ -665,14 +664,13 @@ main_dispatch_hce(int fd, short event, void * ptr) event_loopexit(NULL); return; } - 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 (;;) { @@ -716,8 +714,8 @@ main_dispatch_relay(int fd, short event, void * ptr) int s; ibuf = ptr; - switch (event) { - case EV_READ: + + if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1) fatal("imsg_read error"); if (n == 0) { @@ -726,14 +724,13 @@ main_dispatch_relay(int fd, short event, void * ptr) event_loopexit(NULL); return; } - 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 (;;) { -- cgit v1.2.3