xref: /freebsd-src/sys/contrib/openzfs/module/os/freebsd/spl/spl_cmn_err.c (revision 271171e0d97b88ba2a7c3bf750c9672b484c1c13)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  *
21eda14cbcSMatt Macy  * $FreeBSD$
22eda14cbcSMatt Macy  */
23eda14cbcSMatt Macy /*
24eda14cbcSMatt Macy  * Copyright 2007 John Birrell <jb@FreeBSD.org>. All rights reserved.
25eda14cbcSMatt Macy  * Copyright 2012 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
26eda14cbcSMatt Macy  */
27eda14cbcSMatt Macy 
28eda14cbcSMatt Macy #include <sys/cdefs.h>
29eda14cbcSMatt Macy #include <sys/param.h>
30eda14cbcSMatt Macy #include <sys/systm.h>
31eda14cbcSMatt Macy #include <sys/cmn_err.h>
32eda14cbcSMatt Macy 
33eda14cbcSMatt Macy void
vcmn_err(int ce,const char * fmt,va_list adx)34eda14cbcSMatt Macy vcmn_err(int ce, const char *fmt, va_list adx)
35eda14cbcSMatt Macy {
36eda14cbcSMatt Macy 	char buf[256];
37eda14cbcSMatt Macy 	const char *prefix;
38eda14cbcSMatt Macy 
39eda14cbcSMatt Macy 	prefix = NULL; /* silence unwitty compilers */
40eda14cbcSMatt Macy 	switch (ce) {
41eda14cbcSMatt Macy 	case CE_CONT:
42eda14cbcSMatt Macy 		prefix = "Solaris(cont): ";
43eda14cbcSMatt Macy 		break;
44eda14cbcSMatt Macy 	case CE_NOTE:
45eda14cbcSMatt Macy 		prefix = "Solaris: NOTICE: ";
46eda14cbcSMatt Macy 		break;
47eda14cbcSMatt Macy 	case CE_WARN:
48eda14cbcSMatt Macy 		prefix = "Solaris: WARNING: ";
49eda14cbcSMatt Macy 		break;
50eda14cbcSMatt Macy 	case CE_PANIC:
51eda14cbcSMatt Macy 		prefix = "Solaris(panic): ";
52eda14cbcSMatt Macy 		break;
53eda14cbcSMatt Macy 	case CE_IGNORE:
54eda14cbcSMatt Macy 		break;
55eda14cbcSMatt Macy 	default:
56eda14cbcSMatt Macy 		panic("Solaris: unknown severity level");
57eda14cbcSMatt Macy 	}
58eda14cbcSMatt Macy 	if (ce == CE_PANIC) {
59eda14cbcSMatt Macy 		vsnprintf(buf, sizeof (buf), fmt, adx);
60eda14cbcSMatt Macy 		panic("%s%s", prefix, buf);
61eda14cbcSMatt Macy 	}
62eda14cbcSMatt Macy 	if (ce != CE_IGNORE) {
63eda14cbcSMatt Macy 		printf("%s", prefix);
64eda14cbcSMatt Macy 		vprintf(fmt, adx);
65eda14cbcSMatt Macy 		printf("\n");
66eda14cbcSMatt Macy 	}
67eda14cbcSMatt Macy }
68eda14cbcSMatt Macy 
69eda14cbcSMatt Macy void
cmn_err(int type,const char * fmt,...)70eda14cbcSMatt Macy cmn_err(int type, const char *fmt, ...)
71eda14cbcSMatt Macy {
72eda14cbcSMatt Macy 	va_list ap;
73eda14cbcSMatt Macy 
74eda14cbcSMatt Macy 	va_start(ap, fmt);
75eda14cbcSMatt Macy 	vcmn_err(type, fmt, ap);
76eda14cbcSMatt Macy 	va_end(ap);
77eda14cbcSMatt Macy }
78