11e3b90b0SYuri Pankov.\" 21e3b90b0SYuri Pankov.\" The contents of this file are subject to the terms of the 31e3b90b0SYuri Pankov.\" Common Development and Distribution License (the "License"). 41e3b90b0SYuri Pankov.\" You may not use this file except in compliance with the License. 51e3b90b0SYuri Pankov.\" 61e3b90b0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 71e3b90b0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing. 81e3b90b0SYuri Pankov.\" See the License for the specific language governing permissions 91e3b90b0SYuri Pankov.\" and limitations under the License. 101e3b90b0SYuri Pankov.\" 111e3b90b0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each 121e3b90b0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 131e3b90b0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the 141e3b90b0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying 151e3b90b0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner] 161e3b90b0SYuri Pankov.\" 171e3b90b0SYuri Pankov.\" 18c10c16deSRichard Lowe.\" Copyright 1989 AT&T 191e3b90b0SYuri Pankov.\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved. 201e3b90b0SYuri Pankov.\" Copyright 2016 Nexenta Systems, Inc. 211e3b90b0SYuri Pankov.\" 221e3b90b0SYuri Pankov.Dd Dec 1, 2016 231e3b90b0SYuri Pankov.Dt CMN_ERR 9F 241e3b90b0SYuri Pankov.Os 251e3b90b0SYuri Pankov.Sh NAME 261e3b90b0SYuri Pankov.Nm cmn_err, dev_err, vcmn_err, zcmn_err, vzcmn_err 271e3b90b0SYuri Pankov.Nd display an error message or panic the system 281e3b90b0SYuri Pankov.Sh SYNOPSIS 291e3b90b0SYuri Pankov.In sys/cmn_err.h 301e3b90b0SYuri Pankov.In sys/ddi.h 311e3b90b0SYuri Pankov.In sys/sunddi.h 321e3b90b0SYuri Pankov.Ft void 331e3b90b0SYuri Pankov.Fo cmn_err 341e3b90b0SYuri Pankov.Fa "int level" 351e3b90b0SYuri Pankov.Fa "char *format" 361e3b90b0SYuri Pankov.Fa ... 371e3b90b0SYuri Pankov.Fc 381e3b90b0SYuri Pankov.Ft void 391e3b90b0SYuri Pankov.Fo dev_err 401e3b90b0SYuri Pankov.Fa "dev_info_t *dip" 411e3b90b0SYuri Pankov.Fa "int level" 421e3b90b0SYuri Pankov.Fa "char *format" 431e3b90b0SYuri Pankov.Fa ... 441e3b90b0SYuri Pankov.Fc 451e3b90b0SYuri Pankov.In sys/varargs.h 461e3b90b0SYuri Pankov.Ft void 471e3b90b0SYuri Pankov.Fo vcmn_err 481e3b90b0SYuri Pankov.Fa "int level" 491e3b90b0SYuri Pankov.Fa "char *format" 501e3b90b0SYuri Pankov.Fa "va_list ap" 511e3b90b0SYuri Pankov.Fc 521e3b90b0SYuri Pankov.In sys/types.h 531e3b90b0SYuri Pankov.Ft void 541e3b90b0SYuri Pankov.Fo zcmn_err 551e3b90b0SYuri Pankov.Fa "zoneid_t zoneid" 561e3b90b0SYuri Pankov.Fa "int level" 571e3b90b0SYuri Pankov.Fa "char *format" 581e3b90b0SYuri Pankov.Fa ... 591e3b90b0SYuri Pankov.Fc 601e3b90b0SYuri Pankov.Ft void 611e3b90b0SYuri Pankov.Fo vzcmn_err 621e3b90b0SYuri Pankov.Fa "zoneid_t zoneid" 631e3b90b0SYuri Pankov.Fa "int level" 641e3b90b0SYuri Pankov.Fa "char *format" 651e3b90b0SYuri Pankov.Fa "va_list ap" 661e3b90b0SYuri Pankov.Fc 671e3b90b0SYuri Pankov.Sh INTERFACE LEVEL 68c10c16deSRichard LoweArchitecture independent level 1 (DDI/DKI). 691e3b90b0SYuri Pankov.Sh PARAMETERS 701e3b90b0SYuri Pankov.Ss Fn cmn_err 711e3b90b0SYuri Pankov.Bl -tag -width Ds 721e3b90b0SYuri Pankov.It Fa level 73c10c16deSRichard LoweA constant indicating the severity of the error condition. 741e3b90b0SYuri Pankov.It Fa format 75c10c16deSRichard LoweMessage to be displayed. 761e3b90b0SYuri Pankov.El 771e3b90b0SYuri Pankov.Ss Fn dev_err 781e3b90b0SYuri PankovThe 791e3b90b0SYuri Pankov.Fn dev_err 801e3b90b0SYuri Pankovfunction works exactly like 811e3b90b0SYuri Pankov.Fn cmn_err , 821e3b90b0SYuri Pankovbut includes an additional argument: 831e3b90b0SYuri Pankov.Bl -tag -width Ds 841e3b90b0SYuri Pankov.It Fa dip 851e3b90b0SYuri PankovA pointer to the device's 861e3b90b0SYuri Pankov.Ft dev_info 871e3b90b0SYuri Pankovstructure. 881e3b90b0SYuri Pankov.El 891e3b90b0SYuri Pankov.Ss Fn vcmn_err 901e3b90b0SYuri PankovThe 911e3b90b0SYuri Pankov.Fn vcmn_err 921e3b90b0SYuri Pankovfunction takes 931e3b90b0SYuri Pankov.Fa level 941e3b90b0SYuri Pankovand 951e3b90b0SYuri Pankov.Fa format 961e3b90b0SYuri Pankovas described for 971e3b90b0SYuri Pankov.Fn cmn_err , 981e3b90b0SYuri Pankovbut its third argument is different: 991e3b90b0SYuri Pankov.Bl -tag -width Ds 1001e3b90b0SYuri Pankov.It Fa ap 101c10c16deSRichard LoweVariable argument list passed to the function. 1021e3b90b0SYuri Pankov.El 1031e3b90b0SYuri Pankov.Ss Fn zcmn_err 1041e3b90b0SYuri PankovThe 1051e3b90b0SYuri Pankov.Fn zcmn_err 1061e3b90b0SYuri Pankovfunction works exactly like 1071e3b90b0SYuri Pankov.Fn cmn_err , 1081e3b90b0SYuri Pankovbut includes an additional argument: 1091e3b90b0SYuri Pankov.Bl -tag -width Ds 1101e3b90b0SYuri Pankov.It Fa zoneid 1111e3b90b0SYuri PankovZone to which log messages should be directed. 1121e3b90b0SYuri PankovSee 113*bbf21555SRichard Lowe.Xr zones 7 . 1141e3b90b0SYuri Pankov.El 1151e3b90b0SYuri Pankov.Ss Fn vzcmn_err 1161e3b90b0SYuri PankovThe 1171e3b90b0SYuri Pankov.Fn vzcmn_err 1181e3b90b0SYuri Pankovfunction works exactly like 1191e3b90b0SYuri Pankov.Fn vcmn_err , 1201e3b90b0SYuri Pankovbut includes an additional argument: 1211e3b90b0SYuri Pankov.Bl -tag -width Ds 1221e3b90b0SYuri Pankov.It Fa zoneid 1231e3b90b0SYuri PankovZone to which log messages should be directed. 1241e3b90b0SYuri PankovSee 125*bbf21555SRichard Lowe.Xr zones 7 . 1261e3b90b0SYuri Pankov.El 1271e3b90b0SYuri Pankov.Sh DESCRIPTION 1281e3b90b0SYuri Pankov.Ss Fn cmn_err 1291e3b90b0SYuri PankovThe 1301e3b90b0SYuri Pankov.Fn cmn_err 1311e3b90b0SYuri Pankovfunction displays a specified message on the console. 1321e3b90b0SYuri Pankov.Fn cmn_err 1331e3b90b0SYuri Pankovcan also panic the system. 1341e3b90b0SYuri PankovWhen the system panics, it attempts to save recent changes to data, display a 1351e3b90b0SYuri Pankov.Qq panic message 1361e3b90b0SYuri Pankovon the console, attempt to write a core file, and halt system processing. 1371e3b90b0SYuri PankovSee the 1381e3b90b0SYuri Pankov.Sy CE_PANIC 1391e3b90b0SYuri Pankov.Fa level 1401e3b90b0SYuri Pankovbelow. 1411e3b90b0SYuri Pankov.Pp 1421e3b90b0SYuri Pankov.Fa level 1431e3b90b0SYuri Pankovis a constant indicating the severity of the error condition. 1441e3b90b0SYuri PankovThe four severity levels are: 1451e3b90b0SYuri Pankov.Bl -tag -width "CE_PANIC" 1461e3b90b0SYuri Pankov.It Sy CE_CONT 147c10c16deSRichard LoweUsed to continue another message or to display an informative message not 1481e3b90b0SYuri Pankovassociated with an error. 1491e3b90b0SYuri PankovNote that multiple 1501e3b90b0SYuri Pankov.Sy CE_CONT 1511e3b90b0SYuri Pankovmessages without a newline may or may not appear on the system console or in the 1521e3b90b0SYuri Pankovsystem log as a single line message. 1531e3b90b0SYuri PankovA single line message may be produced by constructing the message with 1541e3b90b0SYuri Pankov.Xr sprintf 9F 1551e3b90b0SYuri Pankovor 1561e3b90b0SYuri Pankov.Xr vsprintf 9F 1571e3b90b0SYuri Pankovbefore calling 1581e3b90b0SYuri Pankov.Fn cmn_err . 1591e3b90b0SYuri Pankov.It Sy CE_NOTE 1601e3b90b0SYuri PankovUsed to display a message preceded with 1611e3b90b0SYuri Pankov.Sy NOTICE . 1621e3b90b0SYuri PankovThis message is used to report system events that do not necessarily require 1631e3b90b0SYuri Pankovuser action, but may interest the system administrator. 1641e3b90b0SYuri PankovFor example, a message saying that a sector on a disk needs to be accessed 1651e3b90b0SYuri Pankovrepeatedly before it can be accessed correctly might be noteworthy. 1661e3b90b0SYuri Pankov.It Sy CE_WARN 1671e3b90b0SYuri PankovUsed to display a message preceded with 1681e3b90b0SYuri Pankov.Sy WARNING . 1691e3b90b0SYuri PankovThis message is used to report system events that require immediate attention, 1701e3b90b0SYuri Pankovsuch as those where if an action is not taken, the system may panic. 1711e3b90b0SYuri PankovFor example, when a peripheral device does not initialize correctly, this level 1721e3b90b0SYuri Pankovshould be used. 1731e3b90b0SYuri Pankov.It Sy CE_PANIC 1741e3b90b0SYuri PankovUsed to display a message preceded with 1751e3b90b0SYuri Pankov.Qq Sy panic , 1761e3b90b0SYuri Pankovand to panic the system. 177c10c16deSRichard LoweDrivers should specify this level only under the most severe conditions or when 1781e3b90b0SYuri Pankovdebugging a driver. 1791e3b90b0SYuri PankovA valid use of this level is when the system cannot continue to function. 1801e3b90b0SYuri PankovIf the error is recoverable, or not essential to continued system operation, do 1811e3b90b0SYuri Pankovnot panic the system. 1821e3b90b0SYuri Pankov.El 1831e3b90b0SYuri Pankov.Pp 1841e3b90b0SYuri PankovThe 1851e3b90b0SYuri Pankov.Fa format 1861e3b90b0SYuri Pankovis identical to the one described in 1871e3b90b0SYuri Pankov.Xr sprintf 9F 1881e3b90b0SYuri Pankovwith additional meaning of the first character affecting where the message will 1891e3b90b0SYuri Pankovbe written: 1901e3b90b0SYuri Pankov.Bl -tag -width Ds 1911f2dca32SMichal Nowak.It \&! 192c10c16deSRichard LoweThe message goes only to the system log. 1931e3b90b0SYuri Pankov.It Sy ^ 194c10c16deSRichard LoweThe message goes only to the console. 1951f2dca32SMichal Nowak.It \&? 1961e3b90b0SYuri PankovIf 1971e3b90b0SYuri Pankov.Fa level 1981e3b90b0SYuri Pankovis also 1991e3b90b0SYuri Pankov.Sy CE_CONT , 2001e3b90b0SYuri Pankovthe message is always sent to the system log, but is only written to the console 2011e3b90b0SYuri Pankovwhen the system has been booted in verbose mode. 2021e3b90b0SYuri PankovSee 203*bbf21555SRichard Lowe.Xr kernel 8 . 2041e3b90b0SYuri PankovIf neither condition is met, the 2051f2dca32SMichal Nowak.Qq Sy \&? 206c10c16deSRichard Lowecharacter has no effect and is simply ignored. 2071e3b90b0SYuri Pankov.El 2081e3b90b0SYuri Pankov.Pp 2091e3b90b0SYuri PankovRefer to 210*bbf21555SRichard Lowe.Xr syslogd 8 2111e3b90b0SYuri Pankovto determine where the system log is written. 2121e3b90b0SYuri Pankov.Pp 2131e3b90b0SYuri PankovThe 2141e3b90b0SYuri Pankov.Fn cmn_err 2151e3b90b0SYuri Pankovfunction sends log messages to the log of the global zone. 2161e3b90b0SYuri Pankov.Fn cmn_err 2171e3b90b0SYuri Pankovappends a 2181e3b90b0SYuri Pankov.Sy \en 2191e3b90b0SYuri Pankovto each 2201e3b90b0SYuri Pankov.Fa format , 2211e3b90b0SYuri Pankovexcept when 2221e3b90b0SYuri Pankov.Fa level 2231e3b90b0SYuri Pankovis 2241e3b90b0SYuri Pankov.Sy CE_CONT . 2251e3b90b0SYuri Pankov.Ss Fn dev_err 2261e3b90b0SYuri PankovWith the exception of its first argument 2271e3b90b0SYuri Pankov.Pq Fa dip , 2281e3b90b0SYuri Pankov.Fn dev_err 2291e3b90b0SYuri Pankovis identical to 2301e3b90b0SYuri Pankov.Fn cmn_err . 2311e3b90b0SYuri Pankov.Fa dip 2321e3b90b0SYuri Pankovis a pointer to a device's 2331e3b90b0SYuri Pankov.Ft dev_info 2341e3b90b0SYuri Pankovstructure, which is used to prepend the driver name and instance number to the 2351e3b90b0SYuri Pankovmessage. 2361e3b90b0SYuri PankovThe driver name and instance number are retrieved using 2371e3b90b0SYuri Pankov.Xr ddi_driver_name 9F 2381e3b90b0SYuri Pankovand 2391e3b90b0SYuri Pankov.Xr ddi_get_instance 9F . 2401e3b90b0SYuri Pankov.Ss Fn vcmn_err 2411e3b90b0SYuri PankovThe 2421e3b90b0SYuri Pankov.Fn vcmn_err 2431e3b90b0SYuri Pankovfunction is identical to 2441e3b90b0SYuri Pankov.Fn cmn_err 2451e3b90b0SYuri Pankovexcept that its last argument, 2461e3b90b0SYuri Pankov.Fa ap , 2471e3b90b0SYuri Pankovis a pointer to a variable list of arguments. 2481e3b90b0SYuri Pankov.Fa ap 249c10c16deSRichard Lowecontains the list of arguments used by the conversion specifications in 2501e3b90b0SYuri Pankov.Fa format . 2511e3b90b0SYuri Pankov.Fa ap 2521e3b90b0SYuri Pankovmust be initialized by calling 2531e3b90b0SYuri Pankov.Xr va_start 9F . 2541e3b90b0SYuri Pankov.Xr va_end 9F 2551e3b90b0SYuri Pankovis used to clean up and must be called after each traversal of the list. 2561e3b90b0SYuri PankovMultiple traversals of the argument list, each bracketed by 2571e3b90b0SYuri Pankov.Xr va_start 9F 2581e3b90b0SYuri Pankovand 2591e3b90b0SYuri Pankov.Xr va_end 9F , 2601e3b90b0SYuri Pankovare possible. 2611e3b90b0SYuri Pankov.Ss Fn zcmn_err 2621e3b90b0SYuri PankovWith the exception of its first argument 2631e3b90b0SYuri Pankov.Pq Fa zoneid , 2641e3b90b0SYuri Pankov.Fn zcmn_err 2651e3b90b0SYuri Pankovis identical to 2661e3b90b0SYuri Pankov.Fn cmn_err . 2671e3b90b0SYuri Pankov.Fa zoneid 2681e3b90b0SYuri Pankovis the numeric ID of the zone to which the message should be directed. 2691e3b90b0SYuri PankovNote that 2701e3b90b0SYuri Pankov.Fa zoneid 2711e3b90b0SYuri Pankovonly has an effect if the message is sent to the system log. 2721e3b90b0SYuri PankovUsing 2731e3b90b0SYuri Pankov.Fa zoneid 2741e3b90b0SYuri Pankovwill cause messages to be sent to the log associated with the specified local 2751e3b90b0SYuri Pankovzone rather than the log in the global zone. 2761e3b90b0SYuri PankovThis is accomplished by the message being received and processed by the 277*bbf21555SRichard Lowe.Xr syslogd 8 2781e3b90b0SYuri Pankovprocess running in the specified zone instead of the one running in the global 2791e3b90b0SYuri Pankovzone. 2801e3b90b0SYuri PankovYou can retrieve a process zone ID from its credential structure using 2811e3b90b0SYuri Pankov.Xr crgetzoneid 9F . 2821e3b90b0SYuri Pankov.Ss Fn vzcmn_err 2831e3b90b0SYuri PankovWith the exception of its first argument 2841e3b90b0SYuri Pankov.Pq Fa zoneid , 2851e3b90b0SYuri Pankov.Fn vzcmn_err 2861e3b90b0SYuri Pankovis identical to 2871e3b90b0SYuri Pankov.Fn vcmn_err . 2881e3b90b0SYuri PankovSee the description of 2891e3b90b0SYuri Pankov.Fn zcmn_err 2901e3b90b0SYuri Pankovabove for an explanation on how the 2911e3b90b0SYuri Pankov.Fa zoneid 2921e3b90b0SYuri Pankovargument is handled. 2931e3b90b0SYuri Pankov.Sh CONTEXT 2941e3b90b0SYuri PankovThe 2951e3b90b0SYuri Pankov.Fn cmn_err 2961e3b90b0SYuri Pankovfunction can be called from user, kernel, interrupt, or high-level interrupt 2971e3b90b0SYuri Pankovcontext. 2981e3b90b0SYuri Pankov.Sh RETURN VALUES 29972d3dbb9SYuri PankovNone. 30072d3dbb9SYuri PankovHowever, if an unknown 3011e3b90b0SYuri Pankov.Fa level 3021e3b90b0SYuri Pankovis passed to 3031e3b90b0SYuri Pankov.Fn cmn_err , 3041e3b90b0SYuri Pankovthe following panic error message is displayed: 3051e3b90b0SYuri Pankov.Bd -literal 3061e3b90b0SYuri Pankovpanic: unknown level in cmn_err (level=level, msg=format) 3071e3b90b0SYuri Pankov.Ed 3081e3b90b0SYuri Pankov.Sh EXAMPLES 3091e3b90b0SYuri Pankov.Bl -tag -width Ds 3101e3b90b0SYuri Pankov.It Sy Example 1 No Using Fn cmn_err 3111e3b90b0SYuri PankovThis first example shows how 3121e3b90b0SYuri Pankov.Fn cmn_err 3131e3b90b0SYuri Pankovcan record tracing and debugging information only in the system log 3141e3b90b0SYuri Pankov.Pq lines 17 ; 3151e3b90b0SYuri Pankovdisplay problems with a device only on the system console 3161e3b90b0SYuri Pankov.Pq line 23 ; 3171e3b90b0SYuri Pankovor display problems with the device on both the system console and in the system 3181e3b90b0SYuri Pankovlog 3191e3b90b0SYuri Pankov.Pq line 28 . 3201e3b90b0SYuri Pankov.Bd -literal 321ed22c710SYuri Pankov1 struct reg { 322ed22c710SYuri Pankov2 uchar_t data; 323ed22c710SYuri Pankov3 uchar_t csr; 324ed22c710SYuri Pankov4 }; 325ed22c710SYuri Pankov5 326ed22c710SYuri Pankov6 struct xxstate { 3271e3b90b0SYuri Pankov7 ... 328ed22c710SYuri Pankov8 dev_info_t *dip; 329ed22c710SYuri Pankov9 struct reg *regp; 3301e3b90b0SYuri Pankov10 ... 331ed22c710SYuri Pankov11 }; 332ed22c710SYuri Pankov12 333ed22c710SYuri Pankov13 dev_t dev; 334ed22c710SYuri Pankov14 struct xxstate *xsp; 3351e3b90b0SYuri Pankov15 ... 336ed22c710SYuri Pankov16 #ifdef DEBUG /* in debugging mode, log function call */ 337ed22c710SYuri Pankov17 cmn_err(CE_CONT, "!%s%d: xxopen function called.", 338ed22c710SYuri Pankov18 ddi_binding_name(xsp->dip), getminor(dev)); 339ed22c710SYuri Pankov19 #endif /* end DEBUG */ 3401e3b90b0SYuri Pankov20 ... 341ed22c710SYuri Pankov21 /* display device power failure on system console */ 342ed22c710SYuri Pankov22 if ((xsp->regp->csr & POWER) == OFF) 343ed22c710SYuri Pankov23 cmn_err(CE_NOTE, "^OFF.", 344ed22c710SYuri Pankov24 ddi_binding_name(xsp->dip), getminor(dev)); 3451e3b90b0SYuri Pankov25 ... 346ed22c710SYuri Pankov26 /* display warning if device has bad VTOC */ 347ed22c710SYuri Pankov27 if (xsp->regp->csr & BADVTOC) 348ed22c710SYuri Pankov28 cmn_err(CE_WARN, "%s%d: xxopen: Bad VTOC.", 349c10c16deSRichard Lowe29 ddi_binding_name(xsp->dip), getminor(dev)); 3501e3b90b0SYuri Pankov.Ed 3511e3b90b0SYuri Pankov.It Sy Example 2 No Using the %b conversion specification 3521e3b90b0SYuri PankovThis example shows how to use the 3531e3b90b0SYuri Pankov.Sy %b 3541e3b90b0SYuri Pankovconversion specification. 3551e3b90b0SYuri PankovBecause of the leading 3561f2dca32SMichal Nowak.Qq Sy \&? 3571e3b90b0SYuri Pankovcharacter in the format string, this message will always be logged, but it will 3581e3b90b0SYuri Pankovonly be displayed when the kernel is booted in verbose mode. 3591e3b90b0SYuri Pankov.Bd -literal 360c10c16deSRichard Lowecmn_err(CE_CONT, "?reg=0x%b\en", regval, "\e020\e3Intr\e2Err\e1Enable"); 3611e3b90b0SYuri Pankov.Ed 3621e3b90b0SYuri Pankov.It Sy Example 3 No Using Fa regval 3631e3b90b0SYuri PankovWhen 3641e3b90b0SYuri Pankov.Fa regval 3651e3b90b0SYuri Pankovis set to 3661e3b90b0SYuri Pankov.Pq decimal 3671e3b90b0SYuri Pankov13, the following message would be displayed: 3681e3b90b0SYuri Pankov.Bd -literal 369c10c16deSRichard Lowereg=0xd<Intr,,Enable> 3701e3b90b0SYuri Pankov.Ed 3711e3b90b0SYuri Pankov.It Sy Example 4 No Error Routine 372c10c16deSRichard LoweThis example shows an error reporting routine which accepts a variable number 373c10c16deSRichard Loweof arguments and displays a single line error message both in the system log 3741e3b90b0SYuri Pankovand on the system console. 3751e3b90b0SYuri PankovNote the use of 3761e3b90b0SYuri Pankov.Fn vsprintf 3771e3b90b0SYuri Pankovto construct the error message before calling 3781e3b90b0SYuri Pankov.Fn cmn_err . 3791e3b90b0SYuri Pankov.Bd -literal 380c10c16deSRichard Lowe#include <sys/varargs.h> 381c10c16deSRichard Lowe#include <sys/ddi.h> 382c10c16deSRichard Lowe#include <sys/sunddi.h> 383ed22c710SYuri Pankov#define MAX_MSG 256; 384c10c16deSRichard Lowe 385ed22c710SYuri Pankovvoid 3861e3b90b0SYuri Pankovxxerror(dev_info_t *dip, int level, const char *fmt, ...) 387ed22c710SYuri Pankov{ 388c10c16deSRichard Lowe va_list ap; 389c10c16deSRichard Lowe int instance; 390c10c16deSRichard Lowe char buf[MAX_MSG], *name; 391c10c16deSRichard Lowe 392c10c16deSRichard Loweinstance = ddi_get_instance(dip); 393c10c16deSRichard Lowename = ddi_binding_name(dip); 394c10c16deSRichard Lowe 395c10c16deSRichard Lowe/* format buf using fmt and arguments contained in ap */ 396c10c16deSRichard Lowe 397c10c16deSRichard Loweva_start(ap, fmt); 398c10c16deSRichard Lowevsprintf(buf, fmt, ap); 399c10c16deSRichard Loweva_end(ap); 400c10c16deSRichard Lowe 401c10c16deSRichard Lowe/* pass formatted string to cmn_err(9F) */ 402c10c16deSRichard Lowe 403ed22c710SYuri Pankovcmn_err(level, "%s%d: %s", name, instance, buf); 404c10c16deSRichard Lowe 405c10c16deSRichard Lowe} 4061e3b90b0SYuri Pankov.Ed 4071e3b90b0SYuri Pankov.It Sy Example 5 No Log to Current Zone 408c10c16deSRichard LoweThis example shows how messages can be sent to the log of the zone in which a 4091e3b90b0SYuri Pankovthread is currently running, when applicable. 4101e3b90b0SYuri PankovNote that most hardware-related messages should instead be sent to the global 4111e3b90b0SYuri Pankovzone using 4121e3b90b0SYuri Pankov.Fn cmn_err . 4131e3b90b0SYuri Pankov.Bd -literal 414ca9a201cSHans Rosenfeldzcmn_err(crgetzoneid(ddi_get_cred()), CE_NOTE, "out of processes"); 4151e3b90b0SYuri Pankov.Ed 4161e3b90b0SYuri Pankov.El 4171e3b90b0SYuri Pankov.Sh SEE ALSO 418*bbf21555SRichard Lowe.Xr zones 7 , 419*bbf21555SRichard Lowe.Xr dmesg 8 , 420*bbf21555SRichard Lowe.Xr kernel 8 , 4211e3b90b0SYuri Pankov.Xr ddi_binding_name 9F , 4221e3b90b0SYuri Pankov.Xr ddi_cred 9F , 4231e3b90b0SYuri Pankov.Xr ddi_driver_name 9F , 4241e3b90b0SYuri Pankov.Xr ddi_get_instance 9F , 4251e3b90b0SYuri Pankov.Xr sprintf 9F , 4261e3b90b0SYuri Pankov.Xr va_arg 9F , 4271e3b90b0SYuri Pankov.Xr va_end 9F , 4281e3b90b0SYuri Pankov.Xr va_start 9F 4291e3b90b0SYuri Pankov.Pp 4301e3b90b0SYuri PankovWriting Device Drivers 4311e3b90b0SYuri Pankov.Sh WARNINGS 4321e3b90b0SYuri PankovThe 4331e3b90b0SYuri Pankov.Fn cmn_err 4341e3b90b0SYuri Pankovfunction with the 4351e3b90b0SYuri Pankov.Sy CE_CONT 4361e3b90b0SYuri Pankovargument can be used by driver developers as a driver code debugging tool. 4371e3b90b0SYuri PankovHowever, using 4381e3b90b0SYuri Pankov.Fn cmn_err 4391e3b90b0SYuri Pankovin this capacity can change system timing characteristics. 4401e3b90b0SYuri Pankov.Sh NOTES 4411e3b90b0SYuri PankovMessages of arbitrary length can be generated using 4421e3b90b0SYuri Pankov.Fn cmn_err , 4431e3b90b0SYuri Pankovbut if the call to 4441e3b90b0SYuri Pankov.Fn cmn_err 4451e3b90b0SYuri Pankovis made from high-level interrupt context and insufficient memory is available 4461e3b90b0SYuri Pankovto create a buffer of the specified size, the message will be truncated to 4471e3b90b0SYuri PankovLOG_MSGSIZE 4481e3b90b0SYuri Pankovbytes 4491e3b90b0SYuri Pankov.Pq see Pa sys/log.h . 4501e3b90b0SYuri PankovFor this reason, callers of 4511e3b90b0SYuri Pankov.Fn cmn_err 4521e3b90b0SYuri Pankovthat require complete and accurate message generation should post down from 4531e3b90b0SYuri Pankovhigh-level interrupt context before calling 4541e3b90b0SYuri Pankov.Fn cmn_err . 455