From patchwork Sun Apr 10 23:57:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [09,of,14] chg: use fsetcloexec instead of closing lockfd manually From: Jun Wu X-Patchwork-Id: 14507 Message-Id: <68977496c0f5b4026c19.1460332646@x1c> To: Date: Mon, 11 Apr 2016 00:57:26 +0100 # HG changeset patch # User Jun Wu # 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);