summaryrefslogtreecommitdiff
path: root/usr.sbin/hoststated
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2006-12-25 19:05:42 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2006-12-25 19:05:42 +0000
commitcf7f2baa5c93cc79c46ffc583e6d4aff6ab97c60 (patch)
tree47537f17cc61d69a418755cbac5f22008ac0adeb /usr.sbin/hoststated
parent2e002eb51e98ddcd00053415bdcefc85983560b6 (diff)
fix the conversion from milliseconds to struct timeval, which uses
seconds (tv_sec) and microseconds (tv_usec), but the code assumed seconds and milliseconds...
Diffstat (limited to 'usr.sbin/hoststated')
-rw-r--r--usr.sbin/hoststated/check_http.c8
-rw-r--r--usr.sbin/hoststated/check_icmp.c20
-rw-r--r--usr.sbin/hoststated/check_tcp.c5
-rw-r--r--usr.sbin/hoststated/hoststated.h4
-rw-r--r--usr.sbin/hoststated/parse.y24
5 files changed, 32 insertions, 29 deletions
diff --git a/usr.sbin/hoststated/check_http.c b/usr.sbin/hoststated/check_http.c
index 3529764375b..b081c1ce2fa 100644
--- a/usr.sbin/hoststated/check_http.c
+++ b/usr.sbin/hoststated/check_http.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_http.c,v 1.3 2006/12/25 18:12:14 reyk Exp $ */
+/* $OpenBSD: check_http.c,v 1.4 2006/12/25 19:05:41 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
*
@@ -129,8 +129,7 @@ http_read(int s, short event, void *arg)
hce_notify_done(cte->host, "http_read: read failed");
} else {
buf_add(cte->buf, rbuf, br);
- tv.tv_sec = cte->table->timeout / 1000;
- tv.tv_usec = cte->table->timeout % 1000;
+ bcopy(&cte->table->timeout, &tv, sizeof(tv));
if (gettimeofday(&tv_now, NULL))
fatal("send_http_request: gettimeofday");
timersub(&tv_now, &cte->tv_start, &tv_now);
@@ -184,8 +183,7 @@ send_http_request(struct ctl_tcp_event *cte)
if ((cte->buf = buf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL)
fatalx("send_http_request: cannot create dynamic buffer");
- tv.tv_sec = cte->table->timeout / 1000;
- tv.tv_usec = cte->table->timeout % 1000;
+ bcopy(&cte->table->timeout, &tv, sizeof(tv));
if (gettimeofday(&tv_now, NULL))
fatal("send_http_request: gettimeofday");
timersub(&tv_now, &cte->tv_start, &tv_now);
diff --git a/usr.sbin/hoststated/check_icmp.c b/usr.sbin/hoststated/check_icmp.c
index ad562e771c4..3cf5360e01f 100644
--- a/usr.sbin/hoststated/check_icmp.c
+++ b/usr.sbin/hoststated/check_icmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_icmp.c,v 1.3 2006/12/25 18:12:14 reyk Exp $ */
+/* $OpenBSD: check_icmp.c,v 1.4 2006/12/25 19:05:41 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -69,18 +69,13 @@ check_icmp(struct ctl_icmp_event *cie)
if (gettimeofday(&cie->tv_start, NULL))
fatal("check_icmp: gettimeofday");
- if (cie->has_icmp4) {
- tv.tv_sec = cie->env->timeout / 1000;
- tv.tv_usec = cie->env->timeout % 1000;
+ bcopy(&cie->env->timeout, &tv, sizeof(tv));
+ if (cie->has_icmp4)
event_once(cie->icmp_sock, EV_READ|EV_TIMEOUT,
recv_icmp4, cie, &tv);
- }
- if (cie->has_icmp6) {
- tv.tv_sec = cie->env->timeout / 1000;
- tv.tv_usec = cie->env->timeout % 1000;
+ if (cie->has_icmp6)
event_once(cie->icmp6_sock, EV_READ|EV_TIMEOUT,
recv_icmp6, cie, &tv);
- }
}
int
@@ -247,8 +242,7 @@ recv_icmp6(int s, short event, void *arg)
return;
if (gettimeofday(&tv_now, NULL))
fatal("recv_icmp6: gettimeofday");
- tv.tv_sec = cie->env->timeout / 1000;
- tv.tv_usec = cie->env->timeout % 1000;
+ bcopy(&cie->env->timeout, &tv, sizeof(tv));
timersub(&tv_now, &cie->tv_start, &tv_now);
timersub(&tv, &tv_now, &tv);
event_once(cie->icmp6_sock, EV_READ|EV_TIMEOUT, recv_icmp6, cie, &tv);
@@ -327,8 +321,8 @@ recv_icmp4(int s, short event, void *arg)
if (gettimeofday(&tv_now, NULL))
fatal("recv_icmp4: gettimeofday");
- tv.tv_sec = cie->env->timeout / 1000;
- tv.tv_usec = cie->env->timeout % 1000;
+
+ bcopy(&cie->env->timeout, &tv, sizeof(tv));
timersub(&tv_now, &cie->tv_start, &tv_now);
timersub(&tv, &tv_now, &tv);
event_once(cie->icmp_sock, EV_READ|EV_TIMEOUT, recv_icmp4, cie, &tv);
diff --git a/usr.sbin/hoststated/check_tcp.c b/usr.sbin/hoststated/check_tcp.c
index 2a65abc4307..93cf8dd7041 100644
--- a/usr.sbin/hoststated/check_tcp.c
+++ b/usr.sbin/hoststated/check_tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_tcp.c,v 1.3 2006/12/25 18:12:14 reyk Exp $ */
+/* $OpenBSD: check_tcp.c,v 1.4 2006/12/25 19:05:41 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -79,8 +79,7 @@ check_tcp(struct ctl_tcp_event *cte)
tcp_host_up(s, cte);
return;
}
- tv.tv_sec = cte->table->timeout / 1000;
- tv.tv_usec = cte->table->timeout % 1000;
+ bcopy(&cte->table->timeout, &tv, sizeof(tv));
event_once(s, EV_TIMEOUT|EV_WRITE, tcp_write, cte, &tv);
return;
bad:
diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h
index 4ca1519bae2..89532b6baf6 100644
--- a/usr.sbin/hoststated/hoststated.h
+++ b/usr.sbin/hoststated/hoststated.h
@@ -184,7 +184,7 @@ struct table {
int up;
in_port_t port;
int retcode;
- int timeout;
+ struct timeval timeout;
char name[TABLE_NAME_SIZE];
char path[MAXPATHLEN];
char digest[41]; /* length of sha1 digest * 2 */
@@ -226,7 +226,7 @@ struct hostated {
int icmp6_sock;
int tablecount;
int servicecount;
- int timeout;
+ struct timeval timeout;
struct table empty_table;
struct event ev;
struct tablelist tables;
diff --git a/usr.sbin/hoststated/parse.y b/usr.sbin/hoststated/parse.y
index 0c6008365b8..33a7ed336ed 100644
--- a/usr.sbin/hoststated/parse.y
+++ b/usr.sbin/hoststated/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.5 2006/12/25 18:12:14 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.6 2006/12/25 19:05:41 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -90,6 +90,7 @@ typedef struct {
u_int32_t number;
char *string;
struct host *host;
+ struct timeval tv;
} v;
int lineno;
} YYSTYPE;
@@ -105,6 +106,7 @@ typedef struct {
%type <v.string> interface
%type <v.number> number
%type <v.host> host
+%type <v.tv> timeout
%%
@@ -140,7 +142,9 @@ varset : STRING '=' STRING {
;
main : INTERVAL number { conf->interval = $2; }
- | TIMEOUT number { conf->timeout = $2; }
+ | TIMEOUT timeout {
+ bcopy(&$2, &conf->timeout, sizeof(struct timeval));
+ }
;
service : SERVICE STRING {
@@ -292,7 +296,7 @@ table : TABLE STRING {
YYERROR;
}
tb->id = last_table_id++;
- tb->timeout = conf->timeout;
+ bcopy(&conf->timeout, &tb->timeout, sizeof(struct timeval));
if (last_table_id == UINT_MAX) {
yyerror("too many tables defined");
YYERROR;
@@ -326,8 +330,8 @@ tableoptsl : host {
$1->tablename = table->name;
TAILQ_INSERT_HEAD(&table->hosts, $1, entry);
}
- | TIMEOUT number {
- table->timeout = $2;
+ | TIMEOUT timeout {
+ bcopy(&$2, &table->timeout, sizeof(struct timeval));
}
| CHECK ICMP {
table->check = CHECK_ICMP;
@@ -413,6 +417,13 @@ host : HOST STRING {
}
;
+timeout : number
+ {
+ $$.tv_sec = $1 / 1000;
+ $$.tv_usec = ($1 % 1000) * 1000;
+ }
+ ;
+
optnl : '\n' optnl
|
;
@@ -686,7 +697,8 @@ parse_config(struct hostated *x_conf, const char *filename, int opts)
(void)strlcpy(conf->empty_table.name, "empty",
sizeof(conf->empty_table.name));
- conf->timeout = CHECK_TIMEOUT;
+ conf->timeout.tv_sec = CHECK_TIMEOUT / 1000;
+ conf->timeout.tv_usec = (CHECK_TIMEOUT % 1000) * 1000;
conf->interval = CHECK_INTERVAL;
conf->opts = opts;