[PATCH 12 of 14] chg: use unlinkat instead of unlink for paths related to socket names

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


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1460331209 -3600
#      Mon Apr 11 00:33:29 2016 +0100
# Node ID a4651e43ceb70c27db15ebe43950e9a788192096
# Parent  9cf8e7497c267cfaea5baa8913f5665ab44867ec
chg: use unlinkat instead of unlink for paths related to socket names

This is a part of the series to support long socket path. Since the server
only returns relative paths from "validate", the client needs to switch
to unlinkat with the sockdirfd to deleting files correctly.

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -353,7 +353,7 @@
 	 * address does not work. we do not want to connect to the server
 	 * again because it will probably tell us the same thing. */
 	if (sockname == opts->redirectsockname)
-		unlink(opts->sockname);
+		unlinkat(opts->sockdirfd, opts->sockname, 0);
 
 	debugmsg("start cmdserver at %s", opts->sockname);
 
@@ -518,7 +518,7 @@
 	for (pinst = insts; *pinst; pinst++) {
 		debugmsg("instruction: %s", *pinst);
 		if (strncmp(*pinst, "unlink ", 7) == 0) {
-			unlink(*pinst + 7);
+			unlinkat(opts->sockdirfd, *pinst + 7, 0);
 		} else if (strncmp(*pinst, "redirect ", 9) == 0) {
 			int r = snprintf(opts->redirectsockname,
 					 sizeof(opts->redirectsockname),


More information about the Mercurial-devel mailing list