2 .\" The contents of this file are subject to the terms of the
3 .\" Common Development and Distribution License (the "License").
4 .\" You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7 .\" or http://www.opensolaris.org/os/licensing.
8 .\" See the License for the specific language governing permissions
9 .\" and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each
12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13 .\" If applicable, add the following below this CDDL HEADER, with the
14 .\" fields enclosed by brackets "[]" replaced with your own identifying
15 .\" information: Portions Copyright [yyyy] [name of copyright owner]
18 .\" Copyright 1989 AT&T
19 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
20 .\" Copyright 2016 Nexenta Systems, Inc.
26 .Nm cmn_err, dev_err, vcmn_err, zcmn_err, vzcmn_err
27 .Nd display an error message or panic the system
68 Architecture independent level 1 (DDI/DKI).
73 A constant indicating the severity of the error condition.
75 Message to be displayed.
80 function works exactly like
82 but includes an additional argument:
85 A pointer to the device's
98 but its third argument is different:
101 Variable argument list passed to the function.
106 function works exactly like
108 but includes an additional argument:
111 Zone to which log messages should be directed.
118 function works exactly like
120 but includes an additional argument:
123 Zone to which log messages should be directed.
131 function displays a specified message on the console.
133 can also panic the system.
134 When the system panics, it attempts to save recent changes to data, display a
136 on the console, attempt to write a core file, and halt system processing.
143 is a constant indicating the severity of the error condition.
144 The four severity levels are:
145 .Bl -tag -width "CE_PANIC"
147 Used to continue another message or to display an informative message not
148 associated with an error.
151 messages without a newline may or may not appear on the system console or in the
152 system log as a single line message.
153 A single line message may be produced by constructing the message with
160 Used to display a message preceded with
162 This message is used to report system events that do not necessarily require
163 user action, but may interest the system administrator.
164 For example, a message saying that a sector on a disk needs to be accessed
165 repeatedly before it can be accessed correctly might be noteworthy.
167 Used to display a message preceded with
169 This message is used to report system events that require immediate attention,
170 such as those where if an action is not taken, the system may panic.
171 For example, when a peripheral device does not initialize correctly, this level
174 Used to display a message preceded with
176 and to panic the system.
177 Drivers should specify this level only under the most severe conditions or when
179 A valid use of this level is when the system cannot continue to function.
180 If the error is recoverable, or not essential to continued system operation, do
181 not panic the system.
186 is identical to the one described in
188 with additional meaning of the first character affecting where the message will
192 The message goes only to the system log.
194 The message goes only to the console.
200 the message is always sent to the system log, but is only written to the console
201 when the system has been booted in verbose mode.
204 If neither condition is met, the
206 character has no effect and is simply ignored.
211 to determine where the system log is written.
215 function sends log messages to the log of the global zone.
226 With the exception of its first argument
232 is a pointer to a device's
234 structure, which is used to prepend the driver name and instance number to the
236 The driver name and instance number are retrieved using
237 .Xr ddi_driver_name 9F
239 .Xr ddi_get_instance 9F .
243 function is identical to
245 except that its last argument,
247 is a pointer to a variable list of arguments.
249 contains the list of arguments used by the conversion specifications in
252 must be initialized by calling
255 is used to clean up and must be called after each traversal of the list.
256 Multiple traversals of the argument list, each bracketed by
262 With the exception of its first argument
268 is the numeric ID of the zone to which the message should be directed.
271 only has an effect if the message is sent to the system log.
274 will cause messages to be sent to the log associated with the specified local
275 zone rather than the log in the global zone.
276 This is accomplished by the message being received and processed by the
278 process running in the specified zone instead of the one running in the global
280 You can retrieve a process zone ID from its credential structure using
283 With the exception of its first argument
288 See the description of
290 above for an explanation on how the
296 function can be called from user, kernel, interrupt, or high-level interrupt
300 However, if an unknown
304 the following panic error message is displayed:
306 panic: unknown level in cmn_err (level=level, msg=format)
310 .It Sy Example 1 No Using Fn cmn_err
311 This first example shows how
313 can record tracing and debugging information only in the system log
315 display problems with a device only on the system console
317 or display problems with the device on both the system console and in the system
334 14 struct xxstate *xsp;
336 16 #ifdef DEBUG /* in debugging mode, log function call */
337 17 cmn_err(CE_CONT, "!%s%d: xxopen function called.",
338 18 ddi_binding_name(xsp->dip), getminor(dev));
339 19 #endif /* end DEBUG */
341 21 /* display device power failure on system console */
342 22 if ((xsp->regp->csr & POWER) == OFF)
343 23 cmn_err(CE_NOTE, "^OFF.",
344 24 ddi_binding_name(xsp->dip), getminor(dev));
346 26 /* display warning if device has bad VTOC */
347 27 if (xsp->regp->csr & BADVTOC)
348 28 cmn_err(CE_WARN, "%s%d: xxopen: Bad VTOC.",
349 29 ddi_binding_name(xsp->dip), getminor(dev));
351 .It Sy Example 2 No Using the %b conversion specification
352 This example shows how to use the
354 conversion specification.
355 Because of the leading
357 character in the format string, this message will always be logged, but it will
358 only be displayed when the kernel is booted in verbose mode.
360 cmn_err(CE_CONT, "?reg=0x%b\en", regval, "\e020\e3Intr\e2Err\e1Enable");
362 .It Sy Example 3 No Using Fa regval
367 13, the following message would be displayed:
369 reg=0xd<Intr,,Enable>
371 .It Sy Example 4 No Error Routine
372 This example shows an error reporting routine which accepts a variable number
373 of arguments and displays a single line error message both in the system log
374 and on the system console.
377 to construct the error message before calling
380 #include <sys/varargs.h>
382 #include <sys/sunddi.h>
386 xxerror(dev_info_t *dip, int level, const char *fmt, ...)
390 char buf[MAX_MSG], *name;
392 instance = ddi_get_instance(dip);
393 name = ddi_binding_name(dip);
395 /* format buf using fmt and arguments contained in ap */
398 vsprintf(buf, fmt, ap);
401 /* pass formatted string to cmn_err(9F) */
403 cmn_err(level, "%s%d: %s", name, instance, buf);
407 .It Sy Example 5 No Log to Current Zone
408 This example shows how messages can be sent to the log of the zone in which a
409 thread is currently running, when applicable.
410 Note that most hardware-related messages should instead be sent to the global
414 zcmn_err(crgetzoneid(ddi_get_cred()), CE_NOTE, "out of processes");
421 .Xr ddi_binding_name 9F ,
423 .Xr ddi_driver_name 9F ,
424 .Xr ddi_get_instance 9F ,
430 Writing Device Drivers
436 argument can be used by driver developers as a driver code debugging tool.
439 in this capacity can change system timing characteristics.
441 Messages of arbitrary length can be generated using
445 is made from high-level interrupt context and insufficient memory is available
446 to create a buffer of the specified size, the message will be truncated to
449 .Pq see Pa sys/log.h .
450 For this reason, callers of
452 that require complete and accurate message generation should post down from
453 high-level interrupt context before calling