[PATCH 14 of 14] chg: chdir to sockdir in killcmdserver

Yuya Nishihara yuya at tcha.org
Wed Apr 13 11:27:16 EDT 2016


On Mon, 11 Apr 2016 00:57:31 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1460331689 -3600
> #      Mon Apr 11 00:41:29 2016 +0100
> # Node ID a19fc1c9f3e23a98f4c510ba5bece148f6d5e3eb
> # Parent  58ea17bb6caad0e680f23473b37f68c03c546146
> chg: chdir to sockdir in killcmdserver
> 
> Since sockname is a basename now, the unlink in killcmdserver won't work
> without a correct directory. If there is realpathat(), things could be
> easier but it seems we have to change cwd to make it work.
> 
> diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
> --- a/contrib/chg/chg.c
> +++ b/contrib/chg/chg.c
> @@ -370,12 +370,15 @@
>  
>  static void killcmdserver(const struct cmdserveropts *opts)
>  {
> -	/* resolve config hash */
> +	int cwdfd = opencwdx();
> +	fchdirx(opts->sockdirfd);
> +	/* resolve symbolic link: e.g. server -> server-a4fd1c015493 */
>  	char *resolvedpath = realpath(opts->sockname, NULL);
>  	if (resolvedpath) {
>  		unlink(resolvedpath);
>  		free(resolvedpath);
>  	}
> +	fchdirx(cwdfd);
>  }

Seems fine. The other idea is to make --kill-chg-daemon kills all daemons
under the socket directory.


More information about the Mercurial-devel mailing list