about summary refs log tree commit diff
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
parent080ffa73c75767cf3e9a1c329624f57cf2d93618 (diff)
downloadglibc-1aa43890df5ecc09004007336f64ed1344a9d335.tar.gz
glibc-1aa43890df5ecc09004007336f64ed1344a9d335.tar.xz
glibc-1aa43890df5ecc09004007336f64ed1344a9d335.zip
Optimize several little things. Use stream unlocked.
-rw-r--r--nis/nss_compat/compat-grp.c30
-rw-r--r--nis/nss_compat/compat-pwd.c23
-rw-r--r--nis/nss_compat/compat-spwd.c28
3 files changed, 46 insertions, 35 deletions
diff --git a/nis/nss_compat/compat-grp.c b/nis/nss_compat/compat-grp.c
index fb6328cfca..a24db336e2 100644
--- a/nis/nss_compat/compat-grp.c
+++ b/nis/nss_compat/compat-grp.c
@@ -17,15 +17,16 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <nss.h>
 #include <grp.h>
-#include <ctype.h>
-#include <bits/libc-lock.h>
+#include <nss.h>
+#include <nsswitch.h>
+#include <stdio_lock.h>
 #include <string.h>
 #include <rpc/types.h>
-#include <nsswitch.h>
+#include <bits/libc-lock.h>
 
 static service_user *ni;
 static enum nss_status (*nss_setgrent) (int stayopen);
@@ -106,7 +107,7 @@ internal_setgrent (ent_t *ent, int stayopen)
 
   if (ent->stream == NULL)
     {
-      ent->stream = fopen ("/etc/group", "r");
+      ent->stream = fopen ("/etc/group", "rm");
 
       if (ent->stream == NULL)
 	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
@@ -115,11 +116,11 @@ internal_setgrent (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)
 	    {
@@ -129,6 +130,9 @@ internal_setgrent (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
@@ -252,8 +256,8 @@ getgrent_next_file (struct group *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')
@@ -380,8 +384,8 @@ internal_getgrnam_r (const char *name, struct group *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')
@@ -507,8 +511,8 @@ internal_getgrgid_r (gid_t gid, struct group *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')
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')
diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c
index a2757c4b66..ed6bcff7df 100644
--- a/nis/nss_compat/compat-spwd.c
+++ b/nis/nss_compat/compat-spwd.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.
 
@@ -17,17 +17,18 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-#include <nss.h>
-#include <errno.h>
 #include <ctype.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <netdb.h>
+#include <nss.h>
+#include <nsswitch.h>
 #include <shadow.h>
+#include <stdio_ext.h>
 #include <string.h>
-#include <bits/libc-lock.h>
 #include <rpc/types.h>
 #include <rpcsvc/ypclnt.h>
-#include <nsswitch.h>
+#include <bits/libc-lock.h>
 
 #include "netgroup.h"
 
@@ -177,7 +178,7 @@ internal_setspent (ent_t *ent, int stayopen)
 
   if (ent->stream == NULL)
     {
-      ent->stream = fopen ("/etc/shadow", "r");
+      ent->stream = fopen ("/etc/shadow", "rm");
 
       if (ent->stream == NULL)
 	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
@@ -186,11 +187,11 @@ internal_setspent (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)
 	    {
@@ -200,6 +201,9 @@ internal_setspent (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
@@ -449,8 +453,8 @@ getspent_next_file (struct spwd *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')
@@ -638,8 +642,8 @@ internal_getspnam_r (const char *name, struct spwd *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')