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.
--- 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);