xref: /titanic_50/usr/src/lib/libtnfctl/status.c (revision 142c9f13e148d687426ed2d4e8bd93717eeaebbc)
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 /*
23  * Copyright (c) 1994, by Sun Microsytems, Inc.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * Error code manipulation routines
30  */
31 
32 #include <string.h>
33 #include <libintl.h>
34 #include <errno.h>
35 
36 #include "tnfctl_int.h"
37 #include "dbg.h"
38 
39 #if !defined(TEXT_DOMAIN)
40 #define	TEXT_DOMAIN	"SYS_TEST"
41 #endif
42 
43 
44 /*
45  * tnfctl_strerror() - this routine returns a pointer to a static string
46  * describing the error argument.
47  */
48 const char *
49 tnfctl_strerror(tnfctl_errcode_t prexstat)
50 {
51 	switch (prexstat) {
52 	case TNFCTL_ERR_NONE:
53 		return (dgettext(TEXT_DOMAIN, "Success"));
54 	case TNFCTL_ERR_ACCES:
55 		return (dgettext(TEXT_DOMAIN, "Permission denied"));
56 	case TNFCTL_ERR_NOTARGET:
57 		return (dgettext(TEXT_DOMAIN, "Target process finished"));
58 	case TNFCTL_ERR_ALLOCFAIL:
59 		return (dgettext(TEXT_DOMAIN, "Memory allocation failed"));
60 	case TNFCTL_ERR_INTERNAL:
61 		return (dgettext(TEXT_DOMAIN, "Internal error"));
62 	case TNFCTL_ERR_SIZETOOSMALL:
63 		return (dgettext(TEXT_DOMAIN, "Requested size too small"));
64 	case TNFCTL_ERR_SIZETOOBIG:
65 		return (dgettext(TEXT_DOMAIN, "Requested size too big"));
66 	case TNFCTL_ERR_BADARG:
67 		return (dgettext(TEXT_DOMAIN, "Bad input argument"));
68 	case TNFCTL_ERR_NOTDYNAMIC:
69 		return (dgettext(TEXT_DOMAIN, "Not a dynamic executable"));
70 	case TNFCTL_ERR_NOLIBTNFPROBE:
71 		return (dgettext(TEXT_DOMAIN,
72 				"No libtnfprobe linked in target"));
73 	case TNFCTL_ERR_BUFEXISTS:
74 		return (dgettext(TEXT_DOMAIN, "Buffer already exists"));
75 	case TNFCTL_ERR_NOBUF:
76 		return (dgettext(TEXT_DOMAIN, "No buffer exists"));
77 	case TNFCTL_ERR_BADDEALLOC:
78 		return (dgettext(TEXT_DOMAIN, "Can't deallocate buffer when "
79 				"tracing is active"));
80 	case TNFCTL_ERR_NOPROCESS:
81 		return (dgettext(TEXT_DOMAIN, "Process not found"));
82 	case TNFCTL_ERR_FILENOTFOUND:
83 		return (dgettext(TEXT_DOMAIN, "No such file"));
84 	case TNFCTL_ERR_BUSY:
85 		return (dgettext(TEXT_DOMAIN,
86 			"Device busy - kernel or process already tracing"));
87 	case TNFCTL_ERR_INVALIDPROBE:
88 		return (dgettext(TEXT_DOMAIN, "Invalid probe specified"));
89 	case TNFCTL_ERR_USR1:
90 		return (dgettext(TEXT_DOMAIN, "User error 1"));
91 	case TNFCTL_ERR_USR2:
92 		return (dgettext(TEXT_DOMAIN, "User error 2"));
93 	case TNFCTL_ERR_USR3:
94 		return (dgettext(TEXT_DOMAIN, "User error 3"));
95 	case TNFCTL_ERR_USR4:
96 		return (dgettext(TEXT_DOMAIN, "User error 4"));
97 	case TNFCTL_ERR_USR5:
98 		return (dgettext(TEXT_DOMAIN, "User error 5"));
99 	default:
100 		return (dgettext(TEXT_DOMAIN,
101 			"Unknown libtnfctl.so error code"));
102 	}
103 }
104 
105 /*
106  * prb_map_to_errocde() - this routine returns maps an internal error code
107  * to a tnfctl_errcode_t
108  */
109 tnfctl_errcode_t
110 _tnfctl_map_to_errcode(prb_status_t prbstat)
111 {
112 	tnfctl_errcode_t	err = TNFCTL_ERR_INTERNAL;
113 
114 	if (prbstat >= PRB_STATUS_MINERRNO &&
115 		prbstat <= PRB_STATUS_MAXERRNO) {
116 		if (prbstat == ENOENT)
117 			err =  TNFCTL_ERR_FILENOTFOUND;
118 		else if (prbstat == ESRCH)
119 			err = TNFCTL_ERR_NOPROCESS;
120 		else if (prbstat == EACCES)
121 			err = TNFCTL_ERR_ACCES;
122 		else if (prbstat == EBUSY)
123 			err = TNFCTL_ERR_BUSY;
124 	} else {
125 		if (prbstat == PRB_STATUS_OK)
126 			err = TNFCTL_ERR_NONE;
127 		else if (prbstat == PRB_STATUS_ALLOCFAIL)
128 			err = TNFCTL_ERR_ALLOCFAIL;
129 	}
130 
131 	return (err);
132 }
133 
134 /*
135  * tnfctl_status_map() - this routine converts an errno value into a
136  * tnfctl_errcode_t
137  */
138 tnfctl_errcode_t
139 tnfctl_status_map(int val)
140 {
141 	tnfctl_errcode_t err = TNFCTL_ERR_INTERNAL;
142 
143 	if (val == ENOENT)
144 		err = TNFCTL_ERR_FILENOTFOUND;
145 	else if (val == ESRCH)
146 		err = TNFCTL_ERR_NOPROCESS;
147 	else if (val == EACCES)
148 		err = TNFCTL_ERR_ACCES;
149 	else if (val == EBUSY)
150 		err = TNFCTL_ERR_BUSY;
151 
152 	return (err);
153 }
154