Patchwork chg: handle connect failure before errno gets overrided

login
register
mail settings
Submitter Jun Wu
Date Dec. 25, 2016, 11:37 p.m.
Message ID <2af8d24aadfd34dc46ef.1482709076@x1c>
Download mbox | patch
Permalink /patch/18038/
State Accepted
Headers show

Comments

Jun Wu - Dec. 25, 2016, 11:37 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1482708731 0
#      Sun Dec 25 23:32:11 2016 +0000
# Node ID 2af8d24aadfd34dc46ef8bf122dc8fa7654048fd
# Parent  caf7e1c5efe431d20404fd462321163cf2a436d4
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 2af8d24aadfd
chg: handle connect failure before errno gets overrided

This patch moves the error handling logic up so that errno after connect
won't be overrided.
Yuya Nishihara - Dec. 26, 2016, 1:29 p.m.
On Sun, 25 Dec 2016 23:37:56 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1482708731 0
> #      Sun Dec 25 23:32:11 2016 +0000
> # Node ID 2af8d24aadfd34dc46ef8bf122dc8fa7654048fd
> # Parent  caf7e1c5efe431d20404fd462321163cf2a436d4
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 2af8d24aadfd
> chg: handle connect failure before errno gets overrided

Ah, thanks. Queued this.

Patch

diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -458,14 +458,15 @@  hgclient_t *hgc_open(const char *socknam
 	/* 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);