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

login
register
mail settings
Submitter Jun Wu
Date April 10, 2016, 11:57 p.m.
Message ID <a4651e43ceb70c27db15.1460332649@x1c>
Download mbox | patch
Permalink /patch/14512/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - April 10, 2016, 11:57 p.m.
# HG changeset patch
# User Jun Wu <quark@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.
timeless - April 11, 2016, 3:43 a.m.
Jun Wu wrote:
> to unlinkat with the sockdirfd to deleting files correctly.

deleting => delete
Jun Wu - April 11, 2016, 10:48 a.m.
On 04/11/2016 04:43 AM, timeless wrote:
> Jun Wu wrote:
>> to unlinkat with the sockdirfd to deleting files correctly.
>
> deleting => delete

Thank you for all your spelling and grammar check efforts on my patches!
I'm very appreciated. If only I could amend my emails directly.

Errors like this one is trivial enough that should just be caught by some
program. I will treat it as a "unit test" to find a good automatic solution.
Jun Wu - April 11, 2016, 12:34 p.m.
I tried some well known solutions.

Sadly (and to my surprise), none of MS Word, After the deadline, and
Grammarly could catch the "to deleting" error.

Eangel can but later I learned it's powered by humans.

1checker can catch it and looks promising but it seems non-trivial to automate.

On 04/11/2016 11:48 AM, Jun Wu wrote:
> Errors like this one is trivial enough that should just be caught by some
> program. I will treat it as a "unit test" to find a good automatic
> solution.
Yuya Nishihara - April 13, 2016, 3:18 p.m.
On Mon, 11 Apr 2016 00:57:29 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@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

Unfortunately, unlinkat() was also introduced in Mac OS X 10.10.

Patch

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),