summaryrefslogtreecommitdiff
path: root/nis/nss_compat/compat-pwd.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-06-28 07:49:05 +0000
committerUlrich Drepper <drepper@redhat.com>2003-06-28 07:49:05 +0000
commit1aa43890df5ecc09004007336f64ed1344a9d335 (patch)
treee99a741794ec1a82e6f5d3a48b06e4290cda14b4 /nis/nss_compat/compat-pwd.c
parent080ffa73c75767cf3e9a1c329624f57cf2d93618 (diff)
Optimize several little things. Use stream unlocked.
Diffstat (limited to 'nis/nss_compat/compat-pwd.c')
-rw-r--r--nis/nss_compat/compat-pwd.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/nis/nss_compat/compat-pwd.c b/nis/nss_compat/compat-pwd.c
index c47ad31e46..d8b9ba18d6 100644
--- a/nis/nss_compat/compat-pwd.c
+++ b/nis/nss_compat/compat-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1998,1999,2001,2002,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001,2002,2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@@ -223,7 +223,7 @@ internal_setpwent (ent_t *ent, int stayopen)
if (ent->stream == NULL)
{
- ent->stream = fopen ("/etc/passwd", "r");
+ ent->stream = fopen ("/etc/passwd", "rm");
if (ent->stream == NULL)
status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
@@ -232,11 +232,11 @@ internal_setpwent (ent_t *ent, int stayopen)
/* We have to make sure the file is `closed on exec'. */
int result, flags;
- result = flags = fcntl (fileno (ent->stream), F_GETFD, 0);
+ result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD, 0);
if (result >= 0)
{
flags |= FD_CLOEXEC;
- result = fcntl (fileno (ent->stream), F_SETFD, flags);
+ result = fcntl (fileno_unlocked (ent->stream), F_SETFD, flags);
}
if (result < 0)
{
@@ -246,6 +246,9 @@ internal_setpwent (ent_t *ent, int stayopen)
ent->stream = NULL;
status = NSS_STATUS_UNAVAIL;
}
+ else
+ /* We take care of locking ourself. */
+ __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
}
}
else
@@ -497,8 +500,8 @@ getpwent_next_file (struct passwd *result, ent_t *ent,
{
fgetpos (ent->stream, &pos);
buffer[buflen - 1] = '\xff';
- p = fgets (buffer, buflen, ent->stream);
- if (p == NULL && feof (ent->stream))
+ p = fgets_unlocked (buffer, buflen, ent->stream);
+ if (p == NULL && feof_unlocked (ent->stream))
return NSS_STATUS_NOTFOUND;
if (p == NULL || buffer[buflen - 1] != '\xff')
@@ -691,8 +694,8 @@ internal_getpwnam_r (const char *name, struct passwd *result, ent_t *ent,
{
fgetpos (ent->stream, &pos);
buffer[buflen - 1] = '\xff';
- p = fgets (buffer, buflen, ent->stream);
- if (p == NULL && feof (ent->stream))
+ p = fgets_unlocked (buffer, buflen, ent->stream);
+ if (p == NULL && feof_unlocked (ent->stream))
{
return NSS_STATUS_NOTFOUND;
}
@@ -894,8 +897,8 @@ internal_getpwuid_r (uid_t uid, struct passwd *result, ent_t *ent,
{
fgetpos (ent->stream, &pos);
buffer[buflen - 1] = '\xff';
- p = fgets (buffer, buflen, ent->stream);
- if (p == NULL && feof (ent->stream))
+ p = fgets_unlocked (buffer, buflen, ent->stream);
+ if (p == NULL && feof_unlocked (ent->stream))
return NSS_STATUS_NOTFOUND;
if (p == NULL || buffer[buflen - 1] != '\xff')