From d51f075a4e71cbde5f25cd22cf07d0b7691d4c6c Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sat, 7 Jun 2008 07:27:28 +0000 Subject: Use a socketpair to synchronise server startup. --- client.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index 59e69875..49041461 100644 --- a/client.c +++ b/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.28 2008-06-02 21:08:36 nicm Exp $ */ +/* $Id: client.c,v 1.29 2008-06-07 07:27:28 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -51,11 +51,9 @@ client_init(const char *path, struct client_ctx *cctx, int start_server) retries = 0; retry: if (stat(path, &sb) != 0) { - if (start_server && errno == ENOENT && retries < 10) { - if (pid == 0) - pid = server_start(path); - usleep(10000); - retries++; + if (start_server && errno == ENOENT) { + if (server_start(path) != 0) + goto no_start; goto retry; } goto fail; @@ -81,9 +79,8 @@ retry: if (start_server && errno == ECONNREFUSED && retries < 10) { if (unlink(path) != 0) goto fail; - usleep(10000); - retries++; - goto retry; + if (server_start(path) != 0) + goto no_start; } goto fail; } @@ -112,6 +109,10 @@ retry: return (0); +no_start: + log_warnx("server failed to start"); + return (1); + fail: log_warn("server not found"); return (1); -- cgit