[PATCH 06 of 14] chg: use full path as --address to start a new server

Yuya Nishihara yuya at tcha.org
Mon Apr 11 09:16:01 EDT 2016


On Mon, 11 Apr 2016 00:57:23 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1460327827 -3600
> #      Sun Apr 10 23:37:07 2016 +0100
> # Node ID a0233eac2848926116ecbdb4bf44fd5f066d7f1d
> # Parent  8dcda8964985a6e1826e6ceb8e7f476a66b8a3f9
> chg: use full path as --address to start a new server
> 
> This is a part of the series to support long socket path. We will change
> sockname to basename instead of full path soon.
> 
> To make sure the server creates the socket file in a correct location,
> we have to pass the full path because we may pass "--cwd" as well and
> a "chdir" just before starting the server doesn't work with "--cwd".
> 
> This patch uses getcwd to resolve the dir fd and get the full path used
> for the server.
> 
> diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
> --- a/contrib/chg/chg.c
> +++ b/contrib/chg/chg.c
> @@ -215,6 +215,27 @@
>  	return hgcmd;
>  }
>  
> +static const char *getfullpath(int dirfd, const char *name)
> +{
> +	if (name[0] == '/')
> +		return name;
> +
> +	static char path[PATH_MAX];
> +	int cwdfd = open(".", O_DIRECTORY);
> +	if (cwdfd == -1)
> +		abortmsgerrno("failed to open current directory");
> +	fchdirx(dirfd);
> +	if (getcwd(path, sizeof(path)) == NULL)
> +		abortmsgerrno("failed to getcwd");
> +	size_t len = strlen(path);
> +	assert(len < sizeof(path));
> +	int r = snprintf(path + len, sizeof(path) - len, "/%s", name);
> +	if ((size_t)r >= sizeof(path))

Wrong boundary. You've shifted the destination pointer by len.


More information about the Mercurial-devel mailing list