summaryrefslogtreecommitdiff
path: root/usr.sbin/dvmrpd/dvmrpd.c
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-06 07:52:05 +0000
committerPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-06 07:52:05 +0000
commitc0022c393ab5435ed57bed21adceb48a959e494f (patch)
tree5039b99b8f6812acece6ce748d22df8e49ef758b /usr.sbin/dvmrpd/dvmrpd.c
parentcd9e24e8e0859fe9e77873ee1d58d24c53926189 (diff)
make dvmrpd imsg-in-a-lib ready as well.
``put it in'' claudio@, ok eric@
Diffstat (limited to 'usr.sbin/dvmrpd/dvmrpd.c')
-rw-r--r--usr.sbin/dvmrpd/dvmrpd.c81
1 files changed, 48 insertions, 33 deletions
diff --git a/usr.sbin/dvmrpd/dvmrpd.c b/usr.sbin/dvmrpd/dvmrpd.c
index 9362b27b1a0..901f0e6462b 100644
--- a/usr.sbin/dvmrpd/dvmrpd.c
+++ b/usr.sbin/dvmrpd/dvmrpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dvmrpd.c,v 1.9 2009/06/01 23:22:58 henning Exp $ */
+/* $OpenBSD: dvmrpd.c,v 1.10 2009/06/06 07:52:04 pyr Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -64,8 +64,8 @@ int pipe_parent2rde[2];
int pipe_dvmrpe2rde[2];
struct dvmrpd_conf *conf = NULL;
-struct imsgbuf *ibuf_dvmrpe;
-struct imsgbuf *ibuf_rde;
+struct imsgev *iev_dvmrpe;
+struct imsgev *iev_rde;
pid_t dvmrpe_pid;
pid_t rde_pid;
@@ -254,22 +254,24 @@ main(int argc, char *argv[])
close(pipe_dvmrpe2rde[0]);
close(pipe_dvmrpe2rde[1]);
- if ((ibuf_dvmrpe = malloc(sizeof(struct imsgbuf))) == NULL ||
- (ibuf_rde = malloc(sizeof(struct imsgbuf))) == NULL)
+ if ((iev_dvmrpe = malloc(sizeof(struct imsgev))) == NULL ||
+ (iev_rde = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
- imsg_init(ibuf_dvmrpe, pipe_parent2dvmrpe[0], main_dispatch_dvmrpe);
- imsg_init(ibuf_rde, pipe_parent2rde[0], main_dispatch_rde);
+ imsg_init(&iev_dvmrpe->ibuf, pipe_parent2dvmrpe[0]);
+ imsg_init(&iev_rde->ibuf, pipe_parent2rde[0]);
+ iev_dvmrpe->handler = main_dispatch_dvmrpe;
+ iev_rde->handler = main_dispatch_rde;
/* setup event handler */
- ibuf_dvmrpe->events = EV_READ;
- event_set(&ibuf_dvmrpe->ev, ibuf_dvmrpe->fd, ibuf_dvmrpe->events,
- ibuf_dvmrpe->handler, ibuf_dvmrpe);
- event_add(&ibuf_dvmrpe->ev, NULL);
+ iev_dvmrpe->events = EV_READ;
+ event_set(&iev_dvmrpe->ev, iev_dvmrpe->ibuf.fd, iev_dvmrpe->events,
+ iev_dvmrpe->handler, iev_dvmrpe);
+ event_add(&iev_dvmrpe->ev, NULL);
- ibuf_rde->events = EV_READ;
- event_set(&ibuf_rde->ev, ibuf_rde->fd, ibuf_rde->events,
- ibuf_rde->handler, ibuf_rde);
- event_add(&ibuf_rde->ev, NULL);
+ iev_rde->events = EV_READ;
+ event_set(&iev_rde->ev, iev_rde->ibuf.fd, iev_rde->events,
+ iev_rde->handler, iev_rde);
+ event_add(&iev_rde->ev, NULL);
if (kmr_init(!(conf->flags & DVMRPD_FLAG_NO_FIB_UPDATE)) == -1)
dvmrpd_shutdown();
@@ -315,10 +317,10 @@ dvmrpd_shutdown(void)
fatal("wait");
} while (pid != -1 || (pid == -1 && errno == EINTR));
- msgbuf_clear(&ibuf_dvmrpe->w);
- free(ibuf_dvmrpe);
- msgbuf_clear(&ibuf_rde->w);
- free(ibuf_rde);
+ msgbuf_clear(&iev_dvmrpe->ibuf.w);
+ free(iev_dvmrpe);
+ msgbuf_clear(&iev_rde->ibuf.w);
+ free(iev_rde);
log_info("terminating");
exit(0);
@@ -348,7 +350,8 @@ check_child(pid_t pid, const char *pname)
void
main_dispatch_dvmrpe(int fd, short event, void *bula)
{
- struct imsgbuf *ibuf = bula;
+ struct imsgev *iev = bula;
+ struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
ssize_t n;
@@ -388,14 +391,15 @@ main_dispatch_dvmrpe(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
main_dispatch_rde(int fd, short event, void *bula)
{
struct mfc mfc;
- struct imsgbuf *ibuf = bula;
+ struct imsgev *iev = bula;
+ struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
ssize_t n;
@@ -441,30 +445,41 @@ main_dispatch_rde(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
main_imsg_compose_dvmrpe(int type, pid_t pid, void *data, u_int16_t datalen)
{
- imsg_compose(ibuf_dvmrpe, type, 0, pid, data, datalen);
+ imsg_compose_event(iev_dvmrpe, type, 0, pid, -1, data, datalen);
}
void
main_imsg_compose_rde(int type, pid_t pid, void *data, u_int16_t datalen)
{
- imsg_compose(ibuf_rde, type, 0, pid, data, datalen);
+ imsg_compose_event(iev_rde, type, 0, pid, -1, data, datalen);
}
-/* this needs to be added here so that dvmrpctl can be used without libevent */
void
-imsg_event_add(struct imsgbuf *ibuf)
+imsg_event_add(struct imsgev *iev)
{
- ibuf->events = EV_READ;
- if (ibuf->w.queued)
- ibuf->events |= EV_WRITE;
+ iev->events = EV_READ;
+ if (iev->ibuf.w.queued)
+ iev->events |= EV_WRITE;
- event_del(&ibuf->ev);
- event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf);
- event_add(&ibuf->ev, NULL);
+ event_del(&iev->ev);
+ event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev);
+ event_add(&iev->ev, NULL);
+}
+
+int
+imsg_compose_event(struct imsgev *iev, u_int16_t type,
+ u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen)
+{
+ int ret;
+
+ if ((ret = imsg_compose(&iev->ibuf, type, peerid,
+ pid, fd, data, datalen)) != -1)
+ imsg_event_add(iev);
+ return (ret);
}