[PATCH 3 of 3] chg: support long socket path

Jun Wu quark at fb.com
Fri Dec 23 11:46:50 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1482510400 0
#      Fri Dec 23 16:26:40 2016 +0000
# Node ID 1f55b42a6af0a8557c291ff16a371d0cf921d20a
# Parent  95f0c3df6e09f0110a365643511c271a8029f5bc
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 1f55b42a6af0
chg: support long socket path

This patch replaces UNIX_PATH_MAX (108) with PATH_MAX (4096) so we can have
long unix path.

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -26,12 +26,12 @@
 #include "util.h"
 
-#ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX (sizeof(((struct sockaddr_un *)NULL)->sun_path))
+#ifndef PATH_MAX
+#define PATH_MAX 4096
 #endif
 
 struct cmdserveropts {
-	char sockname[UNIX_PATH_MAX];
-	char initsockname[UNIX_PATH_MAX];
-	char redirectsockname[UNIX_PATH_MAX];
+	char sockname[PATH_MAX];
+	char initsockname[PATH_MAX];
+	char redirectsockname[PATH_MAX];
 	size_t argsize;
 	const char **args;
@@ -131,5 +131,5 @@ static void setcmdserveropts(struct cmds
 {
 	int r;
-	char sockdir[UNIX_PATH_MAX];
+	char sockdir[PATH_MAX];
 	const char *envsockname = getenv("CHGSOCKNAME");
 	if (!envsockname) {
diff --git a/tests/test-chg.t b/tests/test-chg.t
--- a/tests/test-chg.t
+++ b/tests/test-chg.t
@@ -17,4 +17,18 @@ ill-formed config
 
   $ cp $HGRCPATH.orig $HGRCPATH
+
+long socket path
+
+  $ sockpath=$TESTTMP/this/path/should/be/longer/than/one-hundred-and-seven/characters/where/107/is/the/typical/size/limit/of/unix-domain-socket
+  $ mkdir -p $sockpath
+  $ bakchgsockname=$CHGSOCKNAME
+  $ CHGSOCKNAME=$sockpath/server
+  $ export CHGSOCKNAME
+  $ chg root
+  $TESTTMP/foo
+  $ rm -rf $sockpath
+  $ CHGSOCKNAME=$bakchgsockname
+  $ export CHGSOCKNAME
+
   $ cd ..
 


More information about the Mercurial-devel mailing list