svn commit: r250506 - stable/9/lib/libkvm

Jilles Tjoelker jilles at FreeBSD.org
Sat May 11 11:56:51 UTC 2013


Author: jilles
Date: Sat May 11 11:56:50 2013
New Revision: 250506
URL: http://svnweb.freebsd.org/changeset/base/250506

Log:
  MFC r250230: libkvm: Use O_CLOEXEC instead of separate fcntl(F_SETFD) call.

Modified:
  stable/9/lib/libkvm/kvm.c
Directory Properties:
  stable/9/lib/libkvm/   (props changed)

Modified: stable/9/lib/libkvm/kvm.c
==============================================================================
--- stable/9/lib/libkvm/kvm.c	Sat May 11 11:17:44 2013	(r250505)
+++ stable/9/lib/libkvm/kvm.c	Sat May 11 11:56:50 2013	(r250506)
@@ -166,7 +166,7 @@ _kvm_open(kvm_t *kd, const char *uf, con
 	if (mf == 0)
 		mf = _PATH_MEM;
 
-	if ((kd->pmfd = open(mf, flag, 0)) < 0) {
+	if ((kd->pmfd = open(mf, flag | O_CLOEXEC, 0)) < 0) {
 		_kvm_syserr(kd, kd->program, "%s", mf);
 		goto failed;
 	}
@@ -179,10 +179,6 @@ _kvm_open(kvm_t *kd, const char *uf, con
 		_kvm_syserr(kd, kd->program, "empty file");
 		goto failed;
 	}
-	if (fcntl(kd->pmfd, F_SETFD, FD_CLOEXEC) < 0) {
-		_kvm_syserr(kd, kd->program, "%s", mf);
-		goto failed;
-	}
 	if (S_ISCHR(st.st_mode)) {
 		/*
 		 * If this is a character special device, then check that
@@ -194,11 +190,8 @@ _kvm_open(kvm_t *kd, const char *uf, con
 			kd->vmfd = open(_PATH_DEVNULL, O_RDONLY);
 			return (kd);
 		} else if (strcmp(mf, _PATH_MEM) == 0) {
-			if ((kd->vmfd = open(_PATH_KMEM, flag)) < 0) {
-				_kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
-				goto failed;
-			}
-			if (fcntl(kd->vmfd, F_SETFD, FD_CLOEXEC) < 0) {
+			if ((kd->vmfd = open(_PATH_KMEM, flag | O_CLOEXEC)) <
+			    0) {
 				_kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
 				goto failed;
 			}
@@ -210,11 +203,7 @@ _kvm_open(kvm_t *kd, const char *uf, con
 	 * Initialize the virtual address translation machinery,
 	 * but first setup the namelist fd.
 	 */
-	if ((kd->nlfd = open(uf, O_RDONLY, 0)) < 0) {
-		_kvm_syserr(kd, kd->program, "%s", uf);
-		goto failed;
-	}
-	if (fcntl(kd->nlfd, F_SETFD, FD_CLOEXEC) < 0) {
+	if ((kd->nlfd = open(uf, O_RDONLY | O_CLOEXEC, 0)) < 0) {
 		_kvm_syserr(kd, kd->program, "%s", uf);
 		goto failed;
 	}


More information about the svn-src-stable-9 mailing list