Patchwork [07,of,14] chg: use openat instead of open when creating the lock file

login
register
mail settings
Submitter Jun Wu
Date April 10, 2016, 11:57 p.m.
Message ID <4616bceaa941b40b3905.1460332644@x1c>
Download mbox | patch
Permalink /patch/14505/
State Changes Requested
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 1460327930 -3600
#      Sun Apr 10 23:38:50 2016 +0100
# Node ID 4616bceaa941b40b39055610ba109252dee3a20c
# Parent  a0233eac2848926116ecbdb4bf44fd5f066d7f1d
chg: use openat instead of open when creating the lock file

This is a part of the series to support long socket path. Since we will switch
to basename for the lock file soon, use openat instead of open to make sure
it is created inside the directory.
Yuya Nishihara - April 11, 2016, 1:26 p.m.
On Mon, 11 Apr 2016 00:57:24 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1460327930 -3600
> #      Sun Apr 10 23:38:50 2016 +0100
> # Node ID 4616bceaa941b40b39055610ba109252dee3a20c
> # Parent  a0233eac2848926116ecbdb4bf44fd5f066d7f1d
> chg: use openat instead of open when creating the lock file
> 
> This is a part of the series to support long socket path. Since we will switch
> to basename for the lock file soon, use openat instead of open to make sure
> it is created inside the directory.
> 
> diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
> --- a/contrib/chg/chg.c
> +++ b/contrib/chg/chg.c
> @@ -174,8 +174,8 @@
>  static void lockcmdserver(struct cmdserveropts *opts)
>  {
>  	if (opts->lockfd == -1) {
> -		opts->lockfd = open(opts->lockfile,
> -				    O_RDWR | O_CREAT | O_NOFOLLOW, 0600);
> +		opts->lockfd = openat(opts->sockdirfd, opts->lockfile,
> +				      O_RDWR | O_CREAT | O_NOFOLLOW, 0600);

It appears that openat() was introduced in Mac OS X 10.10, which seems too
new to use without compatibility layer.

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -174,8 +174,8 @@ 
 static void lockcmdserver(struct cmdserveropts *opts)
 {
 	if (opts->lockfd == -1) {
-		opts->lockfd = open(opts->lockfile,
-				    O_RDWR | O_CREAT | O_NOFOLLOW, 0600);
+		opts->lockfd = openat(opts->sockdirfd, opts->lockfile,
+				      O_RDWR | O_CREAT | O_NOFOLLOW, 0600);
 		if (opts->lockfd == -1)
 			abortmsgerrno("cannot create lock file %s",
 				      opts->lockfile);