about summary refs log tree commit diff
path: root/nss/nss_files/files-alias.c
diff options
context:
space:
mode:
Diffstat (limited to 'nss/nss_files/files-alias.c')
-rw-r--r--nss/nss_files/files-alias.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
index 99217fa7c5..0a910aa0fe 100644
--- a/nss/nss_files/files-alias.c
+++ b/nss/nss_files/files-alias.c
@@ -1,5 +1,5 @@
 /* Mail alias file parser in nss_files module.
-   Copyright (C) 1996 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -21,6 +21,7 @@
 #include <aliases.h>
 #include <ctype.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <bits/libc-lock.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -49,6 +50,26 @@ internal_setent (void)
 
       if (stream == NULL)
 	status = NSS_STATUS_UNAVAIL;
+      else
+	{
+	  /* We have to make sure the file is  `closed on exec'.  */
+	  int result, flags;
+
+	  result = flags = fcntl (fileno (stream), F_GETFD, 0);
+	  if (result >= 0)
+	    {
+	      flags |= FD_CLOEXEC;
+	      result = fcntl (fileno (stream), F_SETFD, flags);
+	    }
+	  if (result < 0)
+	    {
+	      /* Something went wrong.  Close the stream and return a
+		 failure.  */
+	      fclose (stream);
+	      stream = NULL;
+	      status = NSS_STATUS_UNAVAIL;
+	    }
+	}
     }
   else
     rewind (stream);