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

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


# 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);
 }
 
 static pid_t peerpid = 0;


More information about the Mercurial-devel mailing list