import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / nsl / t_unbind.c
blob512895550dd2c66073dd2f4a603c817f45b03766
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
24 /* All Rights Reserved */
27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3.4.1 */
33 #include "mt.h"
34 #include <stdlib.h>
35 #include <errno.h>
36 #include <unistd.h>
37 #include <sys/stropts.h>
38 #include <sys/stream.h>
39 #define _SUN_TPI_VERSION 2
40 #include <sys/tihdr.h>
41 #include <sys/timod.h>
42 #include <xti.h>
43 #include <signal.h>
44 #include <syslog.h>
45 #include "tx.h"
48 int
49 _tx_unbind(int fd, int api_semantics)
51 struct _ti_user *tiptr;
52 sigset_t mask;
53 int sv_errno, retval, didalloc;
54 struct strbuf ctlbuf;
56 if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL)
57 return (-1);
59 if (_T_IS_XTI(api_semantics)) {
61 * User level state verification only done for XTI
62 * because doing for TLI may break existing applications
64 if (tiptr->ti_state != T_IDLE) {
65 t_errno = TOUTSTATE;
66 return (-1);
71 * Since unbind is not an idempotent operation, we
72 * block signals around the call.
73 * Note that sig_mutex_lock() only defers signals, it does not
74 * block them, so interruptible syscalls could still get EINTR.
76 (void) thr_sigsetmask(SIG_SETMASK, &fillset, &mask);
77 sig_mutex_lock(&tiptr->ti_lock);
79 * Acquire buffer for use in sending/receiving the message.
80 * Note: assumes (correctly) that ti_ctlsize is large enough
81 * to hold sizeof (struct T_unbind_req/ack)
83 if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) {
84 sv_errno = errno;
85 sig_mutex_unlock(&tiptr->ti_lock);
86 (void) thr_sigsetmask(SIG_SETMASK, &mask, NULL);
87 errno = sv_errno;
88 return (-1);
91 retval = _tx_unbind_locked(fd, tiptr, &ctlbuf);
93 sv_errno = errno;
94 if (didalloc)
95 free(ctlbuf.buf);
96 else
97 tiptr->ti_ctlbuf = ctlbuf.buf;
98 sig_mutex_unlock(&tiptr->ti_lock);
99 (void) thr_sigsetmask(SIG_SETMASK, &mask, NULL);
100 errno = sv_errno;
101 return (retval);
105 _tx_unbind_locked(int fd, struct _ti_user *tiptr, struct strbuf *ctlbufp)
107 struct T_unbind_req *unbind_reqp;
108 int retlen;
110 if (_t_is_event(fd, tiptr) < 0)
111 return (-1);
113 /* LINTED pointer cast */
114 unbind_reqp = (struct T_unbind_req *)ctlbufp->buf;
115 unbind_reqp->PRIM_type = T_UNBIND_REQ;
117 if (_t_do_ioctl(fd, (char *)unbind_reqp,
118 (int)sizeof (struct T_unbind_req), TI_UNBIND, &retlen) < 0) {
119 goto err_out;
122 if (ioctl(fd, I_FLUSH, FLUSHRW) < 0) {
123 t_errno = TSYSERR;
124 goto err_out;
128 * clear more and expedited data bits
130 tiptr->ti_flags &= ~(MORE|EXPEDITED);
132 _T_TX_NEXTSTATE(T_UNBIND, tiptr,
133 "t_unbind: invalid state event T_UNBIND");
135 return (0);
137 err_out:
138 return (-1);