16683 pthread_cond_timedwait broken when using static initializer
[illumos-gate.git] / usr / src / uts / common / rpc / clnt_perr.c
blob5be7b98af6664027629bacb799a1611d8cb23f74
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 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
36 * clnt_perror.c
38 #include <sys/types.h>
39 #include <sys/t_lock.h>
40 #include <rpc/types.h>
41 #include <rpc/auth.h>
42 #include <rpc/clnt.h>
43 #include <sys/systm.h>
44 #include <sys/cmn_err.h>
45 #include <sys/inttypes.h>
48 * Return an ascii string which matches the RPC clnt stat passed in.
50 const char *
51 clnt_sperrno(const enum clnt_stat stat)
53 switch (stat) {
54 case RPC_SUCCESS:
55 return ("RPC: Success");
56 case RPC_CANTENCODEARGS:
57 return ("RPC: Can't encode arguments");
58 case RPC_CANTDECODERES:
59 return ("RPC: Can't decode result");
60 case RPC_CANTSEND:
61 return ("RPC: Unable to send");
62 case RPC_CANTRECV:
63 return ("RPC: Unable to receive");
64 case RPC_TIMEDOUT:
65 return ("RPC: Timed out");
66 case RPC_INTR:
67 return ("RPC: Interrupted");
68 case RPC_UDERROR:
69 return ("RPC: Unitdata error");
70 case RPC_VERSMISMATCH:
71 return ("RPC: Incompatible versions of RPC");
72 case RPC_AUTHERROR:
73 return ("RPC: Authentication error");
74 case RPC_PROGUNAVAIL:
75 return ("RPC: Program unavailable");
76 case RPC_PROGVERSMISMATCH:
77 return ("RPC: Program/version mismatch");
78 case RPC_PROCUNAVAIL:
79 return ("RPC: Procedure unavailable");
80 case RPC_CANTDECODEARGS:
81 return ("RPC: Server can't decode arguments");
82 case RPC_SYSTEMERROR:
83 return ("RPC: Remote system error");
84 case RPC_UNKNOWNHOST:
85 return ("RPC: Unknown host");
86 case RPC_UNKNOWNPROTO:
87 return ("RPC: Unknown protocol");
88 case RPC_UNKNOWNADDR:
89 return ("RPC: Remote address unknown");
90 case RPC_NOBROADCAST:
91 return ("RPC: Broadcasting not supported");
92 case RPC_PMAPFAILURE:
93 return ("RPC: Port mapper failure");
94 case RPC_PROGNOTREGISTERED:
95 return ("RPC: Program not registered");
96 case RPC_N2AXLATEFAILURE:
97 return ("RPC: Name to address translation failed");
98 case RPC_TLIERROR:
99 return ("RPC: TLI error");
100 case RPC_FAILED:
101 return ("RPC: Failed (unspecified error)");
102 case RPC_INPROGRESS:
103 return ("RPC: Operation in progress");
104 case RPC_STALERACHANDLE:
105 return ("RPC: Stale RAC handle");
106 case RPC_CANTCONNECT:
107 return ("RPC: Couldn't make connection");
108 case RPC_XPRTFAILED:
109 return ("RPC: Received disconnect from remote");
110 case RPC_CANTCREATESTREAM:
111 return ("RPC: Can't push RPC module");
112 case RPC_CANTSTORE:
113 return ("RPC: Can't store pending message");
115 return ("RPC: (unknown error code)");
119 * Return string reply error info. For use after clnt_call().
120 * It allocates the buffer of size MAXPATHLEN and assumes
121 * caller's responsibility to free the memory after use.
123 char *
124 clnt_sperror(const CLIENT *cl, const char *s)
126 struct rpc_err e;
127 #ifdef notyet
128 char *err;
129 #endif
130 char *str;
131 char *strstart;
133 str = kmem_alloc(MAXPATHLEN, KM_SLEEP);
134 strstart = str;
136 CLNT_GETERR((CLIENT *) cl, &e);
138 (void) sprintf(str, "%s: ", s);
139 str += strlen(str);
141 (void) strcpy(str, clnt_sperrno(e.re_status));
142 str += strlen(str);
144 switch (e.re_status) {
145 case RPC_SUCCESS:
146 case RPC_CANTENCODEARGS:
147 case RPC_CANTDECODERES:
148 case RPC_TIMEDOUT:
149 case RPC_PROGUNAVAIL:
150 case RPC_PROCUNAVAIL:
151 case RPC_CANTDECODEARGS:
152 case RPC_SYSTEMERROR:
153 case RPC_UNKNOWNHOST:
154 case RPC_UNKNOWNPROTO:
155 case RPC_UNKNOWNADDR:
156 case RPC_NOBROADCAST:
157 case RPC_RPCBFAILURE:
158 case RPC_PROGNOTREGISTERED:
159 case RPC_FAILED:
160 case RPC_INPROGRESS:
161 break;
163 #ifdef notyet
164 case RPC_N2AXLATEFAILURE:
165 (void) sprintf(str, "; %s", netdir_sperror());
166 break;
167 #endif
169 case RPC_TLIERROR:
170 #ifdef notyet
171 (void) sprintf(str, "; %s", t_errlist[e.re_terrno]);
172 #else
173 (void) sprintf(str, "; %d", e.re_terrno);
174 #endif
175 str += strlen(str);
176 if (e.re_errno) {
177 #ifdef notyet
178 (void) sprintf(str, "; %s", strerror(e.re_errno));
179 #else
180 (void) sprintf(str, "; %d", e.re_errno);
181 #endif
183 break;
185 case RPC_CANTSEND:
186 case RPC_CANTRECV:
187 if (e.re_errno) {
188 #ifdef notyet
189 (void) sprintf(str, "; errno = %s",
190 strerror(e.re_errno));
191 #else
192 (void) sprintf(str, "; errno = %d", e.re_errno);
193 #endif
194 str += strlen(str);
196 if (e.re_terrno) {
197 #ifdef notyet
198 (void) sprintf(str, "; %s", t_errlist[e.re_terrno]);
199 #else
200 (void) sprintf(str, "; %d", e.re_terrno);
201 #endif
203 break;
205 case RPC_VERSMISMATCH:
206 (void) sprintf(str,
207 "; low version = %" PRIu32 ", high version = %" PRIu32,
208 e.re_vers.low, e.re_vers.high);
209 break;
211 #ifdef notyet
212 case RPC_AUTHERROR:
213 err = auth_errmsg(e.re_why);
214 (void) sprintf(str, "; why = ");
215 str += strlen(str);
216 if (err != NULL) {
217 (void) sprintf(str, "%s", err);
218 } else {
219 (void) sprintf(str,
220 "(unknown authentication error - %d)",
221 (int)e.re_why);
223 break;
224 #endif
226 case RPC_PROGVERSMISMATCH:
227 (void) sprintf(str,
228 "; low version = %" PRIu32 ", high version = %" PRIu32,
229 e.re_vers.low, e.re_vers.high);
230 break;
232 default: /* unknown */
233 (void) sprintf(str, "; s1 = %" PRIu32 ", s2 = %" PRIu32,
234 e.re_lb.s1, e.re_lb.s2);
235 break;
237 return (strstart);