[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
auth_none thread bug & patch
From: |
Nickolai Zeldovich |
Subject: |
auth_none thread bug & patch |
Date: |
Thu, 14 Feb 2002 12:58:33 -0500 |
If I call authnone_create() in one thread, and then try to use
it via AUTH_MARSHAL in another thread, the AUTH_MARSHAL call
fails because authnone_private is grabbed from that thread's
local state (where it's still null). The patch below makes
auth_none use a lock rather than per-thread state, and fixes
this problem.
-- kolya
--- sunrpc/auth_none.c 2002/02/14 17:17:26 1.1
+++ sunrpc/auth_none.c 2002/02/14 17:28:46
@@ -36,6 +36,7 @@
*/
#include <rpc/rpc.h>
+#include <bits/libc-lock.h>
#define MAX_MARSHEL_SIZE 20
@@ -61,25 +62,27 @@
char marshalled_client[MAX_MARSHEL_SIZE];
u_int mcnt;
};
-#ifdef _RPC_THREAD_SAFE_
-#define authnone_private ((struct authnone_private_s
*)RPC_THREAD_VARIABLE(authnone_private_s))
-#else
+
static struct authnone_private_s *authnone_private;
-#endif
+__libc_lock_define_initialized (static, authnone_lock)
AUTH *
authnone_create (void)
{
struct authnone_private_s *ap;
+ AUTH *a;
XDR xdr_stream;
XDR *xdrs;
+ __libc_lock_lock (authnone_lock);
ap = (struct authnone_private_s *) authnone_private;
if (ap == NULL)
{
ap = (struct authnone_private_s *) calloc (1, sizeof (*ap));
- if (ap == NULL)
+ if (ap == NULL) {
+ __libc_lock_unlock (authnone_lock);
return NULL;
+ }
authnone_private = ap;
}
if (!ap->mcnt)
@@ -94,7 +97,9 @@
ap->mcnt = XDR_GETPOS (xdrs);
XDR_DESTROY (xdrs);
}
- return (&ap->no_client);
+ a = &ap->no_client;
+ __libc_lock_unlock (authnone_lock);
+ return a;
}
/*ARGSUSED */
@@ -102,11 +107,16 @@
authnone_marshal (AUTH *client, XDR *xdrs)
{
struct authnone_private_s *ap;
+ bool_t ret;
+ __libc_lock_lock (authnone_lock);
ap = (struct authnone_private_s *) authnone_private;
if (ap == NULL)
- return FALSE;
- return (*xdrs->x_ops->x_putbytes) (xdrs, ap->marshalled_client, ap->mcnt);
+ ret = FALSE;
+ else
+ ret = (*xdrs->x_ops->x_putbytes) (xdrs, ap->marshalled_client, ap->mcnt);
+ __libc_lock_unlock (authnone_lock);
+ return ret;
}
static void
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- auth_none thread bug & patch,
Nickolai Zeldovich <=