From 437fe324a219673710d47cdb31ca0744194fbc93 Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Sat, 3 Feb 2007 17:51:47 +0000 Subject: wait for hoststated to become available in monitor mode. ok pyr@ --- usr.sbin/hoststatectl/hoststatectl.c | 13 +++++++++++-- usr.sbin/relayctl/relayctl.c | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/hoststatectl/hoststatectl.c b/usr.sbin/hoststatectl/hoststatectl.c index b37f84ad7a2..301488a9dc9 100644 --- a/usr.sbin/hoststatectl/hoststatectl.c +++ b/usr.sbin/hoststatectl/hoststatectl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hoststatectl.c,v 1.12 2007/02/01 21:57:18 reyk Exp $ */ +/* $OpenBSD: hoststatectl.c,v 1.13 2007/02/03 17:51:46 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -113,8 +114,16 @@ main(int argc, char *argv[]) bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; strlcpy(sun.sun_path, HOSTSTATED_SOCKET, sizeof(sun.sun_path)); - if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) + reconnect: + if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) { + /* Keep retrying if running in monitor mode */ + if (res->action == MONITOR && + (errno == ENOENT || errno == ECONNREFUSED)) { + usleep(100); + goto reconnect; + } err(1, "connect: %s", HOSTSTATED_SOCKET); + } if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL) err(1, NULL); diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c index 32e1ffad95c..39746e0d34a 100644 --- a/usr.sbin/relayctl/relayctl.c +++ b/usr.sbin/relayctl/relayctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayctl.c,v 1.12 2007/02/01 21:57:18 reyk Exp $ */ +/* $OpenBSD: relayctl.c,v 1.13 2007/02/03 17:51:46 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -113,8 +114,16 @@ main(int argc, char *argv[]) bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; strlcpy(sun.sun_path, HOSTSTATED_SOCKET, sizeof(sun.sun_path)); - if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) + reconnect: + if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) { + /* Keep retrying if running in monitor mode */ + if (res->action == MONITOR && + (errno == ENOENT || errno == ECONNREFUSED)) { + usleep(100); + goto reconnect; + } err(1, "connect: %s", HOSTSTATED_SOCKET); + } if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL) err(1, NULL); -- cgit v1.2.3