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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30
31 /*
32 * System includes
33 */
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <locale.h>
38 #include <libintl.h>
39
40 /*
41 * local pkg command library includes
42 */
43
44 #include "libinst.h"
45 #include "messages.h"
46
47 /*
48 * forward declarations
49 */
50
51 static char *qreasonNoZonename(int caller, int retcode, int started);
52 static char *qreasonWithZonename(int caller, int retcode, int started);
53
54 /*
55 * *****************************************************************************
56 * global external (public) functions
57 * *****************************************************************************
58 */
59
60 /*
61 * Name: qreason
62 * Description: return message describing specified "quit reason"
63 * Arguments: caller - integer describing the "caller:
64 * Caller identities:
65 * 0 - pkginstall - pkgask
66 * 1 - pkginstall - pkgadd
67 * 2 - pkginstall - mailmsg
68 * 3 - pkgremove - quitmsg
69 * 4 - pkgremove - mailmsg
70 * retcode - integer return code describing "reason"
71 * includeZonename - integer describing zone for reason
72 * == 0 - do not include a zone name in the message
73 * != 0 - include a zone name in the message
74 * Returns: char *
75 * NOTE: all messages are returned from static space that does not need
76 * to be free()ed when no longer needed
77 * NOTE: imbedded "%s"s in returned messages are consistent with the
78 * caller and zone name inclusion:
79 * 0 - no %s's
80 * 1 - one %s - package name
81 * 2 - three %s - package name, rootpath, package instance
82 * 3 - one %s - package name
83 * 4 - two %s - package name, rootpath
84 * If "includeZonename" is true, an extra "%s" is added at the
85 * end of each message for the zone name to be included.
86 */
87
88 char *
qreason(int caller,int retcode,int started,int includeZonename)89 qreason(int caller, int retcode, int started, int includeZonename)
90 {
91 if (includeZonename == 0) {
92 return (qreasonNoZonename(caller, retcode, started));
93 }
94
95 return (qreasonWithZonename(caller, retcode, started));
96 }
97
98 /*
99 * *****************************************************************************
100 * static internal (private) functions
101 * *****************************************************************************
102 */
103
104 static char *
qreasonNoZonename(int caller,int retcode,int started)105 qreasonNoZonename(int caller, int retcode, int started)
106 {
107 switch (retcode) {
108 case 0:
109 case 10:
110 case 20:
111 switch (caller) {
112 case 0: /* pkginstall - pkgask */
113 return (MSG_RE_SUC);
114 case 1: /* pkginstall - pkgadd */
115 return (MSG_IN_SUC0);
116 case 2: /* pkginstall - mailmsg */
117 return (MSG_IN_SUC1);
118 case 3: /* pkgremove - quitmsg */
119 return (MSG_RM_SUC0);
120 case 4: /* pkgremove - mailmsg */
121 return (MSG_RM_SUC1);
122 default:
123 return (MSG_UNKREQ);
124 }
125
126 case 1:
127 case 11:
128 case 21:
129 switch (caller) {
130 case 0: /* pkginstall - pkgask */
131 return (MSG_RE_FAIL);
132 case 1: /* pkginstall - pkgadd */
133 return (MSG_IN_FAIL0);
134 case 2: /* pkginstall - mailmsg */
135 return (MSG_IN_FAIL1);
136 case 3: /* pkgremove - quitmsg */
137 return (MSG_RM_FAIL0);
138 case 4: /* pkgremove - mailmsg */
139 return (MSG_RM_FAIL1);
140 default:
141 return (MSG_UNKREQ);
142 }
143
144 case 2:
145 case 12:
146 case 22:
147 switch (caller) {
148 case 0: /* pkginstall - pkgask */
149 return (MSG_RE_PARFAIL);
150 case 1: /* pkginstall - pkgadd */
151 return (MSG_IN_PARFAIL0);
152 case 2: /* pkginstall - mailmsg */
153 return (MSG_IN_PARFAIL1);
154 case 3: /* pkgremove - quitmsg */
155 return (MSG_RM_PARFAIL0);
156 case 4: /* pkgremove - mailmsg */
157 return (MSG_RM_PARFAIL1);
158 default:
159 return (MSG_UNKREQ);
160 }
161
162 case 3:
163 case 13:
164 case 23:
165 switch (caller) {
166 case 0: /* pkginstall - pkgask */
167 return (MSG_RE_USER);
168 case 1: /* pkginstall - pkgadd */
169 return (MSG_IN_USER0);
170 case 2: /* pkginstall - mailmsg */
171 return (MSG_IN_USER1);
172 case 3: /* pkgremove - quitmsg */
173 return (MSG_RM_USER0);
174 case 4: /* pkgremove - mailmsg */
175 return (MSG_RM_USER1);
176 default:
177 return (MSG_UNKREQ);
178 }
179
180 case 4:
181 case 14:
182 case 24:
183 switch (caller) {
184 case 0: /* pkginstall - pkgask */
185 return (MSG_RE_SUA);
186 case 1: /* pkginstall - pkgadd */
187 return (MSG_IN_SUA0);
188 case 2: /* pkginstall - mailmsg */
189 return (MSG_IN_SUA1);
190 case 3: /* pkgremove - quitmsg */
191 return (MSG_RM_SUA0);
192 case 4: /* pkgremove - mailmsg */
193 return (MSG_RM_SUA1);
194 default:
195 return (MSG_UNKREQ);
196 }
197
198 case 5:
199 case 15:
200 case 25:
201 switch (caller) {
202 case 0: /* pkginstall - pkgask */
203 return (MSG_RE_SUI);
204 case 1: /* pkginstall - pkgadd */
205 return (MSG_IN_SUI0);
206 case 2: /* pkginstall - mailmsg */
207 return (MSG_IN_SUI1);
208 case 3: /* pkgremove - quitmsg */
209 return (MSG_RM_SUI0);
210 case 4: /* pkgremove - mailmsg */
211 return (MSG_RM_SUI1);
212 default:
213 return (MSG_UNKREQ);
214 }
215
216 case 99:
217 if (started) {
218 switch (caller) {
219 case 0: /* pkginstall - pkgask */
220 return (MSG_RE_IEPI);
221 case 1: /* pkginstall - pkgadd */
222 return (MSG_IN_IEPI0);
223 case 2: /* pkginstall - mailmsg */
224 return (MSG_IN_IEPI1);
225 case 3: /* pkgremove - quitmsg */
226 return (MSG_RM_IEPI0);
227 case 4: /* pkgremove - mailmsg */
228 return (MSG_RM_IEPI1);
229 default:
230 return (MSG_UNKREQ);
231 }
232 }
233
234 switch (caller) {
235 case 0: /* pkginstall - pkgask */
236 return (MSG_RE_IE);
237 case 1: /* pkginstall - pkgadd */
238 return (MSG_IN_IE0);
239 case 2: /* pkginstall - mailmsg */
240 return (MSG_IN_IE1);
241 case 3: /* pkgremove - quitmsg */
242 return (MSG_RM_IE0);
243 case 4: /* pkgremove - mailmsg */
244 return (MSG_RM_IE1);
245 default:
246 return (MSG_UNKREQ);
247 }
248
249 default:
250 switch (caller) {
251 case 0: /* pkginstall - pkgask */
252 return (MSG_RE_UNK);
253 case 1: /* pkginstall - pkgadd */
254 return (MSG_IN_UNK0);
255 case 2: /* pkginstall - mailmsg */
256 return (MSG_IN_UNK1);
257 case 3: /* pkgremove - quitmsg */
258 return (MSG_RM_UNK0);
259 case 4: /* pkgremove - mailmsg */
260 return (MSG_RM_UNK1);
261 default:
262 return (MSG_UNKREQ);
263 }
264 }
265 }
266
267 static char *
qreasonWithZonename(int caller,int retcode,int started)268 qreasonWithZonename(int caller, int retcode, int started)
269 {
270 switch (retcode) {
271 case 0:
272 case 10:
273 case 20:
274 switch (caller) {
275 case 0: /* pkginstall - pkgask */
276 return (MSG_RE_SUC_ZONE);
277 case 1: /* pkginstall - pkgadd */
278 return (MSG_IN_SUC0_ZONE);
279 case 2: /* pkginstall - mailmsg */
280 return (MSG_IN_SUC1_ZONE);
281 case 3: /* pkgremove - quitmsg */
282 return (MSG_RM_SUC0_ZONE);
283 case 4: /* pkgremove - mailmsg */
284 return (MSG_RM_SUC1_ZONE);
285 default:
286 return (MSG_UNKREQ_ZONE);
287 }
288
289 case 1:
290 case 11:
291 case 21:
292 switch (caller) {
293 case 0: /* pkginstall - pkgask */
294 return (MSG_RE_FAIL_ZONE);
295 case 1: /* pkginstall - pkgadd */
296 return (MSG_IN_FAIL0_ZONE);
297 case 2: /* pkginstall - mailmsg */
298 return (MSG_IN_FAIL1_ZONE);
299 case 3: /* pkgremove - quitmsg */
300 return (MSG_RM_FAIL0_ZONE);
301 case 4: /* pkgremove - mailmsg */
302 return (MSG_RM_FAIL1_ZONE);
303 default:
304 return (MSG_UNKREQ_ZONE);
305 }
306
307 case 2:
308 case 12:
309 case 22:
310 switch (caller) {
311 case 0: /* pkginstall - pkgask */
312 return (MSG_RE_PARFAIL_ZONE);
313 case 1: /* pkginstall - pkgadd */
314 return (MSG_IN_PARFAIL0_ZONE);
315 case 2: /* pkginstall - mailmsg */
316 return (MSG_IN_PARFAIL1_ZONE);
317 case 3: /* pkgremove - quitmsg */
318 return (MSG_RM_PARFAIL0_ZONE);
319 case 4: /* pkgremove - mailmsg */
320 return (MSG_RM_PARFAIL1_ZONE);
321 default:
322 return (MSG_UNKREQ_ZONE);
323 }
324
325 case 3:
326 case 13:
327 case 23:
328 switch (caller) {
329 case 0: /* pkginstall - pkgask */
330 return (MSG_RE_USER_ZONE);
331 case 1: /* pkginstall - pkgadd */
332 return (MSG_IN_USER0_ZONE);
333 case 2: /* pkginstall - mailmsg */
334 return (MSG_IN_USER1_ZONE);
335 case 3: /* pkgremove - quitmsg */
336 return (MSG_RM_USER0_ZONE);
337 case 4: /* pkgremove - mailmsg */
338 return (MSG_RM_USER1_ZONE);
339 default:
340 return (MSG_UNKREQ_ZONE);
341 }
342
343 case 4:
344 case 14:
345 case 24:
346 switch (caller) {
347 case 0: /* pkginstall - pkgask */
348 return (MSG_RE_SUA_ZONE);
349 case 1: /* pkginstall - pkgadd */
350 return (MSG_IN_SUA0_ZONE);
351 case 2: /* pkginstall - mailmsg */
352 return (MSG_IN_SUA1_ZONE);
353 case 3: /* pkgremove - quitmsg */
354 return (MSG_RM_SUA0_ZONE);
355 case 4: /* pkgremove - mailmsg */
356 return (MSG_RM_SUA1_ZONE);
357 default:
358 return (MSG_UNKREQ_ZONE);
359 }
360
361 case 5:
362 case 15:
363 case 25:
364 switch (caller) {
365 case 0: /* pkginstall - pkgask */
366 return (MSG_RE_SUI_ZONE);
367 case 1: /* pkginstall - pkgadd */
368 return (MSG_IN_SUI0_ZONE);
369 case 2: /* pkginstall - mailmsg */
370 return (MSG_IN_SUI1_ZONE);
371 case 3: /* pkgremove - quitmsg */
372 return (MSG_RM_SUI0_ZONE);
373 case 4: /* pkgremove - mailmsg */
374 return (MSG_RM_SUI1_ZONE);
375 default:
376 return (MSG_UNKREQ_ZONE);
377 }
378
379 case 99:
380 if (started) {
381 switch (caller) {
382 case 0: /* pkginstall - pkgask */
383 return (MSG_RE_IEPI_ZONE);
384 case 1: /* pkginstall - pkgadd */
385 return (MSG_IN_IEPI0_ZONE);
386 case 2: /* pkginstall - mailmsg */
387 return (MSG_IN_IEPI1_ZONE);
388 case 3: /* pkgremove - quitmsg */
389 return (MSG_RM_IEPI0_ZONE);
390 case 4: /* pkgremove - mailmsg */
391 return (MSG_RM_IEPI1_ZONE);
392 default:
393 return (MSG_UNKREQ_ZONE);
394 }
395 }
396
397 switch (caller) {
398 case 0: /* pkginstall - pkgask */
399 return (MSG_RE_IE_ZONE);
400 case 1: /* pkginstall - pkgadd */
401 return (MSG_IN_IE0_ZONE);
402 case 2: /* pkginstall - mailmsg */
403 return (MSG_IN_IE1_ZONE);
404 case 3: /* pkgremove - quitmsg */
405 return (MSG_RM_IE0_ZONE);
406 case 4: /* pkgremove - mailmsg */
407 return (MSG_RM_IE1_ZONE);
408 default:
409 return (MSG_UNKREQ_ZONE);
410 }
411
412 default:
413 switch (caller) {
414 case 0: /* pkginstall - pkgask */
415 return (MSG_RE_UNK_ZONE);
416 case 1: /* pkginstall - pkgadd */
417 return (MSG_IN_UNK0_ZONE);
418 case 2: /* pkginstall - mailmsg */
419 return (MSG_IN_UNK1_ZONE);
420 case 3: /* pkgremove - quitmsg */
421 return (MSG_RM_UNK0_ZONE);
422 case 4: /* pkgremove - mailmsg */
423 return (MSG_RM_UNK1_ZONE);
424 default:
425 return (MSG_UNKREQ_ZONE);
426 }
427 }
428 }
429