diff options
Diffstat (limited to 'nss/nss_files/files-XXX.c')
-rw-r--r-- | nss/nss_files/files-XXX.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c index 7472496a10..ac6b5fa94a 100644 --- a/nss/nss_files/files-XXX.c +++ b/nss/nss_files/files-XXX.c @@ -19,6 +19,7 @@ #include <stdio.h> #include <ctype.h> +#include <fcntl.h> #include <assert.h> #include <errno.h> #include <libc-lock.h> @@ -71,7 +72,27 @@ internal_setent (int stayopen) stream = fopen (DATAFILE, "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); |