about summary refs log tree commit diff
path: root/nis/nss_nisplus/nisplus-pwd.c
diff options
context:
space:
mode:
Diffstat (limited to 'nis/nss_nisplus/nisplus-pwd.c')
-rw-r--r--nis/nss_nisplus/nisplus-pwd.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/nis/nss_nisplus/nisplus-pwd.c b/nis/nss_nisplus/nisplus-pwd.c
index a1c53f74a6..97679dd349 100644
--- a/nis/nss_nisplus/nisplus-pwd.c
+++ b/nis/nss_nisplus/nisplus-pwd.c
@@ -56,7 +56,12 @@ _nss_pwd_create_tablename (int *errnop)
 
       atomic_write_barrier ();
 
-      pwd_tablename_val = p;
+      if (atomic_compare_and_exchange_bool_acq (&pwd_tablename_val, p, NULL))
+	{
+	  /* Another thread already installed the value.  */
+	  free (p);
+	  pwd_tablename_len = strlen (pwd_tablename_val);
+	}
     }
 
   return NSS_STATUS_SUCCESS;
@@ -181,12 +186,8 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
 
   if (pwd_tablename_val == NULL)
     {
-      __libc_lock_lock (lock);
-
       enum nss_status status = _nss_pwd_create_tablename (errnop);
 
-      __libc_lock_unlock (lock);
-
       if (status != NSS_STATUS_SUCCESS)
 	return status;
     }
@@ -248,12 +249,8 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
 {
   if (pwd_tablename_val == NULL)
     {
-      __libc_lock_lock (lock);
-
       enum nss_status status = _nss_pwd_create_tablename (errnop);
 
-      __libc_lock_unlock (lock);
-
       if (status != NSS_STATUS_SUCCESS)
 	return status;
     }