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.
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.
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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* unix system includes */
35 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <instzones_api.h>
44 * consolidation pkg command library includes
50 * local pkg command library includes
58 /* Should be defined by cc -D */
59 #if !defined(TEXT_DOMAIN)
60 #define TEXT_DOMAIN "SYS_TEST"
63 /* local static data */
65 static boolean_t verbose
= B_FALSE
;
69 * Description: Outputs messages to logging facility.
71 * Arguments: a_type - the severity of the message
72 * a_format - the printf format, plus its arguments
78 log_msg(LogMsgType a_type
, const char *a_format
, ...)
81 char *rstr
= (char *)NULL
;
86 char *p
= get_prog_name();
88 /* process message based on type */
92 default: /* treat unknown type as LOG_MSG_ERR */
94 prefix
= MSG_LOG_ERROR
;
96 case LOG_MSG_WRN
: /* warning message */
98 prefix
= MSG_LOG_WARNING
;
100 case LOG_MSG_INFO
: /* information message */
104 case LOG_MSG_DEBUG
: /* debugging message */
105 if (!log_get_verbose()) {
106 /* no debug messages if not verbose mode */
113 /* output debug prefix to match echoDebug() format */
115 (void) fprintf(stderr
, "# [%6d %3d", getpid(), getzoneid());
117 if ((p
!= (char *)NULL
) && (*p
!= '\0')) {
118 fprintf(stderr
, " %-11s", p
);
121 (void) fprintf(stderr
, "] ");
125 /* output prefix if specified */
127 if (prefix
!= NULL
) {
128 (void) fprintf(out
, "%s: ", prefix
);
131 /* determine size of the message in bytes */
133 va_start(ap
, a_format
);
134 vres
= vsnprintf(bfr
, 1, a_format
, ap
);
137 /* allocate storage to hold the message */
139 rstr
= (char *)malloc(vres
+2);
141 /* generate the results of the printf conversion */
143 va_start(ap
, a_format
);
144 vres
= vsnprintf(rstr
, vres
+1, a_format
, ap
);
147 /* output formatted message to appropriate destination */
149 if (fprintf(out
, "%s\n", rstr
) < 0) {
152 * nothing output, try stderr as a
155 (void) fprintf(stderr
, ERR_LOG_FAIL
, a_format
);
159 /* free temporary message storage */
166 * Description: Turns on verbose output
168 * Arguments: verbose = B_TRUE indicates verbose mode
173 log_set_verbose(boolean_t setting
)
180 * Description: Returns whether or not to output verbose messages
183 * Returns: B_TRUE - verbose messages should be output