1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23 /* All Rights Reserved */ 24 25 26 /* 27 * Copyright 1993-2003 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3.4.1 */ 32 33 #include "mt.h" 34 #include <rpc/trace.h> 35 #include <stdlib.h> 36 #include <errno.h> 37 #include <unistd.h> 38 #include <sys/stropts.h> 39 #include <sys/stream.h> 40 #define _SUN_TPI_VERSION 2 41 #include <sys/tihdr.h> 42 #include <sys/timod.h> 43 #include <xti.h> 44 #include <signal.h> 45 #include <syslog.h> 46 #include "tx.h" 47 48 49 int 50 _tx_unbind(int fd, int api_semantics) 51 { 52 struct _ti_user *tiptr; 53 sigset_t mask; 54 int sv_errno, retval, didalloc; 55 struct strbuf ctlbuf; 56 57 trace2(TR_t_unbind, 0, fd); 58 if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL) { 59 sv_errno = errno; 60 trace2(TR_t_unbind, 1, fd); 61 errno = sv_errno; 62 return (-1); 63 } 64 65 if (_T_IS_XTI(api_semantics)) { 66 /* 67 * User level state verification only done for XTI 68 * because doing for TLI may break existing applications 69 */ 70 if (tiptr->ti_state != T_IDLE) { 71 t_errno = TOUTSTATE; 72 trace2(TR_t_unbind, 1, fd); 73 return (-1); 74 } 75 } 76 77 /* 78 * Since unbind is not an idempotent operation, we 79 * block signals around the call. 80 * Note that sig_mutex_lock() only defers signals, it does not 81 * block them, so interruptible syscalls could still get EINTR. 82 */ 83 (void) thr_sigsetmask(SIG_SETMASK, &fillset, &mask); 84 sig_mutex_lock(&tiptr->ti_lock); 85 /* 86 * Acquire buffer for use in sending/receiving the message. 87 * Note: assumes (correctly) that ti_ctlsize is large enough 88 * to hold sizeof (struct T_unbind_req/ack) 89 */ 90 if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) { 91 sv_errno = errno; 92 sig_mutex_unlock(&tiptr->ti_lock); 93 (void) thr_sigsetmask(SIG_SETMASK, &mask, NULL); 94 trace2(TR_t_bind, 1, fd); 95 errno = sv_errno; 96 return (-1); 97 } 98 99 retval = _tx_unbind_locked(fd, tiptr, &ctlbuf); 100 101 sv_errno = errno; 102 if (didalloc) 103 free(ctlbuf.buf); 104 else 105 tiptr->ti_ctlbuf = ctlbuf.buf; 106 sig_mutex_unlock(&tiptr->ti_lock); 107 (void) thr_sigsetmask(SIG_SETMASK, &mask, NULL); 108 trace2(TR_t_unbind, 1, fd); 109 errno = sv_errno; 110 return (retval); 111 } 112 113 int 114 _tx_unbind_locked(int fd, struct _ti_user *tiptr, struct strbuf *ctlbufp) 115 { 116 struct T_unbind_req *unbind_reqp; 117 int sv_errno, retlen; 118 119 trace2(TR_t_unbind_locked, 0, fd); 120 if (_t_is_event(fd, tiptr) < 0) { 121 sv_errno = errno; 122 trace2(TR_t_unbind, 1, fd); 123 errno = sv_errno; 124 return (-1); 125 } 126 127 unbind_reqp = (struct T_unbind_req *)ctlbufp->buf; 128 unbind_reqp->PRIM_type = T_UNBIND_REQ; 129 130 if (_t_do_ioctl(fd, (char *)unbind_reqp, 131 (int)sizeof (struct T_unbind_req), TI_UNBIND, &retlen) < 0) { 132 goto err_out; 133 } 134 135 if (_ioctl(fd, I_FLUSH, FLUSHRW) < 0) { 136 t_errno = TSYSERR; 137 goto err_out; 138 } 139 140 /* 141 * clear more and expedited data bits 142 */ 143 tiptr->ti_flags &= ~(MORE|EXPEDITED); 144 145 _T_TX_NEXTSTATE(T_UNBIND, tiptr, 146 "t_unbind: invalid state event T_UNBIND"); 147 148 trace2(TR_t_unbind_locked, 1, fd); 149 return (0); 150 151 err_out: 152 sv_errno = errno; 153 trace2(TR_t_unbind_locked, 1, fd); 154 errno = sv_errno; 155 return (-1); 156 } 157