1 /* $NetBSD: clnt_vc.c,v 1.4 2000/07/14 08:40:42 fvdl Exp $ */
4 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #if defined(LIBC_SCCS) && !defined(lint)
32 static char *sccsid2 = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
33 static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";
34 static char sccsid3[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
40 * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
42 * Copyright (C) 1984, Sun Microsystems, Inc.
44 * TCP based RPC supports 'batched calls'.
45 * A sequence of calls may be batched-up in a send buffer. The rpc call
46 * return immediately to the client even though the call was not necessarily
47 * sent. The batching occurs if the results' xdr routine is NULL (0) AND
48 * the rpc timeout value is zero (see clnt.h, rpc).
50 * Clients should NOT casually batch calls that in fact return results; that is,
51 * the server side should be aware that a call is batched and not produce any
52 * return message. Batched calls that produce many result messages can
53 * deadlock (netlock) the client and the server....
55 * Now go hang yourself.
58 #include "namespace.h"
59 #include "reentrant.h"
60 #include <sys/types.h>
62 #include <sys/syslog.h>
63 #include <sys/socket.h>
67 #include <arpa/inet.h>
79 #include <rpc/rpcsec_gss.h>
80 #include "un-namespace.h"
84 #define MCALL_MSG_SIZE 24
88 struct cmsgcred cmcred;
91 static enum clnt_stat clnt_vc_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
92 xdrproc_t, void *, struct timeval);
93 static void clnt_vc_geterr(CLIENT *, struct rpc_err *);
94 static bool_t clnt_vc_freeres(CLIENT *, xdrproc_t, void *);
95 static void clnt_vc_abort(CLIENT *);
96 static bool_t clnt_vc_control(CLIENT *, u_int, void *);
97 static void clnt_vc_destroy(CLIENT *);
98 static struct clnt_ops *clnt_vc_ops(void);
99 static bool_t time_not_ok(struct timeval *);
100 static int read_vc(void *, void *, int);
101 static int write_vc(void *, void *, int);
102 static int __msgwrite(int, void *, size_t);
103 static int __msgread(int, void *, size_t);
106 int ct_fd; /* connection's fd */
107 bool_t ct_closeit; /* close it on destroy */
108 struct timeval ct_wait; /* wait interval in milliseconds */
109 bool_t ct_waitset; /* wait set by clnt_control? */
110 struct netbuf ct_addr; /* remote addr */
111 struct rpc_err ct_error;
113 char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
116 u_int ct_mpos; /* pos after marshal */
117 XDR ct_xdrs; /* XDR stream */
121 * This machinery implements per-fd locks for MT-safety. It is not
122 * sufficient to do per-CLIENT handle locks for MT-safety because a
123 * user may create more than one CLIENT handle with the same fd behind
124 * it. Therfore, we allocate an array of flags (vc_fd_locks), protected
125 * by the clnt_fd_lock mutex, and an array (vc_cv) of condition variables
126 * similarly protected. Vc_fd_lock[fd] == 1 => a call is activte on some
127 * CLIENT handle created for that fd.
128 * The current implementation holds locks across the entire RPC and reply.
129 * Yes, this is silly, and as soon as this code is proven to work, this
130 * should be the first thing fixed. One step at a time.
132 static int *vc_fd_locks;
133 static cond_t *vc_cv;
134 #define release_fd_lock(fd, mask) { \
135 mutex_lock(&clnt_fd_lock); \
136 vc_fd_locks[fd] = 0; \
137 mutex_unlock(&clnt_fd_lock); \
138 thr_sigsetmask(SIG_SETMASK, &(mask), (sigset_t *) NULL); \
139 cond_signal(&vc_cv[fd]); \
142 static const char clnt_vc_errstr[] = "%s : %s";
143 static const char clnt_vc_str[] = "clnt_vc_create";
144 static const char clnt_read_vc_str[] = "read_vc";
145 static const char __no_mem_str[] = "out of memory";
148 * Create a client handle for a connection.
149 * Default options are set, which the user can change using clnt_control()'s.
150 * The rpc/vc package does buffering similar to stdio, so the client
151 * must pick send and receive buffer sizes, 0 => use the default.
152 * NB: fd is copied into a private area.
153 * NB: The rpch->cl_auth is set null authentication. Caller may wish to
154 * set this something more useful.
156 * fd should be an open socket
159 clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz)
160 int fd; /* open file descriptor */
161 const struct netbuf *raddr; /* servers address */
162 const rpcprog_t prog; /* program number */
163 const rpcvers_t vers; /* version number */
164 u_int sendsz; /* buffer recv size */
165 u_int recvsz; /* buffer send size */
167 CLIENT *cl; /* client handle */
168 struct ct_data *ct = NULL; /* client handle */
170 struct rpc_msg call_msg;
171 static u_int32_t disrupt;
174 struct sockaddr_storage ss;
176 struct __rpc_sockinfo si;
179 disrupt = (u_int32_t)(long)raddr;
181 cl = (CLIENT *)mem_alloc(sizeof (*cl));
182 ct = (struct ct_data *)mem_alloc(sizeof (*ct));
183 if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
184 (void) syslog(LOG_ERR, clnt_vc_errstr,
185 clnt_vc_str, __no_mem_str);
186 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
187 rpc_createerr.cf_error.re_errno = errno;
190 ct->ct_addr.buf = NULL;
191 sigfillset(&newmask);
192 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
193 mutex_lock(&clnt_fd_lock);
194 if (vc_fd_locks == (int *) NULL) {
195 int cv_allocsz, fd_allocsz;
196 int dtbsize = __rpc_dtbsize();
198 fd_allocsz = dtbsize * sizeof (int);
199 vc_fd_locks = (int *) mem_alloc(fd_allocsz);
200 if (vc_fd_locks == (int *) NULL) {
201 mutex_unlock(&clnt_fd_lock);
202 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
205 memset(vc_fd_locks, '\0', fd_allocsz);
207 assert(vc_cv == (cond_t *) NULL);
208 cv_allocsz = dtbsize * sizeof (cond_t);
209 vc_cv = (cond_t *) mem_alloc(cv_allocsz);
210 if (vc_cv == (cond_t *) NULL) {
211 mem_free(vc_fd_locks, fd_allocsz);
212 vc_fd_locks = (int *) NULL;
213 mutex_unlock(&clnt_fd_lock);
214 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
219 for (i = 0; i < dtbsize; i++)
220 cond_init(&vc_cv[i], 0, (void *) 0);
223 assert(vc_cv != (cond_t *) NULL);
226 * XXX - fvdl connecting while holding a mutex?
229 if (_getpeername(fd, (struct sockaddr *)(void *)&ss, &slen) < 0) {
230 if (errno != ENOTCONN) {
231 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
232 rpc_createerr.cf_error.re_errno = errno;
233 mutex_unlock(&clnt_fd_lock);
234 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
237 if (_connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
238 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
239 rpc_createerr.cf_error.re_errno = errno;
240 mutex_unlock(&clnt_fd_lock);
241 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
245 mutex_unlock(&clnt_fd_lock);
246 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
247 if (!__rpc_fd2sockinfo(fd, &si))
250 ct->ct_closeit = FALSE;
253 * Set up private data struct
256 ct->ct_wait.tv_usec = 0;
257 ct->ct_waitset = FALSE;
258 ct->ct_addr.buf = malloc(raddr->maxlen);
259 if (ct->ct_addr.buf == NULL)
261 memcpy(ct->ct_addr.buf, raddr->buf, raddr->len);
262 ct->ct_addr.len = raddr->len;
263 ct->ct_addr.maxlen = raddr->maxlen;
266 * Initialize call message
268 (void)gettimeofday(&now, NULL);
269 call_msg.rm_xid = ((u_int32_t)++disrupt) ^ __RPC_GETXID(&now);
270 call_msg.rm_direction = CALL;
271 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
272 call_msg.rm_call.cb_prog = (u_int32_t)prog;
273 call_msg.rm_call.cb_vers = (u_int32_t)vers;
276 * pre-serialize the static part of the call msg and stash it away
278 xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE,
280 if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
281 if (ct->ct_closeit) {
286 ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
287 XDR_DESTROY(&(ct->ct_xdrs));
288 assert(ct->ct_mpos + sizeof(uint32_t) <= MCALL_MSG_SIZE);
291 * Create a client handle which uses xdrrec for serialization
292 * and authnone for authentication.
294 cl->cl_ops = clnt_vc_ops();
296 cl->cl_auth = authnone_create();
297 sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
298 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
299 xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
300 cl->cl_private, read_vc, write_vc);
306 mem_free(ct->ct_addr.buf, ct->ct_addr.len);
307 mem_free(ct, sizeof (struct ct_data));
310 mem_free(cl, sizeof (CLIENT));
311 return ((CLIENT *)NULL);
314 static enum clnt_stat
315 clnt_vc_call(cl, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
320 xdrproc_t xdr_results;
322 struct timeval timeout;
324 struct ct_data *ct = (struct ct_data *) cl->cl_private;
325 XDR *xdrs = &(ct->ct_xdrs);
326 struct rpc_msg reply_msg;
328 u_int32_t *msg_x_id = &ct->ct_u.ct_mcalli; /* yuk */
331 sigset_t mask, newmask;
337 sigfillset(&newmask);
338 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
339 mutex_lock(&clnt_fd_lock);
340 while (vc_fd_locks[ct->ct_fd])
341 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
346 vc_fd_locks[ct->ct_fd] = rpc_lock_value;
347 mutex_unlock(&clnt_fd_lock);
348 if (!ct->ct_waitset) {
349 /* If time is not within limits, we ignore it. */
350 if (time_not_ok(&timeout) == FALSE)
351 ct->ct_wait = timeout;
355 (xdr_results == NULL && timeout.tv_sec == 0
356 && timeout.tv_usec == 0) ? FALSE : TRUE;
359 xdrs->x_op = XDR_ENCODE;
360 ct->ct_error.re_status = RPC_SUCCESS;
361 x_id = ntohl(--(*msg_x_id));
363 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
364 if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) ||
365 (! XDR_PUTINT32(xdrs, &proc)) ||
366 (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
367 (! (*xdr_args)(xdrs, args_ptr))) {
368 if (ct->ct_error.re_status == RPC_SUCCESS)
369 ct->ct_error.re_status = RPC_CANTENCODEARGS;
370 (void)xdrrec_endofrecord(xdrs, TRUE);
371 release_fd_lock(ct->ct_fd, mask);
372 return (ct->ct_error.re_status);
375 *(uint32_t *) &ct->ct_u.ct_mcallc[ct->ct_mpos] = htonl(proc);
376 if (! __rpc_gss_wrap(cl->cl_auth, ct->ct_u.ct_mcallc,
377 ct->ct_mpos + sizeof(uint32_t),
378 xdrs, xdr_args, args_ptr)) {
379 if (ct->ct_error.re_status == RPC_SUCCESS)
380 ct->ct_error.re_status = RPC_CANTENCODEARGS;
381 (void)xdrrec_endofrecord(xdrs, TRUE);
382 release_fd_lock(ct->ct_fd, mask);
383 return (ct->ct_error.re_status);
386 if (! xdrrec_endofrecord(xdrs, shipnow)) {
387 release_fd_lock(ct->ct_fd, mask);
388 return (ct->ct_error.re_status = RPC_CANTSEND);
391 release_fd_lock(ct->ct_fd, mask);
392 return (RPC_SUCCESS);
395 * Hack to provide rpc-based message passing
397 if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
398 release_fd_lock(ct->ct_fd, mask);
399 return(ct->ct_error.re_status = RPC_TIMEDOUT);
404 * Keep receiving until we get a valid transaction id
406 xdrs->x_op = XDR_DECODE;
408 reply_msg.acpted_rply.ar_verf = _null_auth;
409 reply_msg.acpted_rply.ar_results.where = NULL;
410 reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
411 if (! xdrrec_skiprecord(xdrs)) {
412 release_fd_lock(ct->ct_fd, mask);
413 return (ct->ct_error.re_status);
415 /* now decode and validate the response header */
416 if (! xdr_replymsg(xdrs, &reply_msg)) {
417 if (ct->ct_error.re_status == RPC_SUCCESS)
419 release_fd_lock(ct->ct_fd, mask);
420 return (ct->ct_error.re_status);
422 if (reply_msg.rm_xid == x_id)
429 _seterr_reply(&reply_msg, &(ct->ct_error));
430 if (ct->ct_error.re_status == RPC_SUCCESS) {
431 if (! AUTH_VALIDATE(cl->cl_auth,
432 &reply_msg.acpted_rply.ar_verf)) {
433 ct->ct_error.re_status = RPC_AUTHERROR;
434 ct->ct_error.re_why = AUTH_INVALIDRESP;
436 if (cl->cl_auth->ah_cred.oa_flavor != RPCSEC_GSS) {
437 reply_stat = (*xdr_results)(xdrs, results_ptr);
439 reply_stat = __rpc_gss_unwrap(cl->cl_auth,
440 xdrs, xdr_results, results_ptr);
443 if (ct->ct_error.re_status == RPC_SUCCESS)
444 ct->ct_error.re_status =
448 /* free verifier ... */
449 if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
450 xdrs->x_op = XDR_FREE;
451 (void)xdr_opaque_auth(xdrs,
452 &(reply_msg.acpted_rply.ar_verf));
454 } /* end successful completion */
456 /* maybe our credentials need to be refreshed ... */
457 if (refreshes-- && AUTH_REFRESH(cl->cl_auth, &reply_msg))
459 } /* end of unsuccessful completion */
460 release_fd_lock(ct->ct_fd, mask);
461 return (ct->ct_error.re_status);
465 clnt_vc_geterr(cl, errp)
467 struct rpc_err *errp;
472 assert(errp != NULL);
474 ct = (struct ct_data *) cl->cl_private;
475 *errp = ct->ct_error;
479 clnt_vc_freeres(cl, xdr_res, res_ptr)
492 ct = (struct ct_data *)cl->cl_private;
493 xdrs = &(ct->ct_xdrs);
495 sigfillset(&newmask);
496 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
497 mutex_lock(&clnt_fd_lock);
498 while (vc_fd_locks[ct->ct_fd])
499 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
500 xdrs->x_op = XDR_FREE;
501 dummy = (*xdr_res)(xdrs, res_ptr);
502 mutex_unlock(&clnt_fd_lock);
503 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
504 cond_signal(&vc_cv[ct->ct_fd]);
517 clnt_vc_control(cl, request, info)
530 ct = (struct ct_data *)cl->cl_private;
532 sigfillset(&newmask);
533 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
534 mutex_lock(&clnt_fd_lock);
535 while (vc_fd_locks[ct->ct_fd])
536 cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
541 vc_fd_locks[ct->ct_fd] = rpc_lock_value;
542 mutex_unlock(&clnt_fd_lock);
546 ct->ct_closeit = TRUE;
547 release_fd_lock(ct->ct_fd, mask);
549 case CLSET_FD_NCLOSE:
550 ct->ct_closeit = FALSE;
551 release_fd_lock(ct->ct_fd, mask);
557 /* for other requests which use info */
559 release_fd_lock(ct->ct_fd, mask);
564 if (time_not_ok((struct timeval *)info)) {
565 release_fd_lock(ct->ct_fd, mask);
568 ct->ct_wait = *(struct timeval *)infop;
569 ct->ct_waitset = TRUE;
572 *(struct timeval *)infop = ct->ct_wait;
574 case CLGET_SERVER_ADDR:
575 (void) memcpy(info, ct->ct_addr.buf, (size_t)ct->ct_addr.len);
578 *(int *)info = ct->ct_fd;
581 /* The caller should not free this memory area */
582 *(struct netbuf *)info = ct->ct_addr;
584 case CLSET_SVC_ADDR: /* set to new address */
585 release_fd_lock(ct->ct_fd, mask);
589 * use the knowledge that xid is the
590 * first element in the call structure
591 * This will get the xid of the PREVIOUS call
594 ntohl(*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli);
597 /* This will set the xid of the NEXT call */
598 *(u_int32_t *)(void *)&ct->ct_u.ct_mcalli =
599 htonl(*((u_int32_t *)info) + 1);
600 /* increment by 1 as clnt_vc_call() decrements once */
604 * This RELIES on the information that, in the call body,
605 * the version number field is the fifth field from the
606 * begining of the RPC header. MUST be changed if the
607 * call_struct is changed
610 ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
611 4 * BYTES_PER_XDR_UNIT));
615 *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
616 4 * BYTES_PER_XDR_UNIT) =
617 htonl(*(u_int32_t *)info);
622 * This RELIES on the information that, in the call body,
623 * the program number field is the fourth field from the
624 * begining of the RPC header. MUST be changed if the
625 * call_struct is changed
628 ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
629 3 * BYTES_PER_XDR_UNIT));
633 *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
634 3 * BYTES_PER_XDR_UNIT) =
635 htonl(*(u_int32_t *)info);
639 release_fd_lock(ct->ct_fd, mask);
642 release_fd_lock(ct->ct_fd, mask);
651 struct ct_data *ct = (struct ct_data *) cl->cl_private;
652 int ct_fd = ct->ct_fd;
658 ct = (struct ct_data *) cl->cl_private;
660 sigfillset(&newmask);
661 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
662 mutex_lock(&clnt_fd_lock);
663 while (vc_fd_locks[ct_fd])
664 cond_wait(&vc_cv[ct_fd], &clnt_fd_lock);
665 if (ct->ct_closeit && ct->ct_fd != -1) {
666 (void)_close(ct->ct_fd);
668 XDR_DESTROY(&(ct->ct_xdrs));
669 free(ct->ct_addr.buf);
670 mem_free(ct, sizeof(struct ct_data));
671 if (cl->cl_netid && cl->cl_netid[0])
672 mem_free(cl->cl_netid, strlen(cl->cl_netid) +1);
673 if (cl->cl_tp && cl->cl_tp[0])
674 mem_free(cl->cl_tp, strlen(cl->cl_tp) +1);
675 mem_free(cl, sizeof(CLIENT));
676 mutex_unlock(&clnt_fd_lock);
677 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
678 cond_signal(&vc_cv[ct_fd]);
682 * Interface between xdr serializer and tcp connection.
683 * Behaves like the system calls, read & write, but keeps some error state
684 * around for the rpc level.
687 read_vc(ctp, buf, len)
694 struct ct_data *ct = (struct ct_data *)ctp;
696 int milliseconds = (int)((ct->ct_wait.tv_sec * 1000) +
697 (ct->ct_wait.tv_usec / 1000));
704 switch (_poll(&fd, 1, milliseconds)) {
706 ct->ct_error.re_status = RPC_TIMEDOUT;
712 ct->ct_error.re_status = RPC_CANTRECV;
713 ct->ct_error.re_errno = errno;
720 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
721 (sa.sa_family == AF_LOCAL)) {
722 len = __msgread(ct->ct_fd, buf, (size_t)len);
724 len = _read(ct->ct_fd, buf, (size_t)len);
730 ct->ct_error.re_errno = ECONNRESET;
731 ct->ct_error.re_status = RPC_CANTRECV;
732 len = -1; /* it's really an error */
736 ct->ct_error.re_errno = errno;
737 ct->ct_error.re_status = RPC_CANTRECV;
744 write_vc(ctp, buf, len)
751 struct ct_data *ct = (struct ct_data *)ctp;
755 if ((_getpeername(ct->ct_fd, &sa, &sal) == 0) &&
756 (sa.sa_family == AF_LOCAL)) {
757 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
758 if ((i = __msgwrite(ct->ct_fd, buf,
759 (size_t)cnt)) == -1) {
760 ct->ct_error.re_errno = errno;
761 ct->ct_error.re_status = RPC_CANTSEND;
766 for (cnt = len; cnt > 0; cnt -= i, buf = (char *)buf + i) {
767 if ((i = _write(ct->ct_fd, buf, (size_t)cnt)) == -1) {
768 ct->ct_error.re_errno = errno;
769 ct->ct_error.re_status = RPC_CANTSEND;
777 static struct clnt_ops *
780 static struct clnt_ops ops;
781 sigset_t mask, newmask;
783 /* VARIABLES PROTECTED BY ops_lock: ops */
785 sigfillset(&newmask);
786 thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
787 mutex_lock(&ops_lock);
788 if (ops.cl_call == NULL) {
789 ops.cl_call = clnt_vc_call;
790 ops.cl_abort = clnt_vc_abort;
791 ops.cl_geterr = clnt_vc_geterr;
792 ops.cl_freeres = clnt_vc_freeres;
793 ops.cl_destroy = clnt_vc_destroy;
794 ops.cl_control = clnt_vc_control;
796 mutex_unlock(&ops_lock);
797 thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
802 * Make sure that the time is not garbage. -1 value is disallowed.
803 * Note this is different from time_not_ok in clnt_dg.c
809 return (t->tv_sec <= -1 || t->tv_sec > 100000000 ||
810 t->tv_usec <= -1 || t->tv_usec > 1000000);
814 __msgread(sock, buf, cnt)
823 char control[CMSG_SPACE(sizeof(struct cmsgcred))];
826 bzero((char *)&cm, sizeof(cm));
827 iov[0].iov_base = buf;
828 iov[0].iov_len = cnt;
834 msg.msg_control = (caddr_t)&cm;
835 msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
838 return(_recvmsg(sock, &msg, 0));
842 __msgwrite(sock, buf, cnt)
851 char control[CMSG_SPACE(sizeof(struct cmsgcred))];
854 bzero((char *)&cm, sizeof(cm));
855 iov[0].iov_base = buf;
856 iov[0].iov_len = cnt;
858 cm.cmsg.cmsg_type = SCM_CREDS;
859 cm.cmsg.cmsg_level = SOL_SOCKET;
860 cm.cmsg.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred));
866 msg.msg_control = (caddr_t)&cm;
867 msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
870 return(_sendmsg(sock, &msg, 0));