logsubr.c revision cf904b458260fa01e28bbe096ba36e34b959956f
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License, Version 1.0 only 2N/A * (the "License"). You may not use this file except in compliance 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" #
define LOG_PRISIZE 8 /* max priority size: 7 characters + null */#
define LOG_FACSIZE 9 /* max priority size: 8 characters + null */ "emerg",
"alert",
"crit",
"error",
"warning",
"notice",
"info",
"debug" "kern",
"user",
"mail",
"daemon",
"auth",
"syslog",
"lpr",
"news",
"uucp",
"resv9",
"resv10",
"resv11",
"resv12",
"audit",
"resv14",
"cron",
"local0",
"local1",
"local2",
"local3",
"local4",
"local5",
"local6",
"local7",
* Get exclusive access to the logging system; this includes all minor * devices. We use an rwlock rather than a mutex because hold times * are potentially long, so we don't want to waste cycles in adaptive mutex * spin (rwlocks always block when contended). Note that we explicitly * support recursive calls (e.g. printf() calls foo() calls printf()). * Clients may use log_enter() / log_exit() to guarantee that a group * of messages is treated atomically (i.e. they appear in order and are * not interspersed with any other messages), e.g. for multiline printf(). * This could probably be changed to a per-zone lock if contention becomes /* lp will be NULL if the queue was created via log_makeq */ * Create a minimal queue with just enough fields filled in to support * canput(9F), putq(9F), and getq_noenab(9F). We set QNOENB to ensure * that the queue will never be enabled. * Initialize the log structure for a new zone. * Create a backlog queue to consume console messages during periods * when there is no console reader (e.g. before syslogd(1M) starts). * Create a queue to hold free message of size <= LOG_MSGSIZE. * Calls from high-level interrupt handlers will do a getq_noenab() * from this queue, so its q_lock must be a maximum SPL spin lock. * Create a queue for messages from high-level interrupt context. * These messages are drained via softcall, or explicitly by panic(). * Create a queue to hold the most recent 8K of console messages. * Useful for debugging. Required by the "$<msgbuf" adb macro. * Create an id space for clone devices opened via /dev/log. * Need to limit the number of zones to avoid exceeding the * available minor number space. * Put ourselves on the ZSD list. Note that zones have not been * initialized yet, but our constructor will be called on the global * Initialize backlog structure. /* Allocate integer space for conslog's minor numbers */ /* Allocate kmem cache for conslog's log structures */ * Now that logging is enabled, emit the SunOS banner. printf(
"\rSunOS Release %s Version %s %u-bit\n",
printf(
"Copyright 1983-2005 Sun Microsystems, Inc. " "All rights reserved.\nUse is subject to license terms.\n");
* Allocate a log device corresponding to supplied device type. * Both devices are clonable. /dev/log devices are allocated per zone. * /dev/conslog devices are allocated from kmem cache, with minor numbers * supplied from a vmem arena. * No point allocating log_t until there's a free minor number. /* search for an available /dev/log device for the zone */ /* Return minor number to the pool */ /* Return log to the cache */ * Move console messages from src to dst. The time of day isn't known * early in boot, so fix up the message timestamps if necessary. * In the early boot phase hrestime is invalid. * hrestime becomes valid when clock() runs for the first time. * At this time is lbolt == 1. log_sendmsg() saves the lbolt * Look ahead to first early boot message with time. * Calculate hrestime for an early log message with * an invalid time stamp. We know: * - the lbolt of the invalid time stamp. * - the hrestime and lbolt of the first valid * Set the fields in the 'target' clone to the specified values. * Then, look at all clones to determine which message types are * currently active and which clone is the primary console queue. * If the primary console queue changes to or from the backlog * queue, copy all messages from backlog to primary or vice versa. * Need to special case the global zone here since this may be * called before zone_init. return;
/* zone is being destroyed, ignore update */ * We use `tid + 1 <= tidend' here rather than the more traditional * `tid < tidend', since the former ensures that there's at least * `sizeof (trace_ids_t)' bytes available before executing the * loop, whereas the latter only ensures that there's a single byte. * Need to special case the global zone here since this may be * called before zone_init. /* specified zone doesn't exist, free message and return */ * Raise the console queue's q_hiwat to ensure that we * capture all panic messages. /* Message was created while panicking. */ body =
facility +
23;
/* strlen("FACILITY_AND_PRIORITY] ") */ * If this is in the global zone, start with the backlog, then * walk through the clone logs. If not, just do the clone logs. * Do the backlog this time, then start on the src +=
body -
2;
/* copy "] " too */ " -- is syslogd(1M) running?");
* Print queued messages to console. * Look ahead to first queued message in the stream. * Check if message is already displayed at /* Strip off the message ID. */ * Using console_printf instead of printf to avoid * queueing messages to log_consq.