diff options
author | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2007-02-01 20:03:40 +0000 |
---|---|---|
committer | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2007-02-01 20:03:40 +0000 |
commit | 46916cfa3030ecdd425a21f5c24dd678f3ebc921 (patch) | |
tree | 9ce456c6fd8ebd072c0120d564bbe0c558b3dd28 /usr.sbin/relayd/control.c | |
parent | c38997fcc31e1562eb59356cb266390c618c4939 (diff) |
add a monitor mode to hoststatectl to continuously report changes in
hoststated.
ok reyk@, "looks nice and clean" niallo@
Diffstat (limited to 'usr.sbin/relayd/control.c')
-rw-r--r-- | usr.sbin/relayd/control.c | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c index b7f78b2434e..a24b86deada 100644 --- a/usr.sbin/relayd/control.c +++ b/usr.sbin/relayd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.10 2007/01/29 14:23:31 pyr Exp $ */ +/* $OpenBSD: control.c,v 1.11 2007/02/01 20:03:39 pyr Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -39,8 +39,6 @@ struct ctl_connlist ctl_conns; -int control_imsg_relay(struct imsg *imsg); - struct ctl_conn *control_connbyfd(int); struct ctl_conn *control_connbypid(pid_t); void control_close(int); @@ -238,9 +236,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_service(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_SERVICE_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -249,9 +250,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_service(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_TABLE_DISABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -260,9 +264,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_table(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_TABLE_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -271,9 +278,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_table(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_HOST_DISABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -282,9 +292,12 @@ control_dispatch_imsg(int fd, short event, void *arg) if (disable_host(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_HOST_ENABLE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id)) @@ -293,14 +306,27 @@ control_dispatch_imsg(int fd, short event, void *arg) if (enable_host(c, &id)) imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); - else + else { + memcpy(imsg.data, &id, sizeof(id)); + control_imsg_forward(&imsg); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, NULL, 0); + } break; case IMSG_CTL_SHUTDOWN: case IMSG_CTL_RELOAD: imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0); break; + case IMSG_CTL_NOTIFY: + if (c->flags & CTL_CONN_NOTIFY) { + log_debug("control_dispatch_imsg: " + "client requested notify more than once"); + imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, + NULL, 0); + break; + } + c->flags |= CTL_CONN_NOTIFY; + break; default: log_debug("control_dispatch_imsg: " "error handling imsg %d", imsg.hdr.type); @@ -325,6 +351,17 @@ control_imsg_relay(struct imsg *imsg) } void +control_imsg_forward(struct imsg *imsg) +{ + struct ctl_conn *c; + + TAILQ_FOREACH(c, &ctl_conns, entry) + if (c->flags & CTL_CONN_NOTIFY) + imsg_compose(&c->ibuf, imsg->hdr.type, 0, imsg->hdr.pid, + imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE); +} + +void session_socket_blockmode(int fd, enum blockmodes bm) { int flags; |