chg: handle connect failure before errno gets overridden
authorJun Wu <quark@fb.com>
Sun, 25 Dec 2016 23:32:11 +0000
changeset 30679 fe11f466880d
parent 30678 caf7e1c5efe4
child 30680 4677df6b449a
chg: handle connect failure before errno gets overridden This patch moves the error handling logic up so that errno after connect won't be overridden.
contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c	Sun Dec 25 03:06:55 2016 +0530
+++ b/contrib/chg/hgclient.c	Sun Dec 25 23:32:11 2016 +0000
@@ -457,16 +457,17 @@
 
 	/* real connect */
 	int r = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
+	if (r < 0) {
+		if (errno != ENOENT && errno != ECONNREFUSED)
+			abortmsgerrno("cannot connect to %s", sockname);
+	}
 	if (bakfd != -1) {
 		fchdirx(bakfd);
 		close(bakfd);
 	}
-
 	if (r < 0) {
 		close(fd);
-		if (errno == ENOENT || errno == ECONNREFUSED)
-			return NULL;
-		abortmsgerrno("cannot connect to %s", addr.sun_path);
+		return NULL;
 	}
 	debugmsg("connected to %s", addr.sun_path);