On Apr 23, 2014, at 6:38 PM, Paul Hargrove <phhargr...@lbl.gov> wrote:

> -Paul [Who always does what the late W. Richard Stevens says to.]

You make a good point, sir.  How about this?

diff --git a/src/topology-linux.c b/src/topology-linux.c
index 25fb465..c9dc7e2 100644
--- a/src/topology-linux.c
+++ b/src/topology-linux.c
@@ -4568,7 +4568,7 @@ hwloc_linux_component_instantiate(struct hwloc_disc_compon
   struct hwloc_backend *backend;
   struct hwloc_linux_backend_data_s *data;
   const char * fsroot_path = _data1;
-  int root = -1;
+  int flags, root = -1;
 
   backend = hwloc_backend_alloc(component);
   if (!backend)
@@ -4602,8 +4602,11 @@ hwloc_linux_component_instantiate(struct hwloc_disc_compo
   }
 
   /* Since this fd stays open after hwloc returns, mark it as
-     close-on-exec so that children don't inherit it */
-  if (fcntl(root, F_SETFD, FD_CLOEXEC) == -1) {
+     close-on-exec so that children don't inherit it.  Stevens says
+     that we should GETFD before we SETFD, so we do. */
+  flags = fcntl(root, F_GETFD, 0);
+  if (-1 == flags ||
+      -1 == fcntl(root, F_SETFD, FD_CLOEXEC | flags)) {
       close(root);
       root = -1;
       goto out_with_data;


-- 
Jeff Squyres
jsquy...@cisco.com
For corporate legal information go to: 
http://www.cisco.com/web/about/doing_business/legal/cri/

Reply via email to