summaryrefslogtreecommitdiff
path: root/libc/inet/rpc/auth_none.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2012-02-02 18:22:36 +0100
committerCarmelo Amoroso <carmelo.amoroso@st.com>2012-02-07 07:55:45 +0100
commitc697912b3a9126390cb67099f94406239c370c79 (patch)
tree97d3932b0f4d06aaa77489d7b68c0d45e0a72fe9 /libc/inet/rpc/auth_none.c
parentae0e6225db6dacb4d4de81245fba8671526dfe90 (diff)
inet:rpc: fix authnone_marshal in multithreading context
This is a port of glibc's fix by Zack Weinberg as reported in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=142312, and discussed in http://sourceware.org/ml/libc-alpha/2002-04/msg00069.html and following. Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/inet/rpc/auth_none.c')
-rw-r--r--libc/inet/rpc/auth_none.c59
1 files changed, 29 insertions, 30 deletions
diff --git a/libc/inet/rpc/auth_none.c b/libc/inet/rpc/auth_none.c
index c48bbfea9..d066f6b5d 100644
--- a/libc/inet/rpc/auth_none.c
+++ b/libc/inet/rpc/auth_none.c
@@ -66,49 +66,48 @@ struct authnone_private_s {
char marshalled_client[MAX_MARSHAL_SIZE];
u_int mcnt;
};
-#ifdef __UCLIBC_HAS_THREADS__
-#define authnone_private (*(struct authnone_private_s **)&RPC_THREAD_VARIABLE(authnone_private_s))
-#else
-static struct authnone_private_s *authnone_private;
-#endif
-AUTH *
-authnone_create (void)
+static struct authnone_private_s authnone_private;
+__libc_once_define(static, authnone_private_guard);
+
+static void authnone_create_once (void);
+
+static void
+authnone_create_once (void)
{
struct authnone_private_s *ap;
XDR xdr_stream;
XDR *xdrs;
- ap = (struct authnone_private_s *) authnone_private;
- if (ap == NULL)
- {
- ap = (struct authnone_private_s *) calloc (1, sizeof (*ap));
- if (ap == NULL)
- return NULL;
- authnone_private = ap;
- }
- if (!ap->mcnt)
- {
- ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
- ap->no_client.ah_ops = (struct auth_ops *)&ops;
- xdrs = &xdr_stream;
- xdrmem_create (xdrs, ap->marshalled_client, (u_int) MAX_MARSHAL_SIZE,
- XDR_ENCODE);
- (void) xdr_opaque_auth (xdrs, &ap->no_client.ah_cred);
- (void) xdr_opaque_auth (xdrs, &ap->no_client.ah_verf);
- ap->mcnt = XDR_GETPOS (xdrs);
- XDR_DESTROY (xdrs);
- }
- return (&ap->no_client);
+ ap = &authnone_private;
+
+ ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
+ ap->no_client.ah_ops = (struct auth_ops *) &ops;
+ xdrs = &xdr_stream;
+ xdrmem_create(xdrs, ap->marshalled_client,
+ (u_int) MAX_MARSHAL_SIZE, XDR_ENCODE);
+ (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
+ (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
+ ap->mcnt = XDR_GETPOS (xdrs);
+ XDR_DESTROY (xdrs);
+}
+
+AUTH *
+authnone_create (void)
+{
+ __libc_once (authnone_private_guard, authnone_create_once);
+ return &authnone_private.no_client;
}
libc_hidden_def(authnone_create)
static bool_t
-authnone_marshal (AUTH *client attribute_unused, XDR *xdrs)
+authnone_marshal (AUTH *client, XDR *xdrs)
{
struct authnone_private_s *ap;
- ap = authnone_private;
+ /* authnone_create returned authnone_private->no_client, which is
+ the first field of struct authnone_private_s. */
+ ap = (struct authnone_private_s *) client;
if (ap == NULL)
return FALSE;
return (*xdrs->x_ops->x_putbytes) (xdrs, ap->marshalled_client, ap->mcnt);