Print this page
8688 svcadm does not handle multiple partial FMRI arguments
Reviewed by: Dominik Hassler <hadfl@omniosce.org>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libscf/common/error.c
+++ new/usr/src/lib/libscf/common/error.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 * Copyright 2013 Joyent, Inc. All rights reserved.
26 + * Copyright 2017 OmniOS Community Edition (OmniOSce) Association.
26 27 */
27 28
28 29 #include "libscf_impl.h"
29 30
30 31 #include <assert.h>
31 32 #include <dlfcn.h>
32 33 #include <libintl.h>
33 34 #include <pthread.h>
34 35 #include <stdarg.h>
35 36 #include <stdio.h>
36 37 #include <stdlib.h>
37 38 #include <string.h>
38 39 #include <sys/machelf.h>
39 40 #include <thread.h>
40 41
41 42 #include <ucontext.h>
42 43
43 44 extern int ndebug;
44 45
45 46 static struct scf_error_info {
46 47 scf_error_t ei_code;
47 48 const char *ei_desc;
48 49 } scf_errors[] = {
49 50 {SCF_ERROR_NONE, "no error"},
50 51 {SCF_ERROR_NOT_BOUND, "handle not bound"},
51 52 {SCF_ERROR_NOT_SET, "cannot use unset argument"},
52 53 {SCF_ERROR_NOT_FOUND, "entity not found"},
53 54 {SCF_ERROR_TYPE_MISMATCH, "type does not match value"},
54 55 {SCF_ERROR_IN_USE, "cannot modify while in-use"},
55 56 {SCF_ERROR_CONNECTION_BROKEN, "connection to repository broken"},
56 57 {SCF_ERROR_INVALID_ARGUMENT, "invalid argument"},
57 58 {SCF_ERROR_NO_MEMORY, "no memory available"},
58 59 {SCF_ERROR_CONSTRAINT_VIOLATED, "required constraint not met"},
59 60 {SCF_ERROR_EXISTS, "object already exists"},
60 61 {SCF_ERROR_NO_SERVER, "repository server unavailable"},
61 62 {SCF_ERROR_NO_RESOURCES, "server has insufficient resources"},
62 63 {SCF_ERROR_PERMISSION_DENIED, "insufficient privileges for action"},
63 64 {SCF_ERROR_BACKEND_ACCESS, "backend refused access"},
64 65 {SCF_ERROR_BACKEND_READONLY, "backend is read-only"},
65 66 {SCF_ERROR_HANDLE_MISMATCH, "mismatched SCF handles"},
66 67 {SCF_ERROR_HANDLE_DESTROYED, "object bound to destroyed handle"},
67 68 {SCF_ERROR_VERSION_MISMATCH, "incompatible SCF version"},
68 69 {SCF_ERROR_DELETED, "object has been deleted"},
69 70 {SCF_ERROR_TEMPLATE_INVALID, "template data is invalid"},
70 71
71 72 {SCF_ERROR_CALLBACK_FAILED, "user callback function failed"},
72 73
73 74 {SCF_ERROR_INTERNAL, "internal error"}
74 75 };
75 76 #define SCF_NUM_ERRORS (sizeof (scf_errors) / sizeof (*scf_errors))
76 77
77 78 /* a SWAG just in case things get out of sync, we can notice */
78 79 #define LOOKS_VALID(e) \
79 80 ((e) >= scf_errors[0].ei_code && \
80 81 (e) < scf_errors[SCF_NUM_ERRORS - 1].ei_code + 10)
81 82
82 83 static scf_error_t _scf_fallback_error = SCF_ERROR_NONE;
83 84
84 85 #if defined(PTHREAD_ONCE_KEY_NP)
85 86
86 87 static pthread_key_t scf_error_key = PTHREAD_ONCE_KEY_NP;
87 88
88 89 int
89 90 scf_setup_error(void)
90 91 {
91 92 return (pthread_key_create_once_np(&scf_error_key, NULL) == 0);
92 93 }
93 94
94 95 #else /* PTHREAD_ONCE_KEY_NP */
95 96
96 97 /*
97 98 * This old code is here to enable the building of a native version
98 99 * of libscf.so when the build machine has not yet been upgraded
99 100 * to a version of libc that provides pthread_key_create_once_np().
100 101 * It should be deleted when solaris_nevada ships.
101 102 * This code is not MT-safe in a relaxed memory model.
102 103 */
103 104
104 105 static pthread_key_t scf_error_key = 0;
105 106
106 107 int
107 108 scf_setup_error(void)
108 109 {
109 110 static pthread_mutex_t scf_key_lock = PTHREAD_MUTEX_INITIALIZER;
110 111 static volatile int scf_error_key_setup = 0;
111 112
112 113 if (scf_error_key_setup == 0) {
113 114 (void) pthread_mutex_lock(&scf_key_lock);
114 115 if (scf_error_key_setup == 0) {
115 116 if (pthread_key_create(&scf_error_key, NULL) == 0)
116 117 scf_error_key_setup = 1;
117 118 }
118 119 (void) pthread_mutex_unlock(&scf_key_lock);
119 120 }
120 121
121 122 return (scf_error_key_setup == 1);
122 123 }
123 124
124 125 #endif /* PTHREAD_ONCE_KEY_NP */
125 126
126 127 int
127 128 scf_set_error(scf_error_t code)
128 129 {
129 130 assert(LOOKS_VALID(code));
130 131
131 132 if (scf_setup_error())
132 133 (void) pthread_setspecific(scf_error_key, (void *)code);
133 134 else
134 135 _scf_fallback_error = code;
135 136 return (-1);
136 137 }
137 138
138 139 scf_error_t
139 140 scf_error(void)
140 141 {
141 142 scf_error_t ret;
142 143
143 144 ret = (scf_error_t)pthread_getspecific(scf_error_key);
144 145 if (ret == 0)
145 146 return (_scf_fallback_error);
146 147 assert(LOOKS_VALID(ret));
147 148 return (ret);
148 149 }
149 150
150 151 const char *
151 152 scf_strerror(scf_error_t code)
152 153 {
153 154 struct scf_error_info *cur, *end;
154 155
155 156 cur = scf_errors;
156 157 end = cur + SCF_NUM_ERRORS;
157 158
158 159 for (; cur < end; cur++)
159 160 if (code == cur->ei_code)
160 161 return (dgettext(TEXT_DOMAIN, cur->ei_desc));
161 162
162 163 return (dgettext(TEXT_DOMAIN, "unknown error"));
163 164 }
164 165
165 166 const char *
166 167 scf_get_msg(scf_msg_t msg)
167 168 {
168 169 switch (msg) {
169 170 case SCF_MSG_ARGTOOLONG:
170 171 return (dgettext(TEXT_DOMAIN,
171 172 "Argument '%s' is too long, ignoring\n"));
172 173
173 174 case SCF_MSG_PATTERN_NOINSTANCE:
174 175 return (dgettext(TEXT_DOMAIN,
175 176 "Pattern '%s' doesn't match any instances\n"));
176 177
177 178 case SCF_MSG_PATTERN_NOINSTSVC:
178 179 return (dgettext(TEXT_DOMAIN,
179 180 "Pattern '%s' doesn't match any instances or services\n"));
180 181
181 182 case SCF_MSG_PATTERN_NOSERVICE:
182 183 return (dgettext(TEXT_DOMAIN,
183 184 "Pattern '%s' doesn't match any services\n"));
184 185
185 186 case SCF_MSG_PATTERN_NOENTITY:
186 187 return (dgettext(TEXT_DOMAIN,
187 188 "Pattern '%s' doesn't match any entities\n"));
188 189
189 190 case SCF_MSG_PATTERN_MULTIMATCH:
190 191 return (dgettext(TEXT_DOMAIN,
191 192 "Pattern '%s' matches multiple instances:\n"));
↓ open down ↓ |
156 lines elided |
↑ open up ↑ |
192 193
193 194 case SCF_MSG_PATTERN_POSSIBLE:
194 195 return (dgettext(TEXT_DOMAIN, " %s\n"));
195 196
196 197 case SCF_MSG_PATTERN_LEGACY:
197 198 return (dgettext(TEXT_DOMAIN,
198 199 "Operation not supported for legacy service '%s'\n"));
199 200
200 201 case SCF_MSG_PATTERN_MULTIPARTIAL:
201 202 return (dgettext(TEXT_DOMAIN,
202 - "Partial FMRI matches multiple instances\n"));
203 + "Partial FMRI '%s' matches multiple instances\n"));
203 204
204 205 default:
205 206 abort();
206 207 /* NOTREACHED */
207 208 }
208 209
209 210 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX