]> andersk Git - nss_nonlocal.git/commitdiff
Guard one-time initialization with memory barriers
authorAnders Kaseorg <andersk@mit.edu>
Tue, 11 Jun 2013 09:33:10 +0000 (05:33 -0400)
committerAnders Kaseorg <andersk@mit.edu>
Thu, 13 Jun 2013 03:17:25 +0000 (23:17 -0400)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
nonlocal-group.c
nonlocal-passwd.c
nonlocal-shadow.c
walk_nss.h

index b4a72d10f3c49aedc1bfdcbe9c78e156eb60ff7b..9bbe156183ccb6db5bc2e325eb2641e866a0d1d6 100644 (file)
@@ -171,6 +171,7 @@ get_local_group(const char *name, struct group *grp, char **buffer, int *errnop)
     return status;
 }
 
+static bool grent_initialized = false;
 static service_user *grent_startp, *grent_nip;
 static void *grent_fct_start;
 static union {
@@ -195,9 +196,12 @@ _nss_nonlocal_setgrent(int stayopen)
     if (status != NSS_STATUS_SUCCESS)
        return status;
 
-    if (grent_fct_start == NULL)
+    if (!grent_initialized) {
        __nss_group_nonlocal_lookup(&grent_startp, grent_fct_name,
                                    &grent_fct_start);
+       __sync_synchronize();
+       grent_initialized = true;
+    }
     grent_nip = grent_startp;
     grent_fct.ptr = grent_fct_start;
     return NSS_STATUS_SUCCESS;
index b9a14b544dfde3c7329b575d430b5d983deb14c6..f8e7f96f823ded1760977b01a28025ea8b851f43 100644 (file)
@@ -162,6 +162,7 @@ get_nonlocal_passwd(const char *name, struct passwd *pwd, char **buffer,
 }
 
 
+static bool pwent_initialized = false;
 static service_user *pwent_startp, *pwent_nip;
 static void *pwent_fct_start;
 static union {
@@ -186,9 +187,12 @@ _nss_nonlocal_setpwent(int stayopen)
     if (status != NSS_STATUS_SUCCESS)
        return status;
 
-    if (pwent_fct_start == NULL)
+    if (!pwent_initialized) {
        __nss_passwd_nonlocal_lookup(&pwent_startp, pwent_fct_name,
                                     &pwent_fct_start);
+       __sync_synchronize();
+       pwent_initialized = true;
+    }
     pwent_nip = pwent_startp;
     pwent_fct.ptr = pwent_fct_start;
     return NSS_STATUS_SUCCESS;
index bfc201c48e85a489f6eb208e8a6494596bd55170..98142e183cfbfc9cc269cde1c1922793ab931a79 100644 (file)
@@ -58,6 +58,7 @@ __nss_shadow_nonlocal_lookup(service_user **ni, const char *fct_name,
 }
 
 
+static bool spent_initialized = false;
 static service_user *spent_startp, *spent_nip;
 static void *spent_fct_start;
 static union {
@@ -82,9 +83,12 @@ _nss_nonlocal_setspent(int stayopen)
     if (status != NSS_STATUS_SUCCESS)
        return status;
 
-    if (spent_fct_start == NULL)
+    if (!spent_initialized) {
        __nss_shadow_nonlocal_lookup(&spent_startp, spent_fct_name,
                                     &spent_fct_start);
+       __sync_synchronize();
+       spent_initialized = true;
+    }
     spent_nip = spent_startp;
     spent_fct.ptr = spent_fct_start;
     return NSS_STATUS_SUCCESS;
index 93af177121ff0ae4d2791de003153729cd2c5b2f..78d3575539be152e3c624609f3e73e3c2b6ea4ae 100644 (file)
@@ -24,8 +24,9 @@
  */
 
 {
-    static service_user *startp = NULL;
-    static void *fct_start = NULL;
+    static bool initialized = false;
+    static service_user *startp;
+    static void *fct_start;
 
     service_user *nip;
     union {
     } fct;
     int old_errno = errno;
 
-    if (fct_start == NULL &&
-       w.lookup(&startp, w.fct_name, &fct_start) != 0) {
-       *w.status = NSS_STATUS_UNAVAIL;
-       goto walk_nss_out;
+    if (!initialized) {
+       if (w.lookup(&startp, w.fct_name, &fct_start) != 0) {
+           *w.status = NSS_STATUS_UNAVAIL;
+           goto walk_nss_out;
+       }
+       __sync_synchronize();
+       initialized = true;
     }
 
     nip = startp;
This page took 0.0384330000000001 seconds and 5 git commands to generate.