[PATCH 05 of 14] chg: add a dirfd parameter to hgc_open

Jun Wu quark at fb.com
Sun Apr 10 19:57:22 EDT 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1460325563 -3600
#      Sun Apr 10 22:59:23 2016 +0100
# Node ID 8dcda8964985a6e1826e6ceb8e7f476a66b8a3f9
# Parent  f2400efd3bd61aef35de18b462d50611be4d77d1
chg: add a dirfd parameter to hgc_open

This is a part of the series to support long socket path. Since we have
connectat and sockdirfd in cmdserveropts, it's time to add a dirfd parameter
to hgc_open.

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -250,7 +250,7 @@
 
 	debugmsg("try connect to %s repeatedly", opts->sockname);
 	for (unsigned int i = 0; i < 10 * 100; i++) {
-		hgclient_t *hgc = hgc_open(opts->sockname);
+		hgclient_t *hgc = hgc_open(opts->sockname, opts->sockdirfd);
 		if (hgc)
 			return hgc;
 
@@ -285,12 +285,12 @@
 	const char *sockname = opts->redirectsockname[0] ?
 		opts->redirectsockname : opts->sockname;
 	debugmsg("try connect to %s", sockname);
-	hgclient_t *hgc = hgc_open(sockname);
+	hgclient_t *hgc = hgc_open(sockname, opts->sockdirfd);
 	if (hgc)
 		return hgc;
 
 	lockcmdserver(opts);
-	hgc = hgc_open(sockname);
+	hgc = hgc_open(sockname, opts->sockdirfd);
 	if (hgc) {
 		unlockcmdserver(opts);
 		debugmsg("cmdserver is started by another process");
diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -410,7 +410,7 @@
  *
  * If no background server running, returns NULL.
  */
-hgclient_t *hgc_open(const char *sockname)
+hgclient_t *hgc_open(const char *sockname, int dirfd)
 {
 	int fd = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (fd < 0)
@@ -429,7 +429,7 @@
 	strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
 	addr.sun_path[sizeof(addr.sun_path) - 1] = '\0';
 
-	int r = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
+	int r = connectat(dirfd, fd, (struct sockaddr *)&addr, sizeof(addr));
 	if (r < 0) {
 		close(fd);
 		if (errno == ENOENT || errno == ECONNREFUSED)
diff --git a/contrib/chg/hgclient.h b/contrib/chg/hgclient.h
--- a/contrib/chg/hgclient.h
+++ b/contrib/chg/hgclient.h
@@ -15,7 +15,7 @@
 struct hgclient_tag_;
 typedef struct hgclient_tag_ hgclient_t;
 
-hgclient_t *hgc_open(const char *sockname);
+hgclient_t *hgc_open(const char *sockname, int dirfd);
 void hgc_close(hgclient_t *hgc);
 
 pid_t hgc_peerpid(const hgclient_t *hgc);


More information about the Mercurial-devel mailing list