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

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


# HG changeset patch
# User Jun Wu <quark at 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.

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


More information about the Mercurial-devel mailing list