PATCH: Catch rpc thread error
H . J . Lu
hjl@lucon.org
Sun Jul 29 01:01:00 GMT 2001
BTW, before we made rpc thread safe, we could
1. Make
extern CLIENT *cl;
2. Do
cl = clnt_create (...)
in one thread.
3. Use cl to call clnt_call () in another thread.
But it won't work with the thread safe rpc glibc 2.2.4. We got
# ./print_client localhost hello
localhost: RPC: Can't encode arguments
This error message is not very clear. This patch catches this
condition. Now we get
# ./print_client localhost hello
localhost: RPC: clnt_create not called in thread
H.J.
------
2001-07-29 H.J. Lu <hjl@gnu.org>
* sunrpc/rpc/clnt.h (clnt_stat): Add RPC_THREAD_NOCREATE.
* sunrpc/clnt_perr.c (clnt_sperror): Handle RPC_THREAD_NOCREATE.
(RPC_THREAD_NOCREATE_IDX): Defined.
(rpc_errstr): Add the entry for RPC_THREAD_NOCREATE_IDX.
(rpc_errtab): Add RPC_THREAD_NOCREATE/RPC_THREAD_NOCREATE_IDX.
* sunrpc/clnt_raw.c (clntraw_call): Return RPC_THREAD_NOCREATE
for __rpc_thread_variables()->authnone_private_s == NULL if
_RPC_THREAD_SAFE_ is defined.
* sunrpc/clnt_tcp.c (clnttcp_call): Likewise.
* sunrpc/clnt_udp.c (clntudp_call): Likewise.
* sunrpc/clnt_unix.c (clntunix_call): Likewise.
--- sunrpc/clnt_perr.c.thread Wed Mar 28 10:45:48 2001
+++ sunrpc/clnt_perr.c Sun Jul 29 00:20:42 2001
@@ -105,6 +105,7 @@ clnt_sperror (CLIENT * rpch, const char
case RPC_PMAPFAILURE:
case RPC_PROGNOTREGISTERED:
case RPC_FAILED:
+ case RPC_THREAD_NOCREATE:
break;
case RPC_CANTSEND:
@@ -235,6 +236,10 @@ static const char rpc_errstr[] =
#define RPC_FAILED_IDX (RPC_PROGNOTREGISTERED_IDX \
+ sizeof "RPC: Program not registered")
N_("RPC: Failed (unspecified error)")
+ "\0"
+#define RPC_THREAD_NOCREATE_IDX (RPC_FAILED_IDX \
+ + sizeof "RPC: Failed (unspecified error)")
+ N_("RPC: clnt_create not called in thread")
};
static const struct rpc_errtab rpc_errlist[] =
@@ -256,7 +261,8 @@ static const struct rpc_errtab rpc_errli
{ RPC_UNKNOWNPROTO, RPC_UNKNOWNPROTO_IDX },
{ RPC_PMAPFAILURE, RPC_PMAPFAILURE_IDX },
{ RPC_PROGNOTREGISTERED, RPC_PROGNOTREGISTERED_IDX },
- { RPC_FAILED, RPC_FAILED_IDX }
+ { RPC_FAILED, RPC_FAILED_IDX },
+ { RPC_THREAD_NOCREATE, RPC_THREAD_NOCREATE_IDX }
};
--- sunrpc/clnt_raw.c.thread Wed Mar 21 09:45:34 2001
+++ sunrpc/clnt_raw.c Sun Jul 29 00:30:16 2001
@@ -146,6 +146,11 @@ clntraw_call (h, proc, xargs, argsp, xre
enum clnt_stat status;
struct rpc_err error;
+#ifdef _RPC_THREAD_SAFE_
+ if (__rpc_thread_variables()->authnone_private_s == NULL)
+ return RPC_THREAD_NOCREATE;
+#endif
+
if (clp == NULL)
return RPC_FAILED;
call_again:
--- sunrpc/clnt_tcp.c.thread Wed Mar 28 10:45:48 2001
+++ sunrpc/clnt_tcp.c Sun Jul 29 00:28:12 2001
@@ -250,6 +250,14 @@ clnttcp_call (h, proc, xdr_args, args_pt
bool_t shipnow;
int refreshes = 2;
+#ifdef _RPC_THREAD_SAFE_
+ if (__rpc_thread_variables()->authnone_private_s == NULL)
+ {
+ ct->ct_error.re_status = RPC_THREAD_NOCREATE;
+ return (ct->ct_error.re_status);
+ }
+#endif
+
if (!ct->ct_waitset)
{
ct->ct_wait = timeout;
--- sunrpc/clnt_udp.c.thread Wed Mar 28 10:45:48 2001
+++ sunrpc/clnt_udp.c Sun Jul 29 00:27:26 2001
@@ -284,6 +284,14 @@ clntudp_call (cl, proc, xargs, argsp, xr
struct timeval timeout;
int anyup; /* any network interface up */
+#ifdef _RPC_THREAD_SAFE_
+ if (__rpc_thread_variables()->authnone_private_s == NULL)
+ {
+ cu->cu_error.re_status = RPC_THREAD_NOCREATE;
+ return (cu->cu_error.re_status);
+ }
+#endif
+
if (cu->cu_total.tv_usec == -1)
{
timeout = utimeout; /* use supplied timeout */
--- sunrpc/clnt_unix.c.thread Wed Mar 28 10:45:48 2001
+++ sunrpc/clnt_unix.c Sun Jul 29 00:30:41 2001
@@ -229,6 +229,14 @@ clntunix_call (h, proc, xdr_args, args_p
bool_t shipnow;
int refreshes = 2;
+#ifdef _RPC_THREAD_SAFE_
+ if (__rpc_thread_variables()->authnone_private_s == NULL)
+ {
+ ct->ct_error.re_status = RPC_THREAD_NOCREATE;
+ return (ct->ct_error.re_status);
+ }
+#endif
+
if (!ct->ct_waitset)
{
ct->ct_wait = timeout;
--- sunrpc/rpc/clnt.h.thread Tue Aug 1 23:59:15 2000
+++ sunrpc/rpc/clnt.h Sat Jul 28 23:32:34 2001
@@ -96,7 +96,12 @@ enum clnt_stat {
* asynchronous errors
*/
RPC_INPROGRESS = 24,
- RPC_STALERACHANDLE = 25
+ RPC_STALERACHANDLE = 25,
+ /*
+ * thread errors
+ */
+ /* clnt_create () is not called in the thread. */
+ RPC_THREAD_NOCREATE = 0x70000000
};
More information about the Libc-alpha
mailing list