From 42fd44f1dbe9e0ea339375185a2b984f21fad93d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 2 Nov 2009 13:41:25 +0000 Subject: There isn't much point in doing lstat before connect so instead just do connect and handle ENOENT from it which is a little tidier. --- client.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index a5c5e39e..c41c669e 100644 --- a/client.c +++ b/client.c @@ -55,19 +55,6 @@ client_init(char *path, int cmdflags, int flags) strlcpy(rpathbuf, path, sizeof rpathbuf); setproctitle("client (%s)", rpathbuf); - if (lstat(path, &sb) != 0) { - if (cmdflags & CMD_STARTSERVER && errno == ENOENT) { - if ((fd = server_start(path)) == -1) - goto start_failed; - goto server_started; - } - goto not_found; - } - if (!S_ISSOCK(sb.st_mode)) { - errno = ENOTSOCK; - goto not_found; - } - memset(&sa, 0, sizeof sa); sa.sun_family = AF_UNIX; size = strlcpy(sa.sun_path, path, sizeof sa.sun_path); @@ -80,9 +67,14 @@ client_init(char *path, int cmdflags, int flags) fatal("socket failed"); if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) { - if (errno == ECONNREFUSED) { - if (unlink(path) != 0 || !(cmdflags & CMD_STARTSERVER)) + if (!(cmdflags & CMD_STARTSERVER)) + goto not_found; + switch (errno) { + case ECONNREFUSED: + if (unlink(path) != 0) goto not_found; + /* FALLTHROUGH */ + case ENOENT: if ((fd = server_start(path)) == -1) goto start_failed; goto server_started; -- cgit v1.2.3