xref: /illumos-gate/usr/src/cmd/mdb/common/kmdb/kctl/kctl_err.c (revision 2654012f83cec5dc15b61dfe3e4a4915f186e7a6)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/cmn_err.h>
31 #include <sys/varargs.h>
32 #include <sys/bootconf.h>
33 #include <sys/sysmacros.h>
34 #include <sys/kmdb.h>
35 
36 /*
37  * The boot printing interfaces don't expose anything that'll allow us
38  * to print multiple arguments at once.  That is, they expose printf-like
39  * interfaces, but these interfaces only support one format specifier per
40  * invocation.  The routines in this file allow the rest of the driver
41  * to pretend that this limitation doesn't exist.
42  */
43 
44 #include <kmdb/kctl/kctl.h>
45 
46 static void
47 kctl_vprintf(int code, const char *format, va_list ap)
48 {
49 	if (kctl.kctl_boot_ops == NULL) {
50 		vcmn_err(code, format, ap);
51 
52 	} else {
53 		char buf[128];
54 
55 		if (code == CE_WARN)
56 			BOP_PUTSARG(kctl.kctl_boot_ops, "WARNING: ", NULL);
57 		else if (code == CE_NOTE)
58 			BOP_PUTSARG(kctl.kctl_boot_ops, "NOTE: ", NULL);
59 
60 		(void) vsnprintf(buf, sizeof (buf), format, ap);
61 		BOP_PUTSARG(kctl.kctl_boot_ops, "%s\n", buf);
62 	}
63 }
64 
65 void
66 kctl_warn(const char *format, ...)
67 {
68 	va_list ap;
69 
70 	va_start(ap, format);
71 	kctl_vprintf(CE_WARN, format, ap);
72 	va_end(ap);
73 }
74 
75 void
76 kctl_dprintf(const char *format, ...)
77 {
78 	va_list ap;
79 
80 	if (!(kctl.kctl_flags & KMDB_F_DRV_DEBUG))
81 		return;
82 
83 	va_start(ap, format);
84 	kctl_vprintf(CE_NOTE, format, ap);
85 	va_end(ap);
86 }
87