1 From 5c797a24a7d6337b5e654079a8d815199b1e8364 Mon Sep 17 00:00:00 2001
2 From: Carmelo Amoroso <carmelo.amoroso@st.com>
3 Date: Thu, 2 Feb 2012 18:22:36 +0100
4 Subject: [PATCH] inet:rpc: fix authnone_marshal in multithreading context
6 This is a port of glibc's fix by Zack Weinberg as reported
7 in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=142312,
8 and discussed in http://sourceware.org/ml/libc-alpha/2002-04/msg00069.html
11 Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
13 libc/inet/rpc/auth_none.c | 59 +++++++++++++++++++++----------------------
14 libc/inet/rpc/rpc_private.h | 2 --
15 libc/inet/rpc/rpc_thread.c | 1 -
16 3 files changed, 29 insertions(+), 33 deletions(-)
18 diff --git a/libc/inet/rpc/auth_none.c b/libc/inet/rpc/auth_none.c
19 index c48bbfe..d066f6b 100644
20 --- a/libc/inet/rpc/auth_none.c
21 +++ b/libc/inet/rpc/auth_none.c
22 @@ -66,49 +66,48 @@ struct authnone_private_s {
23 char marshalled_client[MAX_MARSHAL_SIZE];
26 -#ifdef __UCLIBC_HAS_THREADS__
27 -#define authnone_private (*(struct authnone_private_s **)&RPC_THREAD_VARIABLE(authnone_private_s))
29 -static struct authnone_private_s *authnone_private;
33 -authnone_create (void)
34 +static struct authnone_private_s authnone_private;
35 +__libc_once_define(static, authnone_private_guard);
37 +static void authnone_create_once (void);
40 +authnone_create_once (void)
42 struct authnone_private_s *ap;
46 - ap = (struct authnone_private_s *) authnone_private;
49 - ap = (struct authnone_private_s *) calloc (1, sizeof (*ap));
52 - authnone_private = ap;
56 - ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
57 - ap->no_client.ah_ops = (struct auth_ops *)&ops;
59 - xdrmem_create (xdrs, ap->marshalled_client, (u_int) MAX_MARSHAL_SIZE,
61 - (void) xdr_opaque_auth (xdrs, &ap->no_client.ah_cred);
62 - (void) xdr_opaque_auth (xdrs, &ap->no_client.ah_verf);
63 - ap->mcnt = XDR_GETPOS (xdrs);
66 - return (&ap->no_client);
67 + ap = &authnone_private;
69 + ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
70 + ap->no_client.ah_ops = (struct auth_ops *) &ops;
72 + xdrmem_create(xdrs, ap->marshalled_client,
73 + (u_int) MAX_MARSHAL_SIZE, XDR_ENCODE);
74 + (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
75 + (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
76 + ap->mcnt = XDR_GETPOS (xdrs);
81 +authnone_create (void)
83 + __libc_once (authnone_private_guard, authnone_create_once);
84 + return &authnone_private.no_client;
86 libc_hidden_def(authnone_create)
89 -authnone_marshal (AUTH *client attribute_unused, XDR *xdrs)
90 +authnone_marshal (AUTH *client, XDR *xdrs)
92 struct authnone_private_s *ap;
94 - ap = authnone_private;
95 + /* authnone_create returned authnone_private->no_client, which is
96 + the first field of struct authnone_private_s. */
97 + ap = (struct authnone_private_s *) client;
100 return (*xdrs->x_ops->x_putbytes) (xdrs, ap->marshalled_client, ap->mcnt);
101 diff --git a/libc/inet/rpc/rpc_private.h b/libc/inet/rpc/rpc_private.h
102 index ede3ddf..e1214d2 100644
103 --- a/libc/inet/rpc/rpc_private.h
104 +++ b/libc/inet/rpc/rpc_private.h
105 @@ -18,8 +18,6 @@ struct rpc_thread_variables {
106 struct pollfd *svc_pollfd_s; /* Global, rpc_common.c */
107 int svc_max_pollfd_s; /* Global, rpc_common.c */
109 - void *authnone_private_s; /* auth_none.c */
111 void *clnt_perr_buf_s; /* clnt_perr.c */
113 void *clntraw_private_s; /* clnt_raw.c */
114 diff --git a/libc/inet/rpc/rpc_thread.c b/libc/inet/rpc/rpc_thread.c
115 index 71303b2..3367659 100644
116 --- a/libc/inet/rpc/rpc_thread.c
117 +++ b/libc/inet/rpc/rpc_thread.c
118 @@ -32,7 +32,6 @@ __rpc_thread_destroy (void)
119 __rpc_thread_svc_cleanup ();
120 __rpc_thread_clnt_cleanup ();
121 /*__rpc_thread_key_cleanup (); */
122 - free (tvp->authnone_private_s);
123 free (tvp->clnt_perr_buf_s);
124 free (tvp->clntraw_private_s);
125 free (tvp->svcraw_private_s);