changeset 28856:0d530299acf2

chg: use fsetcloexec instead of closing lockfd manually Since we have the fsetcloexec utility function, use it instead of closing lockfd manually.
author Jun Wu <quark@fb.com>
date Mon, 11 Apr 2016 00:18:27 +0100
parents f5764e177bbe
children 9f67cf7cc28e
files contrib/chg/chg.c
diffstat 1 files changed, 1 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/chg.c	Mon Apr 11 00:17:17 2016 +0100
+++ b/contrib/chg/chg.c	Mon Apr 11 00:18:27 2016 +0100
@@ -178,6 +178,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)
@@ -309,8 +310,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);