xref: /onnv-gate/usr/src/lib/cfgadm_plugins/sbd/common/ap_msg.c (revision 12004:93f274d4a367)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52626Skd93003  * Common Development and Distribution License (the "License").
62626Skd93003  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12004Sjiang.liu@intel.com  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <ctype.h>
270Sstevel@tonic-gate #include <stdio.h>
280Sstevel@tonic-gate #include <stdlib.h>
290Sstevel@tonic-gate #include <stdarg.h>
300Sstevel@tonic-gate #include <string.h>
310Sstevel@tonic-gate #include <unistd.h>
320Sstevel@tonic-gate #include <macros.h>
330Sstevel@tonic-gate #include <errno.h>
340Sstevel@tonic-gate #include <locale.h>
350Sstevel@tonic-gate #include <libdevinfo.h>
360Sstevel@tonic-gate #include <librcm.h>
370Sstevel@tonic-gate #define	CFGA_PLUGIN_LIB
380Sstevel@tonic-gate #include <config_admin.h>
390Sstevel@tonic-gate #include "ap.h"
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #ifdef	SBD_DEBUG
420Sstevel@tonic-gate 
430Sstevel@tonic-gate static FILE *debug_fp;
440Sstevel@tonic-gate 
450Sstevel@tonic-gate int
debugging(void)460Sstevel@tonic-gate debugging(void)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate 	char *ep;
490Sstevel@tonic-gate 	static int inited;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate 	if (inited)
520Sstevel@tonic-gate 		return (debug_fp != NULL);
530Sstevel@tonic-gate 	inited = 1;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate 	if ((ep = getenv("SBD_DEBUG")) == NULL)
560Sstevel@tonic-gate 		return (0);
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	if (*ep == '\0')
590Sstevel@tonic-gate 		debug_fp = stderr;
600Sstevel@tonic-gate 	else {
610Sstevel@tonic-gate 		if ((debug_fp = fopen(ep, "a")) == NULL)
620Sstevel@tonic-gate 			return (0);
630Sstevel@tonic-gate 	}
64*12004Sjiang.liu@intel.com 	(void) fprintf(debug_fp, "\nDebug started, pid=%d\n", (int)getpid());
650Sstevel@tonic-gate 	return (1);
660Sstevel@tonic-gate }
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*PRINTFLIKE1*/
690Sstevel@tonic-gate void
dbg(char * fmt,...)700Sstevel@tonic-gate dbg(char *fmt, ...)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate 	va_list ap;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	if (!debugging())
750Sstevel@tonic-gate 		return;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	va_start(ap, fmt);
780Sstevel@tonic-gate 	(void) vfprintf(debug_fp, fmt, ap);
790Sstevel@tonic-gate 	va_end(ap);
800Sstevel@tonic-gate }
810Sstevel@tonic-gate #endif
820Sstevel@tonic-gate 
830Sstevel@tonic-gate static char *
840Sstevel@tonic-gate ap_err_fmts[] = {
850Sstevel@tonic-gate 	"command invalid: %s",
860Sstevel@tonic-gate 	"%s %s: %s%s%s",			/* command failed */
870Sstevel@tonic-gate 	"%s %s",				/* command nacked */
880Sstevel@tonic-gate 	"command not supported: %s %s",
890Sstevel@tonic-gate 	"command aborted: %s %s",
900Sstevel@tonic-gate 	"option invalid: %s",
910Sstevel@tonic-gate 	"option requires value: %s",
920Sstevel@tonic-gate 	"option requires no value: %s",
930Sstevel@tonic-gate 	"option value invalid: %s %s",
940Sstevel@tonic-gate 	"attachment point invalid: %s",
950Sstevel@tonic-gate 	"component invalid: %s",
960Sstevel@tonic-gate 	"sequence invalid: %s (%s %s) %s",
970Sstevel@tonic-gate 	"change signal disposition failed",
980Sstevel@tonic-gate 	"cannot get RCM handle",
990Sstevel@tonic-gate 	"RCM %s failed for %s",
1000Sstevel@tonic-gate 	"\n%-30s %-10s %s",
1010Sstevel@tonic-gate 	"cannot open %s%s%s",
1020Sstevel@tonic-gate 	"cannot find symbol %s in %s",
1030Sstevel@tonic-gate 	"cannot stat %s: %s",
1040Sstevel@tonic-gate 	"not enough memory",
1050Sstevel@tonic-gate 	"%s plugin: %s",
1060Sstevel@tonic-gate 	"unknown error",
1070Sstevel@tonic-gate 	NULL
1080Sstevel@tonic-gate };
1090Sstevel@tonic-gate 
110*12004Sjiang.liu@intel.com #define	ap_err_fmt(i)		ap_err_fmts[min((uint_t)(i), ERR_NONE)]
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate static char *
1130Sstevel@tonic-gate ap_msg_fmts[] = {
1140Sstevel@tonic-gate 	"%s %s\n",
1150Sstevel@tonic-gate 	"%s %s skipped\n",
1160Sstevel@tonic-gate 	"System may be temporarily suspended, proceed",
1170Sstevel@tonic-gate 	"%s %s aborted\n",
1180Sstevel@tonic-gate 	"%s %s done\n",
1190Sstevel@tonic-gate 	"%s %s failed\n",
1200Sstevel@tonic-gate 	"RCM library not found, feature will be disabled\n",
1210Sstevel@tonic-gate 	"Unknown message\n",
1220Sstevel@tonic-gate 	NULL
1230Sstevel@tonic-gate };
1240Sstevel@tonic-gate 
125*12004Sjiang.liu@intel.com #define	ap_msg_fmt(i)		ap_msg_fmts[min((uint_t)(i), MSG_NONE)]
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate #define	STR_BD			"board"
1280Sstevel@tonic-gate #define	STR_SEP			": "
1290Sstevel@tonic-gate #define	STR_NULL		"NULL"
1300Sstevel@tonic-gate #define	STR_CMD_UNKNOWN		"unknown command"
1310Sstevel@tonic-gate #define	STR_ERR_UNKNOWN		"unknown error"
1320Sstevel@tonic-gate #define	STR_MSG_UNKNOWN		"unknown message\n"
1330Sstevel@tonic-gate #define	STR_TGT_UNKNOWN		"unknown target"
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate #define	get_cmd(c, ap, v) \
1360Sstevel@tonic-gate { \
1370Sstevel@tonic-gate 	(v) = va_arg((ap), int); \
1380Sstevel@tonic-gate 	if (((c) = ap_cmd_name((v))) == NULL) \
1390Sstevel@tonic-gate 		(c) = STR_CMD_UNKNOWN; \
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate #define	get_tgt(t, ap) {\
1420Sstevel@tonic-gate 	(t) = va_arg((ap), char *); \
1430Sstevel@tonic-gate 	if (!str_valid((t))) \
1440Sstevel@tonic-gate 		(t) = STR_TGT_UNKNOWN; \
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate #define	check_tgt(tgt, t) {\
1470Sstevel@tonic-gate 	if (str_valid((tgt))) \
1480Sstevel@tonic-gate 		(t) = (tgt); \
1490Sstevel@tonic-gate 	else \
1500Sstevel@tonic-gate 		(t) = STR_TGT_UNKNOWN; \
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate #define	get_str(v, ap, d) \
1530Sstevel@tonic-gate { \
1540Sstevel@tonic-gate 	(v) = va_arg((ap), char *); \
1550Sstevel@tonic-gate 	if ((v) == NULL) \
1560Sstevel@tonic-gate 		(v) = (d); \
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate static char *
1600Sstevel@tonic-gate ap_stnames[] = {
1610Sstevel@tonic-gate 	"unknown state",
1620Sstevel@tonic-gate 	"empty",
1630Sstevel@tonic-gate 	"disconnected",
1640Sstevel@tonic-gate 	"connected",
1650Sstevel@tonic-gate 	"unconfigured",
1660Sstevel@tonic-gate 	"configured"
1670Sstevel@tonic-gate };
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate /*
1700Sstevel@tonic-gate  * ap_err() accepts a variable number of message IDs and constructs
1710Sstevel@tonic-gate  * a corresponding error string.  ap_err() calls dgettext() to
1720Sstevel@tonic-gate  * internationalize the proper portions of a message.  If a system
1730Sstevel@tonic-gate  * error was encountered (errno set), ap_err() looks for the error
1740Sstevel@tonic-gate  * string corresponding to the returned error code if one is available.
1750Sstevel@tonic-gate  * If not, the standard libc error string is fetched.
1760Sstevel@tonic-gate  */
1770Sstevel@tonic-gate void
ap_err(apd_t * a,...)1780Sstevel@tonic-gate ap_err(apd_t *a, ...)
1790Sstevel@tonic-gate {
1800Sstevel@tonic-gate 	int v;
1810Sstevel@tonic-gate 	int err;
1820Sstevel@tonic-gate 	int len;
1830Sstevel@tonic-gate 	char *p;
1840Sstevel@tonic-gate 	char *sep;
1850Sstevel@tonic-gate 	char *rsep;
1860Sstevel@tonic-gate 	const char *fmt;
1870Sstevel@tonic-gate 	char *cmd;
1880Sstevel@tonic-gate 	char *value;
1890Sstevel@tonic-gate 	char *target;
1900Sstevel@tonic-gate 	char *serr;
1910Sstevel@tonic-gate 	char *syserr;
1920Sstevel@tonic-gate 	char *rstate;
1930Sstevel@tonic-gate 	char *ostate;
1940Sstevel@tonic-gate 	char *srsrc;
1950Sstevel@tonic-gate 	char *sysrsrc;
1960Sstevel@tonic-gate 	char *option;
1970Sstevel@tonic-gate 	char *path;
1980Sstevel@tonic-gate 	char *sym;
1990Sstevel@tonic-gate 	char *msg;
2000Sstevel@tonic-gate 	const char *error;
2010Sstevel@tonic-gate 	char **errstring;
2020Sstevel@tonic-gate 	char *rinfostr = NULL;
2030Sstevel@tonic-gate 	va_list ap;
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	DBG("ap_err(%p)\n", (void *)a);
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate 	/*
2080Sstevel@tonic-gate 	 * If there is no descriptor or string pointer or if
2090Sstevel@tonic-gate 	 * there is an outstanding error, just return.
2100Sstevel@tonic-gate 	 */
2110Sstevel@tonic-gate 	if (a == NULL || (errstring = a->errstring) == NULL ||
2120Sstevel@tonic-gate 	    *errstring != NULL)
2130Sstevel@tonic-gate 		return;
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate 	va_start(ap, a);
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	err = va_arg(ap, int);
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 	if ((fmt = ap_err_fmt(err)) == NULL)
2200Sstevel@tonic-gate 		fmt = STR_ERR_UNKNOWN;
2210Sstevel@tonic-gate 	fmt = dgettext(TEXT_DOMAIN, fmt);
2220Sstevel@tonic-gate 	len = strlen(fmt);
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	sep = "";
2250Sstevel@tonic-gate 	serr = NULL;
2260Sstevel@tonic-gate 	srsrc = NULL;
2270Sstevel@tonic-gate 	error = NULL;
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 	/*
2300Sstevel@tonic-gate 	 * Get the proper arguments for the error.
2310Sstevel@tonic-gate 	 */
2320Sstevel@tonic-gate 	switch (err) {
2330Sstevel@tonic-gate 	case ERR_CMD_ABORT:
2340Sstevel@tonic-gate 	case ERR_CMD_FAIL:
2350Sstevel@tonic-gate 	case ERR_CMD_NACK:
2360Sstevel@tonic-gate 		get_cmd(cmd, ap, v);
2370Sstevel@tonic-gate 		check_tgt(a->target, target);
2380Sstevel@tonic-gate 		len += strlen(cmd) + strlen(target);
2390Sstevel@tonic-gate 		DBG("<%s><%s>", cmd, target);
2400Sstevel@tonic-gate 		break;
2410Sstevel@tonic-gate 	case ERR_CMD_NOTSUPP:
2420Sstevel@tonic-gate 		get_cmd(cmd, ap, v);
2430Sstevel@tonic-gate 		if (a->tgt == AP_BOARD)
2440Sstevel@tonic-gate 			target = STR_BD;
2450Sstevel@tonic-gate 		else
2460Sstevel@tonic-gate 			check_tgt(a->cname, target);
2470Sstevel@tonic-gate 		len += strlen(cmd) + strlen(target);
2480Sstevel@tonic-gate 		DBG("<%s><%s>", cmd, target);
2490Sstevel@tonic-gate 		break;
2500Sstevel@tonic-gate 	case ERR_AP_INVAL:
2510Sstevel@tonic-gate 		check_tgt((char *)a->apid, target);
2520Sstevel@tonic-gate 		len += strlen(target);
2530Sstevel@tonic-gate 		DBG("<%s>", target);
2540Sstevel@tonic-gate 		break;
2550Sstevel@tonic-gate 	case ERR_CMD_INVAL:
2560Sstevel@tonic-gate 	case ERR_CM_INVAL:
2570Sstevel@tonic-gate 	case ERR_OPT_INVAL:
2580Sstevel@tonic-gate 	case ERR_OPT_NOVAL:
2590Sstevel@tonic-gate 	case ERR_OPT_VAL:
2600Sstevel@tonic-gate 	case ERR_OPT_BADVAL:
2610Sstevel@tonic-gate 		get_str(option, ap, STR_NULL);
2620Sstevel@tonic-gate 		len += strlen(option);
2630Sstevel@tonic-gate 		DBG("<%s>", option);
2640Sstevel@tonic-gate 		if (err != ERR_OPT_BADVAL)
2650Sstevel@tonic-gate 			break;
2660Sstevel@tonic-gate 		get_str(value, ap, STR_NULL);
2670Sstevel@tonic-gate 		len += strlen(value);
2680Sstevel@tonic-gate 		DBG("<%s>", value);
2690Sstevel@tonic-gate 		break;
2700Sstevel@tonic-gate 	case ERR_TRANS_INVAL: {
2710Sstevel@tonic-gate 		cfga_stat_t rs, os;
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 		get_cmd(cmd, ap, v);
2740Sstevel@tonic-gate 		check_tgt(a->target, target);
2750Sstevel@tonic-gate 		len += strlen(cmd) + strlen(target);
2760Sstevel@tonic-gate 		ap_state(a, &rs, &os);
2770Sstevel@tonic-gate 		rstate = ap_stnames[rs];
2780Sstevel@tonic-gate 		ostate = ap_stnames[os];
2790Sstevel@tonic-gate 		len += strlen(rstate) + strlen(ostate);
2800Sstevel@tonic-gate 		DBG("<%s><%s><%s><%s>", cmd, target, rstate, ostate);
2810Sstevel@tonic-gate 		break;
2820Sstevel@tonic-gate 	}
2830Sstevel@tonic-gate 	case ERR_RCM_CMD: {
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 		get_cmd(cmd, ap, v);
2860Sstevel@tonic-gate 		check_tgt(a->target, target);
2870Sstevel@tonic-gate 		len += strlen(cmd) + strlen(target);
2880Sstevel@tonic-gate 		DBG("<%s><%s>", cmd, target);
2890Sstevel@tonic-gate 
2902626Skd93003 		if ((ap_rcm_info(a, &rinfostr) == 0) && (rinfostr != NULL)) {
2910Sstevel@tonic-gate 			len += strlen(rinfostr);
2920Sstevel@tonic-gate 		}
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate 		break;
2950Sstevel@tonic-gate 	}
2960Sstevel@tonic-gate 	case ERR_LIB_OPEN:
2970Sstevel@tonic-gate 		get_str(path, ap, STR_NULL);
2980Sstevel@tonic-gate 		get_str(error, ap, "");
2990Sstevel@tonic-gate 		if (str_valid(error))
3000Sstevel@tonic-gate 			sep = STR_SEP;
3010Sstevel@tonic-gate 		DBG("<%s><%s>", path, error);
3020Sstevel@tonic-gate 		break;
3030Sstevel@tonic-gate 	case ERR_LIB_SYM:
3040Sstevel@tonic-gate 		get_str(path, ap, STR_NULL);
3050Sstevel@tonic-gate 		get_str(sym, ap, STR_NULL);
3060Sstevel@tonic-gate 		DBG("<%s><%s>", path, sym);
3070Sstevel@tonic-gate 		break;
3080Sstevel@tonic-gate 	case ERR_STAT:
3090Sstevel@tonic-gate 		get_str(path, ap, STR_NULL);
3100Sstevel@tonic-gate 		break;
3110Sstevel@tonic-gate 	case ERR_PLUGIN:
3120Sstevel@tonic-gate 		get_str(msg, ap, STR_NULL);
3130Sstevel@tonic-gate 		break;
3140Sstevel@tonic-gate 	default:
3150Sstevel@tonic-gate 		DBG("<NOARGS>");
3160Sstevel@tonic-gate 		break;
3170Sstevel@tonic-gate 	}
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	va_end(ap);
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate 	/*
3220Sstevel@tonic-gate 	 * In case of a system error, get the reason for
3230Sstevel@tonic-gate 	 * the failure as well as the resource if availbale.
3240Sstevel@tonic-gate 	 * If we already got some error info (e.g. from RCM)
3250Sstevel@tonic-gate 	 * don't bother looking.
3260Sstevel@tonic-gate 	 */
3270Sstevel@tonic-gate 	if (!str_valid(error) && errno) {
3280Sstevel@tonic-gate 		sep = STR_SEP;
3290Sstevel@tonic-gate 		sysrsrc = NULL;
3300Sstevel@tonic-gate 		if ((syserr = ap_sys_err(a, &sysrsrc)) == NULL)
3310Sstevel@tonic-gate 			syserr = STR_ERR_UNKNOWN;
3320Sstevel@tonic-gate 		else
3330Sstevel@tonic-gate 			serr = syserr;
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 		syserr = dgettext(TEXT_DOMAIN, syserr);
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate 		if (sysrsrc == NULL)
3380Sstevel@tonic-gate 			sysrsrc = "";
3390Sstevel@tonic-gate 		else
3400Sstevel@tonic-gate 			srsrc = sysrsrc;
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate 		len += strlen(syserr) + strlen(sysrsrc);
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 		if (str_valid(sysrsrc)) {
3450Sstevel@tonic-gate 			rsep = STR_SEP;
3460Sstevel@tonic-gate 			len += strlen(rsep);
3470Sstevel@tonic-gate 		} else
3480Sstevel@tonic-gate 			rsep = "";
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 		DBG("<%s><%s><%s>", syserr, rsep, sysrsrc);
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate 	} else
3530Sstevel@tonic-gate 		syserr = rsep = sysrsrc = "";
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	DBG("\n");
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 	if ((p = (char *)calloc(len, 1)) != NULL)
3580Sstevel@tonic-gate 		*errstring = p;
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	/*
3610Sstevel@tonic-gate 	 * Print the string with appropriate arguments.
3620Sstevel@tonic-gate 	 */
3630Sstevel@tonic-gate 	switch (err) {
3640Sstevel@tonic-gate 	case ERR_CMD_FAIL:
3650Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, cmd, target,
366*12004Sjiang.liu@intel.com 		    syserr, rsep, sysrsrc);
3670Sstevel@tonic-gate 		break;
3680Sstevel@tonic-gate 	case ERR_CMD_ABORT:
3690Sstevel@tonic-gate 	case ERR_CMD_NACK:
3700Sstevel@tonic-gate 	case ERR_CMD_NOTSUPP:
3710Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, cmd, target);
3720Sstevel@tonic-gate 		break;
3730Sstevel@tonic-gate 	case ERR_AP_INVAL:
3740Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, target);
3750Sstevel@tonic-gate 		break;
3760Sstevel@tonic-gate 	case ERR_CMD_INVAL:
3770Sstevel@tonic-gate 	case ERR_CM_INVAL:
3780Sstevel@tonic-gate 	case ERR_OPT_INVAL:
3790Sstevel@tonic-gate 	case ERR_OPT_NOVAL:
3800Sstevel@tonic-gate 	case ERR_OPT_VAL:
3810Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, option);
3820Sstevel@tonic-gate 		break;
3830Sstevel@tonic-gate 	case ERR_OPT_BADVAL:
3840Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, option, value);
3850Sstevel@tonic-gate 		break;
3860Sstevel@tonic-gate 	case ERR_TRANS_INVAL:
3870Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, cmd, rstate, ostate, target);
3880Sstevel@tonic-gate 		break;
3890Sstevel@tonic-gate 	case ERR_SIG_CHANGE:
3900Sstevel@tonic-gate 	case ERR_RCM_HANDLE:
3910Sstevel@tonic-gate 		(void) snprintf(p, len, fmt);
3920Sstevel@tonic-gate 		break;
3930Sstevel@tonic-gate 	case ERR_RCM_CMD:
3940Sstevel@tonic-gate 		/*
3950Sstevel@tonic-gate 		 * If the rinfostr has a string, then the librcm has returned
3960Sstevel@tonic-gate 		 * us a text field of its reasons why the command failed.
3970Sstevel@tonic-gate 		 *
3980Sstevel@tonic-gate 		 * If the rinfostr is not returning data, we will use
3990Sstevel@tonic-gate 		 * the standard ap_err_fmts[] for the rcm error.
4000Sstevel@tonic-gate 		 */
4010Sstevel@tonic-gate 		if (rinfostr != NULL)
4020Sstevel@tonic-gate 			(void) snprintf(p, len, "%s", rinfostr);
4030Sstevel@tonic-gate 		else
4040Sstevel@tonic-gate 			(void) snprintf(p, len, fmt, cmd, target);
4050Sstevel@tonic-gate 		break;
4060Sstevel@tonic-gate 	case ERR_LIB_OPEN:
4070Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, path, sep, error);
4080Sstevel@tonic-gate 		break;
4090Sstevel@tonic-gate 	case ERR_LIB_SYM:
4100Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, sym, path);
4110Sstevel@tonic-gate 		break;
4120Sstevel@tonic-gate 	case ERR_STAT:
4130Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, path, syserr);
4140Sstevel@tonic-gate 		break;
4150Sstevel@tonic-gate 	case ERR_NOMEM:
4160Sstevel@tonic-gate 		(void) snprintf(p, len, fmt);
4170Sstevel@tonic-gate 		break;
4180Sstevel@tonic-gate 	case ERR_PLUGIN:
4190Sstevel@tonic-gate 		(void) snprintf(p, len, fmt, a->class, msg);
4200Sstevel@tonic-gate 		break;
4210Sstevel@tonic-gate 	default:
4220Sstevel@tonic-gate 		break;
4230Sstevel@tonic-gate 	}
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate 	if (serr)
4260Sstevel@tonic-gate 		free(serr);
4270Sstevel@tonic-gate 	if (srsrc)
4280Sstevel@tonic-gate 		free(srsrc);
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate /*
4320Sstevel@tonic-gate  * ap_msg() accepts a variable number of message IDs and constructs
4330Sstevel@tonic-gate  * a corresponding message string which is printed via the message print
4340Sstevel@tonic-gate  * routine argument.  ap_msg() internationalizes the appropriate portion
4350Sstevel@tonic-gate  * of the message.
4360Sstevel@tonic-gate  */
4370Sstevel@tonic-gate void
ap_msg(apd_t * a,...)4380Sstevel@tonic-gate ap_msg(apd_t *a, ...)
4390Sstevel@tonic-gate {
4400Sstevel@tonic-gate 	int v;
4410Sstevel@tonic-gate 	int len;
4420Sstevel@tonic-gate 	char *p;
4430Sstevel@tonic-gate 	const char *fmt;
4440Sstevel@tonic-gate 	char *cmd;
4450Sstevel@tonic-gate 	char *target;
4460Sstevel@tonic-gate 	struct cfga_msg *msgp;
4470Sstevel@tonic-gate 	va_list ap;
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 	DBG("ap_msg(%p)\n", (void *)a);
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate 	if (a == NULL || ap_getopt(a, OPT_VERBOSE) == 0)
4520Sstevel@tonic-gate 		return;
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 	msgp = a->msgp;
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate 	if (msgp == NULL || msgp->message_routine == NULL)
4570Sstevel@tonic-gate 		return;
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate 	va_start(ap, a);
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate 	v = va_arg(ap, int);
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate 	if ((fmt = ap_msg_fmt(v)) == NULL)
4640Sstevel@tonic-gate 		fmt = STR_MSG_UNKNOWN;
4650Sstevel@tonic-gate 	fmt = dgettext(TEXT_DOMAIN, fmt);
4660Sstevel@tonic-gate 	len = strlen(fmt) + 128;	/* slop */
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	DBG("<%d>", v);
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate 	switch (v) {
4710Sstevel@tonic-gate 	case MSG_ISSUE:
4720Sstevel@tonic-gate 	case MSG_SKIP:
4730Sstevel@tonic-gate 	case MSG_ABORT:
4740Sstevel@tonic-gate 	case MSG_FAIL:
4750Sstevel@tonic-gate 	case MSG_DONE:
4760Sstevel@tonic-gate 		get_cmd(cmd, ap, v);
4770Sstevel@tonic-gate 		get_tgt(target, ap);
4780Sstevel@tonic-gate 		DBG("<%s><%s>\n", cmd, target);
4790Sstevel@tonic-gate 		len += strlen(cmd) + strlen(target);
4800Sstevel@tonic-gate 		break;
4810Sstevel@tonic-gate 	default:
4820Sstevel@tonic-gate 		break;
4830Sstevel@tonic-gate 	}
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 	va_end(ap);
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate 	if ((p = (char *)calloc(len, 1)) == NULL)
4880Sstevel@tonic-gate 		return;
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate 	(void) snprintf(p, len, fmt, cmd, target);
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	(*msgp->message_routine)(msgp->appdata_ptr, p);
4930Sstevel@tonic-gate 	free(p);
4940Sstevel@tonic-gate }
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate int
ap_confirm(apd_t * a)4970Sstevel@tonic-gate ap_confirm(apd_t *a)
4980Sstevel@tonic-gate {
4990Sstevel@tonic-gate 	int rc;
5000Sstevel@tonic-gate 	char *msg;
5010Sstevel@tonic-gate 	struct cfga_confirm *confp;
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate 	if (a == NULL)
5040Sstevel@tonic-gate 		return (0);
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate 	confp = a->confp;
5070Sstevel@tonic-gate 
5080Sstevel@tonic-gate 	if (confp == NULL || confp->confirm == NULL)
5090Sstevel@tonic-gate 		return (0);
5100Sstevel@tonic-gate 
5110Sstevel@tonic-gate 	msg = dgettext(TEXT_DOMAIN, ap_msg_fmt(MSG_SUSPEND));
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 	rc = (*confp->confirm)(confp->appdata_ptr, msg);
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate 	return (rc);
5160Sstevel@tonic-gate }
517