Patchwork [09,of,14] chg: use fsetcloexec instead of closing lockfd manually

login
register
mail settings
Submitter Jun Wu
Date April 10, 2016, 11:57 p.m.
Message ID <68977496c0f5b4026c19.1460332646@x1c>
Download mbox | patch
Permalink /patch/14507/
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 1460330307 -3600
#      Mon Apr 11 00:18:27 2016 +0100
# Node ID 68977496c0f5b4026c19cd8ec4ea22113401c030
# Parent  95e54f1b7e4f7184f6f1f77945b0ba9ed3cc2efb
chg: use fsetcloexec instead of closing lockfd manually

Since we have the fsetcloexec utility function, use it instead of closing
lockfd manually.
Yuya Nishihara - April 11, 2016, 1:49 p.m.
On Mon, 11 Apr 2016 00:57:26 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1460330307 -3600
> #      Mon Apr 11 00:18:27 2016 +0100
> # Node ID 68977496c0f5b4026c19cd8ec4ea22113401c030
> # Parent  95e54f1b7e4f7184f6f1f77945b0ba9ed3cc2efb
> chg: use fsetcloexec instead of closing lockfd manually

Queued this, thanks.

I've reviewed up to this patch.

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -179,6 +179,7 @@ 
 		if (opts->lockfd == -1)
 			abortmsgerrno("cannot create lock file %s",
 				      opts->lockfile);
+		fsetcloexec(opts->lockfd);
 	}
 	int r = flock(opts->lockfd, LOCK_EX);
 	if (r == -1)
@@ -331,8 +332,6 @@ 
 	if (pid < 0)
 		abortmsg("failed to fork cmdserver process");
 	if (pid == 0) {
-		/* do not leak lockfd to hg */
-		close(opts->lockfd);
 		execcmdserver(opts);
 	} else {
 		hgc = retryconnectcmdserver(opts, pid);