summary refs log tree commit diff
path: root/nss/nss_db/db-netgrp.c
diff options
context:
space:
mode:
Diffstat (limited to 'nss/nss_db/db-netgrp.c')
-rw-r--r--nss/nss_db/db-netgrp.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/nss/nss_db/db-netgrp.c b/nss/nss_db/db-netgrp.c
index e716dd00b2..c301789f74 100644
--- a/nss/nss_db/db-netgrp.c
+++ b/nss/nss_db/db-netgrp.c
@@ -53,6 +53,26 @@ _nss_db_setnetgrent (const char *group)
 
       if (db == NULL)
 	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
+      else
+	{
+	  /* We have to make sure the file is  `closed on exec'.  */
+	  int result, flags;
+
+	  result = flags = fcntl ((*db->fd) (db), F_GETFD, 0);
+	  if (result >= 0)
+	    {
+	      flags |= FD_CLOEXEC;
+	      result = fcntl ((*db->fd) (db), F_SETFD, flags);
+	    }
+	  if (result < 0)
+	    {
+	      /* Something went wrong.  Close the stream and return a
+		 failure.  */
+	      (*db->close) (db);
+	      db = NULL;
+	      status = NSS_STATUS_UNAVAIL;
+	    }
+	}
     }
 
   if (status == NSS_STATUS_SUCCESS)