1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3 * This file and its contents are supplied under the terms of the
4 * Common Development and Distribution License ("CDDL"), version 1.0.
5 * You may only use this file in accordance with the terms of version
6 * 1.0 of the CDDL.
7 *
8 * A full copy of the text of the CDDL should have accompanied this
9 * source. A copy of the CDDL is also available via the Internet at
10 * https://opensource.org/license/CDDL-1.0.
11 *
12 * $FreeBSD$
13 */
14 /*
15 * Copyright 2007 John Birrell <jb@FreeBSD.org>. All rights reserved.
16 * Copyright 2012 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
17 */
18
19 #include <sys/cdefs.h>
20 #include <sys/param.h>
21 #include <sys/systm.h>
22 #include <sys/cmn_err.h>
23
24 void
vcmn_err(int ce,const char * fmt,va_list adx)25 vcmn_err(int ce, const char *fmt, va_list adx)
26 {
27 char buf[256];
28 const char *prefix;
29
30 prefix = NULL; /* silence unwitty compilers */
31 switch (ce) {
32 case CE_CONT:
33 prefix = "zfs(cont): ";
34 break;
35 case CE_NOTE:
36 prefix = "zfs: NOTICE: ";
37 break;
38 case CE_WARN:
39 prefix = "zfs: WARNING: ";
40 break;
41 case CE_PANIC:
42 prefix = "zfs(panic): ";
43 break;
44 case CE_IGNORE:
45 break;
46 default:
47 panic("zfs: unknown severity level");
48 }
49 if (ce == CE_PANIC) {
50 vsnprintf(buf, sizeof (buf), fmt, adx);
51 panic("%s%s", prefix, buf);
52 }
53 if (ce != CE_IGNORE) {
54 printf("%s", prefix);
55 vprintf(fmt, adx);
56 printf("\n");
57 }
58 }
59
60 void
cmn_err(int type,const char * fmt,...)61 cmn_err(int type, const char *fmt, ...)
62 {
63 va_list ap;
64
65 va_start(ap, fmt);
66 vcmn_err(type, fmt, ap);
67 va_end(ap);
68 }
69