summaryrefslogtreecommitdiff
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.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
index 341e9d4d68..aca89ed73c 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 <libc-lock.h>
#include <stdlib.h>
#include <stdio.h>
@@ -48,7 +49,27 @@ internal_setent (void)
stream = fopen ("/etc/aliases", "r");
if (stream == NULL)
- status = NSS_STATUS_UNAVAIL;
+ 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 (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);