clnt_vc.c revision 1.2.4.2 1 1.2.4.2 minoura /* $NetBSD: clnt_vc.c,v 1.2.4.2 2000/06/23 16:17:42 minoura Exp $ */
2 1.2.4.2 minoura
3 1.2.4.2 minoura /*
4 1.2.4.2 minoura * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 1.2.4.2 minoura * unrestricted use provided that this legend is included on all tape
6 1.2.4.2 minoura * media and as a part of the software program in whole or part. Users
7 1.2.4.2 minoura * may copy or modify Sun RPC without charge, but are not authorized
8 1.2.4.2 minoura * to license or distribute it to anyone else except as part of a product or
9 1.2.4.2 minoura * program developed by the user.
10 1.2.4.2 minoura *
11 1.2.4.2 minoura * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 1.2.4.2 minoura * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 1.2.4.2 minoura * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 1.2.4.2 minoura *
15 1.2.4.2 minoura * Sun RPC is provided with no support and without any obligation on the
16 1.2.4.2 minoura * part of Sun Microsystems, Inc. to assist in its use, correction,
17 1.2.4.2 minoura * modification or enhancement.
18 1.2.4.2 minoura *
19 1.2.4.2 minoura * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 1.2.4.2 minoura * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 1.2.4.2 minoura * OR ANY PART THEREOF.
22 1.2.4.2 minoura *
23 1.2.4.2 minoura * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 1.2.4.2 minoura * or profits or other special, indirect and consequential damages, even if
25 1.2.4.2 minoura * Sun has been advised of the possibility of such damages.
26 1.2.4.2 minoura *
27 1.2.4.2 minoura * Sun Microsystems, Inc.
28 1.2.4.2 minoura * 2550 Garcia Avenue
29 1.2.4.2 minoura * Mountain View, California 94043
30 1.2.4.2 minoura */
31 1.2.4.2 minoura
32 1.2.4.2 minoura #include <sys/cdefs.h>
33 1.2.4.2 minoura #if defined(LIBC_SCCS) && !defined(lint)
34 1.2.4.2 minoura #if 0
35 1.2.4.2 minoura static char *sccsid = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
36 1.2.4.2 minoura static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
37 1.2.4.2 minoura static char sccsid[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
38 1.2.4.2 minoura #else
39 1.2.4.2 minoura __RCSID("$NetBSD: clnt_vc.c,v 1.2.4.2 2000/06/23 16:17:42 minoura Exp $");
40 1.2.4.2 minoura #endif
41 1.2.4.2 minoura #endif
42 1.2.4.2 minoura
43 1.2.4.2 minoura /*
44 1.2.4.2 minoura * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
45 1.2.4.2 minoura *
46 1.2.4.2 minoura * Copyright (C) 1984, Sun Microsystems, Inc.
47 1.2.4.2 minoura *
48 1.2.4.2 minoura * TCP based RPC supports 'batched calls'.
49 1.2.4.2 minoura * A sequence of calls may be batched-up in a send buffer. The rpc call
50 1.2.4.2 minoura * return immediately to the client even though the call was not necessarily
51 1.2.4.2 minoura * sent. The batching occurs if the results' xdr routine is NULL (0) AND
52 1.2.4.2 minoura * the rpc timeout value is zero (see clnt.h, rpc).
53 1.2.4.2 minoura *
54 1.2.4.2 minoura * Clients should NOT casually batch calls that in fact return results; that is,
55 1.2.4.2 minoura * the server side should be aware that a call is batched and not produce any
56 1.2.4.2 minoura * return message. Batched calls that produce many result messages can
57 1.2.4.2 minoura * deadlock (netlock) the client and the server....
58 1.2.4.2 minoura *
59 1.2.4.2 minoura * Now go hang yourself.
60 1.2.4.2 minoura */
61 1.2.4.2 minoura
62 1.2.4.2 minoura #include "namespace.h"
63 1.2.4.2 minoura #include "reentrant.h"
64 1.2.4.2 minoura #include <sys/types.h>
65 1.2.4.2 minoura #include <sys/poll.h>
66 1.2.4.2 minoura #include <sys/socket.h>
67 1.2.4.2 minoura
68 1.2.4.2 minoura #include <assert.h>
69 1.2.4.2 minoura #include <err.h>
70 1.2.4.2 minoura #include <errno.h>
71 1.2.4.2 minoura #include <netdb.h>
72 1.2.4.2 minoura #include <stdio.h>
73 1.2.4.2 minoura #include <stdlib.h>
74 1.2.4.2 minoura #include <string.h>
75 1.2.4.2 minoura #include <unistd.h>
76 1.2.4.2 minoura #include <signal.h>
77 1.2.4.2 minoura
78 1.2.4.2 minoura #include <rpc/rpc.h>
79 1.2.4.2 minoura
80 1.2.4.2 minoura #include "rpc_com.h"
81 1.2.4.2 minoura
82 1.2.4.2 minoura #ifdef __weak_alias
83 1.2.4.2 minoura __weak_alias(clnt_vc_create,_clnt_vc_create)
84 1.2.4.2 minoura #endif
85 1.2.4.2 minoura
86 1.2.4.2 minoura #define MCALL_MSG_SIZE 24
87 1.2.4.2 minoura
88 1.2.4.2 minoura static enum clnt_stat clnt_vc_call __P((CLIENT *, rpcproc_t, xdrproc_t, caddr_t,
89 1.2.4.2 minoura xdrproc_t, caddr_t, struct timeval));
90 1.2.4.2 minoura static void clnt_vc_geterr __P((CLIENT *, struct rpc_err *));
91 1.2.4.2 minoura static bool_t clnt_vc_freeres __P((CLIENT *, xdrproc_t, caddr_t));
92 1.2.4.2 minoura static void clnt_vc_abort __P((CLIENT *));
93 1.2.4.2 minoura static bool_t clnt_vc_control __P((CLIENT *, u_int, char *));
94 1.2.4.2 minoura static void clnt_vc_destroy __P((CLIENT *));
95 1.2.4.2 minoura static struct clnt_ops *clnt_vc_ops __P((void));
96 1.2.4.2 minoura static bool_t time_not_ok __P((struct timeval *));
97 1.2.4.2 minoura static int read_vc __P((caddr_t, caddr_t, int));
98 1.2.4.2 minoura static int write_vc __P((caddr_t, caddr_t, int));
99 1.2.4.2 minoura
100 1.2.4.2 minoura struct ct_data {
101 1.2.4.2 minoura int ct_fd;
102 1.2.4.2 minoura bool_t ct_closeit;
103 1.2.4.2 minoura struct timeval ct_wait;
104 1.2.4.2 minoura bool_t ct_waitset; /* wait set by clnt_control? */
105 1.2.4.2 minoura struct netbuf ct_addr;
106 1.2.4.2 minoura struct rpc_err ct_error;
107 1.2.4.2 minoura union {
108 1.2.4.2 minoura char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
109 1.2.4.2 minoura u_int32_t ct_mcalli;
110 1.2.4.2 minoura } ct_u;
111 1.2.4.2 minoura u_int ct_mpos; /* pos after marshal */
112 1.2.4.2 minoura XDR ct_xdrs;
113 1.2.4.2 minoura };
114 1.2.4.2 minoura
115 1.2.4.2 minoura /*
116 1.2.4.2 minoura * This machinery implements per-fd locks for MT-safety. It is not
117 1.2.4.2 minoura * sufficient to do per-CLIENT handle locks for MT-safety because a
118 1.2.4.2 minoura * user may create more than one CLIENT handle with the same fd behind
119 1.2.4.2 minoura * it. Therfore, we allocate an array of flags (vc_fd_locks), protected
120 1.2.4.2 minoura * by the clnt_fd_lock mutex, and an array (vc_cv) of condition variables
121 1.2.4.2 minoura * similarly protected. Vc_fd_lock[fd] == 1 => a call is activte on some
122 1.2.4.2 minoura * CLIENT handle created for that fd.
123 1.2.4.2 minoura * The current implementation holds locks across the entire RPC and reply.
124 1.2.4.2 minoura * Yes, this is silly, and as soon as this code is proven to work, this
125 1.2.4.2 minoura * should be the first thing fixed. One step at a time.
126 1.2.4.2 minoura */
127 1.2.4.2 minoura #ifdef __REENT
128 1.2.4.2 minoura static int *vc_fd_locks;
129 1.2.4.2 minoura extern int __rpc_lock_value;
130 1.2.4.2 minoura extern mutex_t clnt_fd_lock;
131 1.2.4.2 minoura static cond_t *vc_cv;
132 1.2.4.2 minoura #define release_fd_lock(fd, mask) { \
133 1.2.4.2 minoura mutex_lock(&clnt_fd_lock); \
134 1.2.4.2 minoura vc_fd_locks[fd] = 0; \
135 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock); \
136 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &(mask), (sigset_t *) NULL); \
137 1.2.4.2 minoura cond_signal(&vc_cv[fd]); \
138 1.2.4.2 minoura }
139 1.2.4.2 minoura #else
140 1.2.4.2 minoura #define release_fd_lock(fd,mask)
141 1.2.4.2 minoura #define __rpc_lock_value 0
142 1.2.4.2 minoura #endif
143 1.2.4.2 minoura
144 1.2.4.2 minoura
145 1.2.4.2 minoura /*
146 1.2.4.2 minoura * Create a client handle for a connection.
147 1.2.4.2 minoura * Default options are set, which the user can change using clnt_control()'s.
148 1.2.4.2 minoura * The rpc/vc package does buffering similar to stdio, so the client
149 1.2.4.2 minoura * must pick send and receive buffer sizes, 0 => use the default.
150 1.2.4.2 minoura * NB: fd is copied into a private area.
151 1.2.4.2 minoura * NB: The rpch->cl_auth is set null authentication. Caller may wish to
152 1.2.4.2 minoura * set this something more useful.
153 1.2.4.2 minoura *
154 1.2.4.2 minoura * fd should be an open socket
155 1.2.4.2 minoura */
156 1.2.4.2 minoura CLIENT *
157 1.2.4.2 minoura clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
158 1.2.4.2 minoura int fd;
159 1.2.4.2 minoura const struct netbuf *raddr;
160 1.2.4.2 minoura rpcprog_t prog;
161 1.2.4.2 minoura rpcvers_t vers;
162 1.2.4.2 minoura u_int sendsz;
163 1.2.4.2 minoura u_int recvsz;
164 1.2.4.2 minoura {
165 1.2.4.2 minoura CLIENT *h;
166 1.2.4.2 minoura struct ct_data *ct = NULL;
167 1.2.4.2 minoura struct timeval now;
168 1.2.4.2 minoura struct rpc_msg call_msg;
169 1.2.4.2 minoura static u_int32_t disrupt;
170 1.2.4.2 minoura #ifdef __REENT
171 1.2.4.2 minoura sigset_t mask;
172 1.2.4.2 minoura #endif
173 1.2.4.2 minoura sigset_t newmask;
174 1.2.4.2 minoura struct sockaddr_storage ss;
175 1.2.4.2 minoura socklen_t slen;
176 1.2.4.2 minoura struct __rpc_sockinfo si;
177 1.2.4.2 minoura
178 1.2.4.2 minoura if (disrupt == 0)
179 1.2.4.2 minoura disrupt = (u_int32_t)(long)raddr;
180 1.2.4.2 minoura
181 1.2.4.2 minoura h = (CLIENT *)mem_alloc(sizeof(*h));
182 1.2.4.2 minoura if (h == NULL) {
183 1.2.4.2 minoura warnx("clnt_vc_create: out of memory");
184 1.2.4.2 minoura rpc_createerr.cf_stat = RPC_SYSTEMERROR;
185 1.2.4.2 minoura rpc_createerr.cf_error.re_errno = errno;
186 1.2.4.2 minoura goto fooy;
187 1.2.4.2 minoura }
188 1.2.4.2 minoura ct = (struct ct_data *)mem_alloc(sizeof(*ct));
189 1.2.4.2 minoura if (ct == NULL) {
190 1.2.4.2 minoura warnx("clnt_vc_create: out of memory");
191 1.2.4.2 minoura rpc_createerr.cf_stat = RPC_SYSTEMERROR;
192 1.2.4.2 minoura rpc_createerr.cf_error.re_errno = errno;
193 1.2.4.2 minoura goto fooy;
194 1.2.4.2 minoura }
195 1.2.4.2 minoura
196 1.2.4.2 minoura sigfillset(&newmask);
197 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
198 1.2.4.2 minoura #ifdef __REENT
199 1.2.4.2 minoura mutex_lock(&clnt_fd_lock);
200 1.2.4.2 minoura if (vc_fd_locks == (int *) NULL) {
201 1.2.4.2 minoura int cv_allocsz, fd_allocsz;
202 1.2.4.2 minoura int dtbsize = __rpc_dtbsize();
203 1.2.4.2 minoura
204 1.2.4.2 minoura fd_allocsz = dtbsize * sizeof (int);
205 1.2.4.2 minoura vc_fd_locks = (int *) mem_alloc(fd_allocsz);
206 1.2.4.2 minoura if (vc_fd_locks == (int *) NULL) {
207 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
208 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
209 1.2.4.2 minoura goto fooy;
210 1.2.4.2 minoura } else
211 1.2.4.2 minoura memset(vc_fd_locks, '\0', fd_allocsz);
212 1.2.4.2 minoura
213 1.2.4.2 minoura assert(vc_cv == (cond_t *) NULL);
214 1.2.4.2 minoura cv_allocsz = dtbsize * sizeof (cond_t);
215 1.2.4.2 minoura vc_cv = (cond_t *) mem_alloc(cv_allocsz);
216 1.2.4.2 minoura if (vc_cv == (cond_t *) NULL) {
217 1.2.4.2 minoura mem_free(vc_fd_locks, fd_allocsz);
218 1.2.4.2 minoura vc_fd_locks = (int *) NULL;
219 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
220 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
221 1.2.4.2 minoura goto fooy;
222 1.2.4.2 minoura } else {
223 1.2.4.2 minoura int i;
224 1.2.4.2 minoura
225 1.2.4.2 minoura for (i = 0; i < dtbsize; i++)
226 1.2.4.2 minoura cond_init(&vc_cv[i], 0, (void *) 0);
227 1.2.4.2 minoura }
228 1.2.4.2 minoura } else
229 1.2.4.2 minoura assert(vc_cv != (cond_t *) NULL);
230 1.2.4.2 minoura #endif
231 1.2.4.2 minoura
232 1.2.4.2 minoura /*
233 1.2.4.2 minoura * XXX - fvdl connecting while holding a mutex?
234 1.2.4.2 minoura */
235 1.2.4.2 minoura slen = sizeof ss;
236 1.2.4.2 minoura if (getpeername(fd, (struct sockaddr *)&ss, &slen) < 0) {
237 1.2.4.2 minoura if (errno != ENOTCONN) {
238 1.2.4.2 minoura rpc_createerr.cf_stat = RPC_SYSTEMERROR;
239 1.2.4.2 minoura rpc_createerr.cf_error.re_errno = errno;
240 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
241 1.2.4.2 minoura goto fooy;
242 1.2.4.2 minoura }
243 1.2.4.2 minoura if (connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
244 1.2.4.2 minoura rpc_createerr.cf_stat = RPC_SYSTEMERROR;
245 1.2.4.2 minoura rpc_createerr.cf_error.re_errno = errno;
246 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
247 1.2.4.2 minoura goto fooy;
248 1.2.4.2 minoura }
249 1.2.4.2 minoura }
250 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
251 1.2.4.2 minoura if (!__rpc_fd2sockinfo(fd, &si))
252 1.2.4.2 minoura goto fooy;
253 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
254 1.2.4.2 minoura
255 1.2.4.2 minoura ct->ct_closeit = FALSE;
256 1.2.4.2 minoura
257 1.2.4.2 minoura /*
258 1.2.4.2 minoura * Set up private data struct
259 1.2.4.2 minoura */
260 1.2.4.2 minoura ct->ct_fd = fd;
261 1.2.4.2 minoura ct->ct_wait.tv_usec = 0;
262 1.2.4.2 minoura ct->ct_waitset = FALSE;
263 1.2.4.2 minoura ct->ct_addr.buf = malloc(raddr->maxlen);
264 1.2.4.2 minoura if (ct->ct_addr.buf == NULL)
265 1.2.4.2 minoura goto fooy;
266 1.2.4.2 minoura memcpy(ct->ct_addr.buf, &raddr->buf, raddr->len);
267 1.2.4.2 minoura ct->ct_addr.len = raddr->maxlen;
268 1.2.4.2 minoura ct->ct_addr.maxlen = raddr->maxlen;
269 1.2.4.2 minoura
270 1.2.4.2 minoura /*
271 1.2.4.2 minoura * Initialize call message
272 1.2.4.2 minoura */
273 1.2.4.2 minoura (void)gettimeofday(&now, (struct timezone *)0);
274 1.2.4.2 minoura call_msg.rm_xid =
275 1.2.4.2 minoura (u_int32_t)((++disrupt) ^ getpid() ^ now.tv_sec ^ now.tv_usec);
276 1.2.4.2 minoura call_msg.rm_direction = CALL;
277 1.2.4.2 minoura call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
278 1.2.4.2 minoura call_msg.rm_call.cb_prog = (u_int32_t)prog;
279 1.2.4.2 minoura call_msg.rm_call.cb_vers = (u_int32_t)vers;
280 1.2.4.2 minoura
281 1.2.4.2 minoura /*
282 1.2.4.2 minoura * pre-serialize the static part of the call msg and stash it away
283 1.2.4.2 minoura */
284 1.2.4.2 minoura xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE,
285 1.2.4.2 minoura XDR_ENCODE);
286 1.2.4.2 minoura if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
287 1.2.4.2 minoura if (ct->ct_closeit) {
288 1.2.4.2 minoura (void)close(fd);
289 1.2.4.2 minoura }
290 1.2.4.2 minoura goto fooy;
291 1.2.4.2 minoura }
292 1.2.4.2 minoura ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
293 1.2.4.2 minoura XDR_DESTROY(&(ct->ct_xdrs));
294 1.2.4.2 minoura
295 1.2.4.2 minoura /*
296 1.2.4.2 minoura * Create a client handle which uses xdrrec for serialization
297 1.2.4.2 minoura * and authnone for authentication.
298 1.2.4.2 minoura */
299 1.2.4.2 minoura h->cl_ops = clnt_vc_ops();
300 1.2.4.2 minoura h->cl_private = ct;
301 1.2.4.2 minoura h->cl_auth = authnone_create();
302 1.2.4.2 minoura sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
303 1.2.4.2 minoura recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
304 1.2.4.2 minoura xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
305 1.2.4.2 minoura h->cl_private, read_vc, write_vc);
306 1.2.4.2 minoura return (h);
307 1.2.4.2 minoura
308 1.2.4.2 minoura fooy:
309 1.2.4.2 minoura /*
310 1.2.4.2 minoura * Something goofed, free stuff and barf
311 1.2.4.2 minoura */
312 1.2.4.2 minoura if (ct)
313 1.2.4.2 minoura mem_free(ct, sizeof(struct ct_data));
314 1.2.4.2 minoura if (h)
315 1.2.4.2 minoura mem_free(h, sizeof(CLIENT));
316 1.2.4.2 minoura return ((CLIENT *)NULL);
317 1.2.4.2 minoura }
318 1.2.4.2 minoura
319 1.2.4.2 minoura static enum clnt_stat
320 1.2.4.2 minoura clnt_vc_call(h, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
321 1.2.4.2 minoura CLIENT *h;
322 1.2.4.2 minoura rpcproc_t proc;
323 1.2.4.2 minoura xdrproc_t xdr_args;
324 1.2.4.2 minoura caddr_t args_ptr;
325 1.2.4.2 minoura xdrproc_t xdr_results;
326 1.2.4.2 minoura caddr_t results_ptr;
327 1.2.4.2 minoura struct timeval timeout;
328 1.2.4.2 minoura {
329 1.2.4.2 minoura struct ct_data *ct;
330 1.2.4.2 minoura XDR *xdrs;
331 1.2.4.2 minoura struct rpc_msg reply_msg;
332 1.2.4.2 minoura u_int32_t x_id;
333 1.2.4.2 minoura u_int32_t *msg_x_id;
334 1.2.4.2 minoura bool_t shipnow;
335 1.2.4.2 minoura int refreshes = 2;
336 1.2.4.2 minoura #ifdef __REENT
337 1.2.4.2 minoura sigset_t mask, newmask;
338 1.2.4.2 minoura #endif
339 1.2.4.2 minoura
340 1.2.4.2 minoura _DIAGASSERT(h != NULL);
341 1.2.4.2 minoura
342 1.2.4.2 minoura #ifdef __REENT
343 1.2.4.2 minoura sigfillset(&newmask);
344 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
345 1.2.4.2 minoura mutex_lock(&clnt_fd_lock);
346 1.2.4.2 minoura while (vc_fd_locks[ct->ct_fd])
347 1.2.4.2 minoura cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
348 1.2.4.2 minoura vc_fd_locks[ct->ct_fd] = lock_value;
349 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
350 1.2.4.2 minoura #endif
351 1.2.4.2 minoura
352 1.2.4.2 minoura ct = (struct ct_data *) h->cl_private;
353 1.2.4.2 minoura xdrs = &(ct->ct_xdrs);
354 1.2.4.2 minoura msg_x_id = &ct->ct_u.ct_mcalli;
355 1.2.4.2 minoura
356 1.2.4.2 minoura if (!ct->ct_waitset) {
357 1.2.4.2 minoura if (time_not_ok(&timeout) == FALSE)
358 1.2.4.2 minoura ct->ct_wait = timeout;
359 1.2.4.2 minoura }
360 1.2.4.2 minoura
361 1.2.4.2 minoura shipnow =
362 1.2.4.2 minoura (xdr_results == (xdrproc_t)0 && timeout.tv_sec == 0
363 1.2.4.2 minoura && timeout.tv_usec == 0) ? FALSE : TRUE;
364 1.2.4.2 minoura
365 1.2.4.2 minoura call_again:
366 1.2.4.2 minoura xdrs->x_op = XDR_ENCODE;
367 1.2.4.2 minoura ct->ct_error.re_status = RPC_SUCCESS;
368 1.2.4.2 minoura x_id = ntohl(--(*msg_x_id));
369 1.2.4.2 minoura if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) ||
370 1.2.4.2 minoura (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
371 1.2.4.2 minoura (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
372 1.2.4.2 minoura (! (*xdr_args)(xdrs, args_ptr))) {
373 1.2.4.2 minoura if (ct->ct_error.re_status == RPC_SUCCESS)
374 1.2.4.2 minoura ct->ct_error.re_status = RPC_CANTENCODEARGS;
375 1.2.4.2 minoura (void)xdrrec_endofrecord(xdrs, TRUE);
376 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
377 1.2.4.2 minoura return (ct->ct_error.re_status);
378 1.2.4.2 minoura }
379 1.2.4.2 minoura if (! xdrrec_endofrecord(xdrs, shipnow)) {
380 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
381 1.2.4.2 minoura return (ct->ct_error.re_status = RPC_CANTSEND);
382 1.2.4.2 minoura }
383 1.2.4.2 minoura if (! shipnow) {
384 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
385 1.2.4.2 minoura return (RPC_SUCCESS);
386 1.2.4.2 minoura }
387 1.2.4.2 minoura /*
388 1.2.4.2 minoura * Hack to provide rpc-based message passing
389 1.2.4.2 minoura */
390 1.2.4.2 minoura if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
391 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
392 1.2.4.2 minoura return(ct->ct_error.re_status = RPC_TIMEDOUT);
393 1.2.4.2 minoura }
394 1.2.4.2 minoura
395 1.2.4.2 minoura
396 1.2.4.2 minoura /*
397 1.2.4.2 minoura * Keep receiving until we get a valid transaction id
398 1.2.4.2 minoura */
399 1.2.4.2 minoura xdrs->x_op = XDR_DECODE;
400 1.2.4.2 minoura for (;;) {
401 1.2.4.2 minoura reply_msg.acpted_rply.ar_verf = _null_auth;
402 1.2.4.2 minoura reply_msg.acpted_rply.ar_results.where = NULL;
403 1.2.4.2 minoura reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
404 1.2.4.2 minoura if (! xdrrec_skiprecord(xdrs)) {
405 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
406 1.2.4.2 minoura return (ct->ct_error.re_status);
407 1.2.4.2 minoura }
408 1.2.4.2 minoura /* now decode and validate the response header */
409 1.2.4.2 minoura if (! xdr_replymsg(xdrs, &reply_msg)) {
410 1.2.4.2 minoura if (ct->ct_error.re_status == RPC_SUCCESS)
411 1.2.4.2 minoura continue;
412 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
413 1.2.4.2 minoura return (ct->ct_error.re_status);
414 1.2.4.2 minoura }
415 1.2.4.2 minoura if (reply_msg.rm_xid == x_id)
416 1.2.4.2 minoura break;
417 1.2.4.2 minoura }
418 1.2.4.2 minoura
419 1.2.4.2 minoura /*
420 1.2.4.2 minoura * process header
421 1.2.4.2 minoura */
422 1.2.4.2 minoura _seterr_reply(&reply_msg, &(ct->ct_error));
423 1.2.4.2 minoura if (ct->ct_error.re_status == RPC_SUCCESS) {
424 1.2.4.2 minoura if (! AUTH_VALIDATE(h->cl_auth,
425 1.2.4.2 minoura &reply_msg.acpted_rply.ar_verf)) {
426 1.2.4.2 minoura ct->ct_error.re_status = RPC_AUTHERROR;
427 1.2.4.2 minoura ct->ct_error.re_why = AUTH_INVALIDRESP;
428 1.2.4.2 minoura } else if (! (*xdr_results)(xdrs, results_ptr)) {
429 1.2.4.2 minoura if (ct->ct_error.re_status == RPC_SUCCESS)
430 1.2.4.2 minoura ct->ct_error.re_status = RPC_CANTDECODERES;
431 1.2.4.2 minoura }
432 1.2.4.2 minoura /* free verifier ... */
433 1.2.4.2 minoura if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
434 1.2.4.2 minoura xdrs->x_op = XDR_FREE;
435 1.2.4.2 minoura (void)xdr_opaque_auth(xdrs,
436 1.2.4.2 minoura &(reply_msg.acpted_rply.ar_verf));
437 1.2.4.2 minoura }
438 1.2.4.2 minoura } /* end successful completion */
439 1.2.4.2 minoura else {
440 1.2.4.2 minoura /* maybe our credentials need to be refreshed ... */
441 1.2.4.2 minoura if (refreshes-- && AUTH_REFRESH(h->cl_auth))
442 1.2.4.2 minoura goto call_again;
443 1.2.4.2 minoura } /* end of unsuccessful completion */
444 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
445 1.2.4.2 minoura return (ct->ct_error.re_status);
446 1.2.4.2 minoura }
447 1.2.4.2 minoura
448 1.2.4.2 minoura static void
449 1.2.4.2 minoura clnt_vc_geterr(h, errp)
450 1.2.4.2 minoura CLIENT *h;
451 1.2.4.2 minoura struct rpc_err *errp;
452 1.2.4.2 minoura {
453 1.2.4.2 minoura struct ct_data *ct;
454 1.2.4.2 minoura
455 1.2.4.2 minoura _DIAGASSERT(h != NULL);
456 1.2.4.2 minoura _DIAGASSERT(errp != NULL);
457 1.2.4.2 minoura
458 1.2.4.2 minoura ct = (struct ct_data *) h->cl_private;
459 1.2.4.2 minoura *errp = ct->ct_error;
460 1.2.4.2 minoura }
461 1.2.4.2 minoura
462 1.2.4.2 minoura static bool_t
463 1.2.4.2 minoura clnt_vc_freeres(cl, xdr_res, res_ptr)
464 1.2.4.2 minoura CLIENT *cl;
465 1.2.4.2 minoura xdrproc_t xdr_res;
466 1.2.4.2 minoura caddr_t res_ptr;
467 1.2.4.2 minoura {
468 1.2.4.2 minoura struct ct_data *ct;
469 1.2.4.2 minoura XDR *xdrs;
470 1.2.4.2 minoura bool_t dummy;
471 1.2.4.2 minoura #ifdef __REENT
472 1.2.4.2 minoura sigset_t mask;
473 1.2.4.2 minoura #endif
474 1.2.4.2 minoura sigset_t newmask;
475 1.2.4.2 minoura
476 1.2.4.2 minoura _DIAGASSERT(cl != NULL);
477 1.2.4.2 minoura
478 1.2.4.2 minoura ct = (struct ct_data *)cl->cl_private;
479 1.2.4.2 minoura xdrs = &(ct->ct_xdrs);
480 1.2.4.2 minoura
481 1.2.4.2 minoura sigfillset(&newmask);
482 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
483 1.2.4.2 minoura mutex_lock(&clnt_fd_lock);
484 1.2.4.2 minoura #ifdef __REENT
485 1.2.4.2 minoura while (vc_fd_locks[ct->ct_fd])
486 1.2.4.2 minoura cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
487 1.2.4.2 minoura #endif
488 1.2.4.2 minoura
489 1.2.4.2 minoura xdrs->x_op = XDR_FREE;
490 1.2.4.2 minoura dummy = (*xdr_res)(xdrs, res_ptr);
491 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
492 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
493 1.2.4.2 minoura cond_signal(&vc_cv[ct->ct_fd]);
494 1.2.4.2 minoura
495 1.2.4.2 minoura return dummy;
496 1.2.4.2 minoura }
497 1.2.4.2 minoura
498 1.2.4.2 minoura /*ARGSUSED*/
499 1.2.4.2 minoura static void
500 1.2.4.2 minoura clnt_vc_abort(cl)
501 1.2.4.2 minoura CLIENT *cl;
502 1.2.4.2 minoura {
503 1.2.4.2 minoura }
504 1.2.4.2 minoura
505 1.2.4.2 minoura static bool_t
506 1.2.4.2 minoura clnt_vc_control(cl, request, info)
507 1.2.4.2 minoura CLIENT *cl;
508 1.2.4.2 minoura u_int request;
509 1.2.4.2 minoura char *info;
510 1.2.4.2 minoura {
511 1.2.4.2 minoura struct ct_data *ct;
512 1.2.4.2 minoura void *infop = info;
513 1.2.4.2 minoura #ifdef _REENT
514 1.2.4.2 minoura sigset_t mask;
515 1.2.4.2 minoura #endif
516 1.2.4.2 minoura sigset_t newmask;
517 1.2.4.2 minoura
518 1.2.4.2 minoura _DIAGASSERT(cl != NULL);
519 1.2.4.2 minoura
520 1.2.4.2 minoura ct = (struct ct_data *)cl->cl_private;
521 1.2.4.2 minoura
522 1.2.4.2 minoura sigfillset(&newmask);
523 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
524 1.2.4.2 minoura mutex_lock(&clnt_fd_lock);
525 1.2.4.2 minoura #ifdef __REENT
526 1.2.4.2 minoura while (vc_fd_locks[ct->ct_fd])
527 1.2.4.2 minoura cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
528 1.2.4.2 minoura vc_fd_locks[ct->ct_fd] = __rpc_lock_value;
529 1.2.4.2 minoura #endif
530 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
531 1.2.4.2 minoura
532 1.2.4.2 minoura switch (request) {
533 1.2.4.2 minoura case CLSET_FD_CLOSE:
534 1.2.4.2 minoura ct->ct_closeit = TRUE;
535 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
536 1.2.4.2 minoura return (TRUE);
537 1.2.4.2 minoura case CLSET_FD_NCLOSE:
538 1.2.4.2 minoura ct->ct_closeit = FALSE;
539 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
540 1.2.4.2 minoura return (TRUE);
541 1.2.4.2 minoura default:
542 1.2.4.2 minoura break;
543 1.2.4.2 minoura }
544 1.2.4.2 minoura
545 1.2.4.2 minoura /* for other requests which use info */
546 1.2.4.2 minoura if (info == NULL) {
547 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
548 1.2.4.2 minoura return (FALSE);
549 1.2.4.2 minoura }
550 1.2.4.2 minoura switch (request) {
551 1.2.4.2 minoura case CLSET_TIMEOUT:
552 1.2.4.2 minoura if (time_not_ok((struct timeval *)info)) {
553 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
554 1.2.4.2 minoura return (FALSE);
555 1.2.4.2 minoura }
556 1.2.4.2 minoura ct->ct_wait = *(struct timeval *)infop;
557 1.2.4.2 minoura ct->ct_waitset = TRUE;
558 1.2.4.2 minoura break;
559 1.2.4.2 minoura case CLGET_TIMEOUT:
560 1.2.4.2 minoura *(struct timeval *)infop = ct->ct_wait;
561 1.2.4.2 minoura break;
562 1.2.4.2 minoura case CLGET_SERVER_ADDR:
563 1.2.4.2 minoura (void) memcpy(info, ct->ct_addr.buf, (int)ct->ct_addr.len);
564 1.2.4.2 minoura break;
565 1.2.4.2 minoura case CLGET_FD:
566 1.2.4.2 minoura *(int *)info = ct->ct_fd;
567 1.2.4.2 minoura break;
568 1.2.4.2 minoura case CLGET_SVC_ADDR:
569 1.2.4.2 minoura /* The caller should not free this memory area */
570 1.2.4.2 minoura *(struct netbuf *)info = ct->ct_addr;
571 1.2.4.2 minoura break;
572 1.2.4.2 minoura case CLSET_SVC_ADDR: /* set to new address */
573 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
574 1.2.4.2 minoura return (FALSE);
575 1.2.4.2 minoura case CLGET_XID:
576 1.2.4.2 minoura /*
577 1.2.4.2 minoura * use the knowledge that xid is the
578 1.2.4.2 minoura * first element in the call structure
579 1.2.4.2 minoura * This will get the xid of the PREVIOUS call
580 1.2.4.2 minoura */
581 1.2.4.2 minoura *(u_int32_t *)info = ntohl(*(u_int32_t *)&ct->ct_u.ct_mcalli);
582 1.2.4.2 minoura break;
583 1.2.4.2 minoura case CLSET_XID:
584 1.2.4.2 minoura /* This will set the xid of the NEXT call */
585 1.2.4.2 minoura *(u_int32_t *)&ct->ct_u.ct_mcalli =
586 1.2.4.2 minoura htonl(*(u_int32_t *)info + 1);
587 1.2.4.2 minoura /* increment by 1 as clnt_vc_call() decrements once */
588 1.2.4.2 minoura break;
589 1.2.4.2 minoura case CLGET_VERS:
590 1.2.4.2 minoura /*
591 1.2.4.2 minoura * This RELIES on the information that, in the call body,
592 1.2.4.2 minoura * the version number field is the fifth field from the
593 1.2.4.2 minoura * begining of the RPC header. MUST be changed if the
594 1.2.4.2 minoura * call_struct is changed
595 1.2.4.2 minoura */
596 1.2.4.2 minoura *(u_int32_t *)info = ntohl(*(u_int32_t *)(ct->ct_u.ct_mcallc +
597 1.2.4.2 minoura 4 * BYTES_PER_XDR_UNIT));
598 1.2.4.2 minoura break;
599 1.2.4.2 minoura
600 1.2.4.2 minoura case CLSET_VERS:
601 1.2.4.2 minoura *(u_int32_t *)(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT) =
602 1.2.4.2 minoura htonl(*(u_int32_t *)info);
603 1.2.4.2 minoura break;
604 1.2.4.2 minoura
605 1.2.4.2 minoura case CLGET_PROG:
606 1.2.4.2 minoura /*
607 1.2.4.2 minoura * This RELIES on the information that, in the call body,
608 1.2.4.2 minoura * the program number field is the fourth field from the
609 1.2.4.2 minoura * begining of the RPC header. MUST be changed if the
610 1.2.4.2 minoura * call_struct is changed
611 1.2.4.2 minoura */
612 1.2.4.2 minoura *(u_int32_t *)info = ntohl(*(u_int32_t *)(ct->ct_u.ct_mcallc +
613 1.2.4.2 minoura 3 * BYTES_PER_XDR_UNIT));
614 1.2.4.2 minoura break;
615 1.2.4.2 minoura
616 1.2.4.2 minoura case CLSET_PROG:
617 1.2.4.2 minoura *(u_int32_t *)(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT) =
618 1.2.4.2 minoura htonl(*(u_int32_t *)info);
619 1.2.4.2 minoura break;
620 1.2.4.2 minoura
621 1.2.4.2 minoura default:
622 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
623 1.2.4.2 minoura return (FALSE);
624 1.2.4.2 minoura }
625 1.2.4.2 minoura release_fd_lock(ct->ct_fd, mask);
626 1.2.4.2 minoura return (TRUE);
627 1.2.4.2 minoura }
628 1.2.4.2 minoura
629 1.2.4.2 minoura
630 1.2.4.2 minoura static void
631 1.2.4.2 minoura clnt_vc_destroy(cl)
632 1.2.4.2 minoura CLIENT *cl;
633 1.2.4.2 minoura {
634 1.2.4.2 minoura struct ct_data *ct;
635 1.2.4.2 minoura #ifdef __REENT
636 1.2.4.2 minoura int ct_fd = ct->ct_fd;
637 1.2.4.2 minoura sigset_t mask;
638 1.2.4.2 minoura #endif
639 1.2.4.2 minoura sigset_t newmask;
640 1.2.4.2 minoura
641 1.2.4.2 minoura _DIAGASSERT(cl != NULL);
642 1.2.4.2 minoura
643 1.2.4.2 minoura ct = (struct ct_data *) cl->cl_private;
644 1.2.4.2 minoura
645 1.2.4.2 minoura sigfillset(&newmask);
646 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
647 1.2.4.2 minoura mutex_lock(&clnt_fd_lock);
648 1.2.4.2 minoura #ifdef _REENT
649 1.2.4.2 minoura while (vc_fd_locks[ct_fd])
650 1.2.4.2 minoura cond_wait(&vc_cv[ct_fd], &clnt_fd_lock);
651 1.2.4.2 minoura #endif
652 1.2.4.2 minoura if (ct->ct_closeit && ct->ct_fd != -1) {
653 1.2.4.2 minoura (void)close(ct->ct_fd);
654 1.2.4.2 minoura }
655 1.2.4.2 minoura XDR_DESTROY(&(ct->ct_xdrs));
656 1.2.4.2 minoura if (ct->ct_addr.buf)
657 1.2.4.2 minoura free(ct->ct_addr.buf);
658 1.2.4.2 minoura mem_free(ct, sizeof(struct ct_data));
659 1.2.4.2 minoura mem_free(cl, sizeof(CLIENT));
660 1.2.4.2 minoura mutex_unlock(&clnt_fd_lock);
661 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
662 1.2.4.2 minoura
663 1.2.4.2 minoura cond_signal(&vc_cv[ct_fd]);
664 1.2.4.2 minoura }
665 1.2.4.2 minoura
666 1.2.4.2 minoura /*
667 1.2.4.2 minoura * Interface between xdr serializer and tcp connection.
668 1.2.4.2 minoura * Behaves like the system calls, read & write, but keeps some error state
669 1.2.4.2 minoura * around for the rpc level.
670 1.2.4.2 minoura */
671 1.2.4.2 minoura static int
672 1.2.4.2 minoura read_vc(ctp, buf, len)
673 1.2.4.2 minoura caddr_t ctp;
674 1.2.4.2 minoura caddr_t buf;
675 1.2.4.2 minoura int len;
676 1.2.4.2 minoura {
677 1.2.4.2 minoura struct ct_data *ct = (struct ct_data *)(void *)ctp;
678 1.2.4.2 minoura struct pollfd fd;
679 1.2.4.2 minoura int milliseconds = (int)((ct->ct_wait.tv_sec * 1000) +
680 1.2.4.2 minoura (ct->ct_wait.tv_usec / 1000));
681 1.2.4.2 minoura
682 1.2.4.2 minoura if (len == 0)
683 1.2.4.2 minoura return (0);
684 1.2.4.2 minoura fd.fd = ct->ct_fd;
685 1.2.4.2 minoura fd.events = POLLIN;
686 1.2.4.2 minoura for (;;) {
687 1.2.4.2 minoura switch (poll(&fd, 1, milliseconds)) {
688 1.2.4.2 minoura case 0:
689 1.2.4.2 minoura ct->ct_error.re_status = RPC_TIMEDOUT;
690 1.2.4.2 minoura return (-1);
691 1.2.4.2 minoura
692 1.2.4.2 minoura case -1:
693 1.2.4.2 minoura if (errno == EINTR)
694 1.2.4.2 minoura continue;
695 1.2.4.2 minoura ct->ct_error.re_status = RPC_CANTRECV;
696 1.2.4.2 minoura ct->ct_error.re_errno = errno;
697 1.2.4.2 minoura return (-1);
698 1.2.4.2 minoura }
699 1.2.4.2 minoura break;
700 1.2.4.2 minoura }
701 1.2.4.2 minoura switch (len = read(ct->ct_fd, buf, (size_t)len)) {
702 1.2.4.2 minoura
703 1.2.4.2 minoura case 0:
704 1.2.4.2 minoura /* premature eof */
705 1.2.4.2 minoura ct->ct_error.re_errno = ECONNRESET;
706 1.2.4.2 minoura ct->ct_error.re_status = RPC_CANTRECV;
707 1.2.4.2 minoura len = -1; /* it's really an error */
708 1.2.4.2 minoura break;
709 1.2.4.2 minoura
710 1.2.4.2 minoura case -1:
711 1.2.4.2 minoura ct->ct_error.re_errno = errno;
712 1.2.4.2 minoura ct->ct_error.re_status = RPC_CANTRECV;
713 1.2.4.2 minoura break;
714 1.2.4.2 minoura }
715 1.2.4.2 minoura return (len);
716 1.2.4.2 minoura }
717 1.2.4.2 minoura
718 1.2.4.2 minoura static int
719 1.2.4.2 minoura write_vc(ctp, buf, len)
720 1.2.4.2 minoura caddr_t ctp;
721 1.2.4.2 minoura caddr_t buf;
722 1.2.4.2 minoura int len;
723 1.2.4.2 minoura {
724 1.2.4.2 minoura struct ct_data *ct = (struct ct_data *)(void *)ctp;
725 1.2.4.2 minoura int i, cnt;
726 1.2.4.2 minoura
727 1.2.4.2 minoura for (cnt = len; cnt > 0; cnt -= i, buf += i) {
728 1.2.4.2 minoura if ((i = write(ct->ct_fd, buf, (size_t)cnt)) == -1) {
729 1.2.4.2 minoura ct->ct_error.re_errno = errno;
730 1.2.4.2 minoura ct->ct_error.re_status = RPC_CANTSEND;
731 1.2.4.2 minoura return (-1);
732 1.2.4.2 minoura }
733 1.2.4.2 minoura }
734 1.2.4.2 minoura return (len);
735 1.2.4.2 minoura }
736 1.2.4.2 minoura
737 1.2.4.2 minoura static struct clnt_ops *
738 1.2.4.2 minoura clnt_vc_ops()
739 1.2.4.2 minoura {
740 1.2.4.2 minoura static struct clnt_ops ops;
741 1.2.4.2 minoura #ifdef __REENT
742 1.2.4.2 minoura extern mutex_t ops_lock;
743 1.2.4.2 minoura sigset_t mask;
744 1.2.4.2 minoura #endif
745 1.2.4.2 minoura sigset_t newmask;
746 1.2.4.2 minoura
747 1.2.4.2 minoura /* VARIABLES PROTECTED BY ops_lock: ops */
748 1.2.4.2 minoura
749 1.2.4.2 minoura sigfillset(&newmask);
750 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
751 1.2.4.2 minoura mutex_lock(&ops_lock);
752 1.2.4.2 minoura if (ops.cl_call == NULL) {
753 1.2.4.2 minoura ops.cl_call = clnt_vc_call;
754 1.2.4.2 minoura ops.cl_abort = clnt_vc_abort;
755 1.2.4.2 minoura ops.cl_geterr = clnt_vc_geterr;
756 1.2.4.2 minoura ops.cl_freeres = clnt_vc_freeres;
757 1.2.4.2 minoura ops.cl_destroy = clnt_vc_destroy;
758 1.2.4.2 minoura ops.cl_control = clnt_vc_control;
759 1.2.4.2 minoura }
760 1.2.4.2 minoura mutex_unlock(&ops_lock);
761 1.2.4.2 minoura thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
762 1.2.4.2 minoura return (&ops);
763 1.2.4.2 minoura }
764 1.2.4.2 minoura
765 1.2.4.2 minoura /*
766 1.2.4.2 minoura * Make sure that the time is not garbage. -1 value is disallowed.
767 1.2.4.2 minoura * Note this is different from time_not_ok in clnt_dg.c
768 1.2.4.2 minoura */
769 1.2.4.2 minoura static bool_t
770 1.2.4.2 minoura time_not_ok(t)
771 1.2.4.2 minoura struct timeval *t;
772 1.2.4.2 minoura {
773 1.2.4.2 minoura return (t->tv_sec <= -1 || t->tv_sec > 100000000 ||
774 1.2.4.2 minoura t->tv_usec <= -1 || t->tv_usec > 1000000);
775 1.2.4.2 minoura }
776