17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*068ccd7aSns92644 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/param.h> 317c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 327c478bd9Sstevel@tonic-gate #include <sys/systm.h> 337c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 347c478bd9Sstevel@tonic-gate #include <sys/stream.h> 357c478bd9Sstevel@tonic-gate #include <sys/strsubr.h> 367c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 377c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 387c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 397c478bd9Sstevel@tonic-gate #include <sys/log.h> 407c478bd9Sstevel@tonic-gate #include <sys/spl.h> 417c478bd9Sstevel@tonic-gate #include <sys/syslog.h> 427c478bd9Sstevel@tonic-gate #include <sys/console.h> 437c478bd9Sstevel@tonic-gate #include <sys/debug.h> 447c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 457c478bd9Sstevel@tonic-gate #include <sys/id_space.h> 467c478bd9Sstevel@tonic-gate #include <sys/zone.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate log_zone_t log_global; 497c478bd9Sstevel@tonic-gate queue_t *log_consq; 507c478bd9Sstevel@tonic-gate queue_t *log_backlogq; 517c478bd9Sstevel@tonic-gate queue_t *log_intrq; 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #define LOG_PRISIZE 8 /* max priority size: 7 characters + null */ 547c478bd9Sstevel@tonic-gate #define LOG_FACSIZE 9 /* max priority size: 8 characters + null */ 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate static krwlock_t log_rwlock; 577c478bd9Sstevel@tonic-gate static int log_rwlock_depth; 587c478bd9Sstevel@tonic-gate static int log_seq_no[SL_CONSOLE + 1]; 597c478bd9Sstevel@tonic-gate static stdata_t log_fakestr; 607c478bd9Sstevel@tonic-gate static id_space_t *log_minorspace; 617c478bd9Sstevel@tonic-gate static log_t log_backlog; 62*068ccd7aSns92644 static struct kmem_cache *log_cons_cache; /* log_t cache */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate static queue_t *log_recentq; 657c478bd9Sstevel@tonic-gate static queue_t *log_freeq; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate static zone_key_t log_zone_key; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate static char log_overflow_msg[] = "message overflow on /dev/log minor #%d%s\n"; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate static char log_pri[LOG_PRIMASK + 1][LOG_PRISIZE] = { 727c478bd9Sstevel@tonic-gate "emerg", "alert", "crit", "error", 737c478bd9Sstevel@tonic-gate "warning", "notice", "info", "debug" 747c478bd9Sstevel@tonic-gate }; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate static char log_fac[LOG_NFACILITIES + 1][LOG_FACSIZE] = { 777c478bd9Sstevel@tonic-gate "kern", "user", "mail", "daemon", 787c478bd9Sstevel@tonic-gate "auth", "syslog", "lpr", "news", 797c478bd9Sstevel@tonic-gate "uucp", "resv9", "resv10", "resv11", 807c478bd9Sstevel@tonic-gate "resv12", "audit", "resv14", "cron", 817c478bd9Sstevel@tonic-gate "local0", "local1", "local2", "local3", 827c478bd9Sstevel@tonic-gate "local4", "local5", "local6", "local7", 837c478bd9Sstevel@tonic-gate "unknown" 847c478bd9Sstevel@tonic-gate }; 85*068ccd7aSns92644 static int log_cons_constructor(void *, void *, int); 86*068ccd7aSns92644 static void log_cons_destructor(void *, void *); 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * Get exclusive access to the logging system; this includes all minor 907c478bd9Sstevel@tonic-gate * devices. We use an rwlock rather than a mutex because hold times 917c478bd9Sstevel@tonic-gate * are potentially long, so we don't want to waste cycles in adaptive mutex 927c478bd9Sstevel@tonic-gate * spin (rwlocks always block when contended). Note that we explicitly 937c478bd9Sstevel@tonic-gate * support recursive calls (e.g. printf() calls foo() calls printf()). 947c478bd9Sstevel@tonic-gate * 957c478bd9Sstevel@tonic-gate * Clients may use log_enter() / log_exit() to guarantee that a group 967c478bd9Sstevel@tonic-gate * of messages is treated atomically (i.e. they appear in order and are 977c478bd9Sstevel@tonic-gate * not interspersed with any other messages), e.g. for multiline printf(). 987c478bd9Sstevel@tonic-gate * 997c478bd9Sstevel@tonic-gate * This could probably be changed to a per-zone lock if contention becomes 1007c478bd9Sstevel@tonic-gate * an issue. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate void 1037c478bd9Sstevel@tonic-gate log_enter(void) 1047c478bd9Sstevel@tonic-gate { 1057c478bd9Sstevel@tonic-gate if (rw_owner(&log_rwlock) != curthread) 1067c478bd9Sstevel@tonic-gate rw_enter(&log_rwlock, RW_WRITER); 1077c478bd9Sstevel@tonic-gate log_rwlock_depth++; 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate void 1117c478bd9Sstevel@tonic-gate log_exit(void) 1127c478bd9Sstevel@tonic-gate { 1137c478bd9Sstevel@tonic-gate if (--log_rwlock_depth == 0) 1147c478bd9Sstevel@tonic-gate rw_exit(&log_rwlock); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate void 1187c478bd9Sstevel@tonic-gate log_flushq(queue_t *q) 1197c478bd9Sstevel@tonic-gate { 1207c478bd9Sstevel@tonic-gate mblk_t *mp; 1217c478bd9Sstevel@tonic-gate log_t *lp = (log_t *)q->q_ptr; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* lp will be NULL if the queue was created via log_makeq */ 1247c478bd9Sstevel@tonic-gate while ((mp = getq_noenab(q)) != NULL) 1257c478bd9Sstevel@tonic-gate log_sendmsg(mp, lp == NULL ? GLOBAL_ZONEID : lp->log_zoneid); 1267c478bd9Sstevel@tonic-gate } 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * Create a minimal queue with just enough fields filled in to support 1307c478bd9Sstevel@tonic-gate * canput(9F), putq(9F), and getq_noenab(9F). We set QNOENB to ensure 1317c478bd9Sstevel@tonic-gate * that the queue will never be enabled. 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate static queue_t * 1347c478bd9Sstevel@tonic-gate log_makeq(size_t lowat, size_t hiwat, void *ibc) 1357c478bd9Sstevel@tonic-gate { 1367c478bd9Sstevel@tonic-gate queue_t *q; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate q = kmem_zalloc(sizeof (queue_t), KM_SLEEP); 1397c478bd9Sstevel@tonic-gate q->q_stream = &log_fakestr; 1407c478bd9Sstevel@tonic-gate q->q_flag = QISDRV | QMTSAFE | QNOENB | QREADR | QUSE; 1417c478bd9Sstevel@tonic-gate q->q_nfsrv = q; 1427c478bd9Sstevel@tonic-gate q->q_lowat = lowat; 1437c478bd9Sstevel@tonic-gate q->q_hiwat = hiwat; 1447c478bd9Sstevel@tonic-gate mutex_init(QLOCK(q), NULL, MUTEX_DRIVER, ibc); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate return (q); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * Initialize the log structure for a new zone. 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate static void * 1537c478bd9Sstevel@tonic-gate log_zoneinit(zoneid_t zoneid) 1547c478bd9Sstevel@tonic-gate { 1557c478bd9Sstevel@tonic-gate int i; 1567c478bd9Sstevel@tonic-gate log_zone_t *lzp; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate if (zoneid == GLOBAL_ZONEID) 1597c478bd9Sstevel@tonic-gate lzp = &log_global; /* use statically allocated struct */ 1607c478bd9Sstevel@tonic-gate else 1617c478bd9Sstevel@tonic-gate lzp = kmem_zalloc(sizeof (log_zone_t), KM_SLEEP); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate for (i = 0; i < LOG_NUMCLONES; i++) { 1647c478bd9Sstevel@tonic-gate lzp->lz_clones[i].log_minor = 1657c478bd9Sstevel@tonic-gate (minor_t)id_alloc(log_minorspace); 1667c478bd9Sstevel@tonic-gate lzp->lz_clones[i].log_zoneid = zoneid; 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate return (lzp); 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1727c478bd9Sstevel@tonic-gate static void 1737c478bd9Sstevel@tonic-gate log_zonefree(zoneid_t zoneid, void *arg) 1747c478bd9Sstevel@tonic-gate { 1757c478bd9Sstevel@tonic-gate log_zone_t *lzp = arg; 1767c478bd9Sstevel@tonic-gate int i; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate ASSERT(lzp != &log_global && zoneid != GLOBAL_ZONEID); 1797c478bd9Sstevel@tonic-gate if (lzp == NULL) 1807c478bd9Sstevel@tonic-gate return; 1817c478bd9Sstevel@tonic-gate for (i = 0; i < LOG_NUMCLONES; i++) 1827c478bd9Sstevel@tonic-gate id_free(log_minorspace, lzp->lz_clones[i].log_minor); 1837c478bd9Sstevel@tonic-gate kmem_free(lzp, sizeof (log_zone_t)); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate void 1877c478bd9Sstevel@tonic-gate log_init(void) 1887c478bd9Sstevel@tonic-gate { 1897c478bd9Sstevel@tonic-gate int log_maxzones; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Create a backlog queue to consume console messages during periods 1937c478bd9Sstevel@tonic-gate * when there is no console reader (e.g. before syslogd(1M) starts). 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate log_backlogq = log_consq = log_makeq(0, LOG_HIWAT, NULL); 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate /* 1987c478bd9Sstevel@tonic-gate * Create a queue to hold free message of size <= LOG_MSGSIZE. 1997c478bd9Sstevel@tonic-gate * Calls from high-level interrupt handlers will do a getq_noenab() 2007c478bd9Sstevel@tonic-gate * from this queue, so its q_lock must be a maximum SPL spin lock. 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate log_freeq = log_makeq(LOG_MINFREE, LOG_MAXFREE, (void *)ipltospl(SPL8)); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* 2057c478bd9Sstevel@tonic-gate * Create a queue for messages from high-level interrupt context. 2067c478bd9Sstevel@tonic-gate * These messages are drained via softcall, or explicitly by panic(). 2077c478bd9Sstevel@tonic-gate */ 2087c478bd9Sstevel@tonic-gate log_intrq = log_makeq(0, LOG_HIWAT, (void *)ipltospl(SPL8)); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * Create a queue to hold the most recent 8K of console messages. 2127c478bd9Sstevel@tonic-gate * Useful for debugging. Required by the "$<msgbuf" adb macro. 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate log_recentq = log_makeq(0, LOG_RECENTSIZE, NULL); 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate /* 2177c478bd9Sstevel@tonic-gate * Create an id space for clone devices opened via /dev/log. 2187c478bd9Sstevel@tonic-gate * Need to limit the number of zones to avoid exceeding the 2197c478bd9Sstevel@tonic-gate * available minor number space. 2207c478bd9Sstevel@tonic-gate */ 2217c478bd9Sstevel@tonic-gate log_maxzones = (L_MAXMIN32 - LOG_LOGMIN) / LOG_NUMCLONES - 1; 2227c478bd9Sstevel@tonic-gate if (log_maxzones < maxzones) 2237c478bd9Sstevel@tonic-gate maxzones = log_maxzones; 2247c478bd9Sstevel@tonic-gate log_minorspace = id_space_create("logminor_space", LOG_LOGMIN + 1, 2257c478bd9Sstevel@tonic-gate L_MAXMIN32); 2267c478bd9Sstevel@tonic-gate /* 2277c478bd9Sstevel@tonic-gate * Put ourselves on the ZSD list. Note that zones have not been 2287c478bd9Sstevel@tonic-gate * initialized yet, but our constructor will be called on the global 2297c478bd9Sstevel@tonic-gate * zone when they are. 2307c478bd9Sstevel@tonic-gate */ 2317c478bd9Sstevel@tonic-gate zone_key_create(&log_zone_key, log_zoneinit, NULL, log_zonefree); 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate /* 2347c478bd9Sstevel@tonic-gate * Initialize backlog structure. 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate log_backlog.log_zoneid = GLOBAL_ZONEID; 2377c478bd9Sstevel@tonic-gate log_backlog.log_minor = LOG_BACKLOG; 2387c478bd9Sstevel@tonic-gate 239*068ccd7aSns92644 /* Allocate kmem cache for conslog's log structures */ 240*068ccd7aSns92644 log_cons_cache = kmem_cache_create("log_cons_cache", 241*068ccd7aSns92644 sizeof (struct log), 0, log_cons_constructor, log_cons_destructor, 242*068ccd7aSns92644 NULL, NULL, NULL, 0); 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate /* 2457c478bd9Sstevel@tonic-gate * Let the logging begin. 2467c478bd9Sstevel@tonic-gate */ 2477c478bd9Sstevel@tonic-gate log_update(&log_backlog, log_backlogq, SL_CONSOLE, log_console); 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * Now that logging is enabled, emit the SunOS banner. 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate printf("\rSunOS Release %s Version %s %u-bit\n", 2537c478bd9Sstevel@tonic-gate utsname.release, utsname.version, NBBY * (uint_t)sizeof (void *)); 2547c478bd9Sstevel@tonic-gate printf("Copyright 1983-2005 Sun Microsystems, Inc. " 2557c478bd9Sstevel@tonic-gate "All rights reserved.\nUse is subject to license terms.\n"); 2567c478bd9Sstevel@tonic-gate #ifdef DEBUG 2577c478bd9Sstevel@tonic-gate printf("DEBUG enabled\n"); 2587c478bd9Sstevel@tonic-gate #endif 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* 262*068ccd7aSns92644 * Allocate a log device corresponding to supplied device type. 263*068ccd7aSns92644 * Both devices are clonable. /dev/log devices are allocated per zone. 264*068ccd7aSns92644 * /dev/conslog devices are allocated from kmem cache. 2657c478bd9Sstevel@tonic-gate */ 2667c478bd9Sstevel@tonic-gate log_t * 2677c478bd9Sstevel@tonic-gate log_alloc(minor_t type) 2687c478bd9Sstevel@tonic-gate { 2697c478bd9Sstevel@tonic-gate zone_t *zptr = curproc->p_zone; 2707c478bd9Sstevel@tonic-gate log_zone_t *lzp; 2717c478bd9Sstevel@tonic-gate log_t *lp; 2727c478bd9Sstevel@tonic-gate int i; 273*068ccd7aSns92644 minor_t minor; 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate if (type == LOG_CONSMIN) { 2767c478bd9Sstevel@tonic-gate 277*068ccd7aSns92644 /* 278*068ccd7aSns92644 * Return a write-only /dev/conslog device. 279*068ccd7aSns92644 * No point allocating log_t until there's a free minor number. 280*068ccd7aSns92644 */ 281*068ccd7aSns92644 minor = (minor_t)id_alloc(log_minorspace); 282*068ccd7aSns92644 lp = kmem_cache_alloc(log_cons_cache, KM_SLEEP); 283*068ccd7aSns92644 lp->log_minor = minor; 284*068ccd7aSns92644 return (lp); 285*068ccd7aSns92644 } else { 2867c478bd9Sstevel@tonic-gate ASSERT(type == LOG_LOGMIN); 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate lzp = zone_getspecific(log_zone_key, zptr); 2897c478bd9Sstevel@tonic-gate ASSERT(lzp != NULL); 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate /* search for an available /dev/log device for the zone */ 2927c478bd9Sstevel@tonic-gate for (i = LOG_LOGMINIDX; i <= LOG_LOGMAXIDX; i++) { 2937c478bd9Sstevel@tonic-gate lp = &lzp->lz_clones[i]; 2947c478bd9Sstevel@tonic-gate if (lp->log_inuse == 0) 2957c478bd9Sstevel@tonic-gate break; 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate if (i > LOG_LOGMAXIDX) 2987c478bd9Sstevel@tonic-gate lp = NULL; 299*068ccd7aSns92644 else 300*068ccd7aSns92644 /* Indicate which device type */ 301*068ccd7aSns92644 lp->log_major = LOG_LOGMIN; 3027c478bd9Sstevel@tonic-gate return (lp); 3037c478bd9Sstevel@tonic-gate } 304*068ccd7aSns92644 } 305*068ccd7aSns92644 306*068ccd7aSns92644 void 307*068ccd7aSns92644 log_free(log_t *lp) 308*068ccd7aSns92644 { 309*068ccd7aSns92644 id_free(log_minorspace, lp->log_minor); 310*068ccd7aSns92644 kmem_cache_free(log_cons_cache, lp); 311*068ccd7aSns92644 } 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate /* 3147c478bd9Sstevel@tonic-gate * Move console messages from src to dst. The time of day isn't known 3157c478bd9Sstevel@tonic-gate * early in boot, so fix up the message timestamps if necessary. 3167c478bd9Sstevel@tonic-gate */ 3177c478bd9Sstevel@tonic-gate static void 3187c478bd9Sstevel@tonic-gate log_conswitch(log_t *src, log_t *dst) 3197c478bd9Sstevel@tonic-gate { 3207c478bd9Sstevel@tonic-gate mblk_t *mp; 3217c478bd9Sstevel@tonic-gate mblk_t *hmp = NULL; 3227c478bd9Sstevel@tonic-gate mblk_t *tmp = NULL; 3237c478bd9Sstevel@tonic-gate log_ctl_t *hlc; 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate while ((mp = getq_noenab(src->log_q)) != NULL) { 3267c478bd9Sstevel@tonic-gate log_ctl_t *lc = (log_ctl_t *)mp->b_rptr; 3277c478bd9Sstevel@tonic-gate lc->flags |= SL_LOGONLY; 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate /* 3307c478bd9Sstevel@tonic-gate * In the early boot phase hrestime is invalid. 3317c478bd9Sstevel@tonic-gate * hrestime becomes valid when clock() runs for the first time. 3327c478bd9Sstevel@tonic-gate * At this time is lbolt == 1. log_sendmsg() saves the lbolt 3337c478bd9Sstevel@tonic-gate * value in ltime. 3347c478bd9Sstevel@tonic-gate */ 3357c478bd9Sstevel@tonic-gate if (lc->ltime < 2) { 3367c478bd9Sstevel@tonic-gate /* 3377c478bd9Sstevel@tonic-gate * Look ahead to first early boot message with time. 3387c478bd9Sstevel@tonic-gate */ 3397c478bd9Sstevel@tonic-gate if (hmp) { 3407c478bd9Sstevel@tonic-gate tmp->b_next = mp; 3417c478bd9Sstevel@tonic-gate tmp = mp; 3427c478bd9Sstevel@tonic-gate } else 3437c478bd9Sstevel@tonic-gate hmp = tmp = mp; 3447c478bd9Sstevel@tonic-gate continue; 3457c478bd9Sstevel@tonic-gate } 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate while (hmp) { 3487c478bd9Sstevel@tonic-gate tmp = hmp->b_next; 3497c478bd9Sstevel@tonic-gate hmp->b_next = NULL; 3507c478bd9Sstevel@tonic-gate hlc = (log_ctl_t *)hmp->b_rptr; 3517c478bd9Sstevel@tonic-gate /* 3527c478bd9Sstevel@tonic-gate * Calculate hrestime for an early log message with 3537c478bd9Sstevel@tonic-gate * an invalid time stamp. We know: 3547c478bd9Sstevel@tonic-gate * - the lbolt of the invalid time stamp. 3557c478bd9Sstevel@tonic-gate * - the hrestime and lbolt of the first valid 3567c478bd9Sstevel@tonic-gate * time stamp. 3577c478bd9Sstevel@tonic-gate */ 3587c478bd9Sstevel@tonic-gate hlc->ttime = lc->ttime - (lc->ltime - hlc->ltime) / hz; 3597c478bd9Sstevel@tonic-gate (void) putq(dst->log_q, hmp); 3607c478bd9Sstevel@tonic-gate hmp = tmp; 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate (void) putq(dst->log_q, mp); 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate while (hmp) { 3657c478bd9Sstevel@tonic-gate tmp = hmp->b_next; 3667c478bd9Sstevel@tonic-gate hmp->b_next = NULL; 3677c478bd9Sstevel@tonic-gate hlc = (log_ctl_t *)hmp->b_rptr; 3687c478bd9Sstevel@tonic-gate hlc->ttime = gethrestime_sec() - (lbolt - hlc->ltime) / hz; 3697c478bd9Sstevel@tonic-gate (void) putq(dst->log_q, hmp); 3707c478bd9Sstevel@tonic-gate hmp = tmp; 3717c478bd9Sstevel@tonic-gate } 3727c478bd9Sstevel@tonic-gate dst->log_overflow = src->log_overflow; 3737c478bd9Sstevel@tonic-gate src->log_flags = 0; 3747c478bd9Sstevel@tonic-gate dst->log_flags = SL_CONSOLE; 3757c478bd9Sstevel@tonic-gate log_consq = dst->log_q; 3767c478bd9Sstevel@tonic-gate } 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate /* 3797c478bd9Sstevel@tonic-gate * Set the fields in the 'target' clone to the specified values. 3807c478bd9Sstevel@tonic-gate * Then, look at all clones to determine which message types are 3817c478bd9Sstevel@tonic-gate * currently active and which clone is the primary console queue. 3827c478bd9Sstevel@tonic-gate * If the primary console queue changes to or from the backlog 3837c478bd9Sstevel@tonic-gate * queue, copy all messages from backlog to primary or vice versa. 3847c478bd9Sstevel@tonic-gate */ 3857c478bd9Sstevel@tonic-gate void 3867c478bd9Sstevel@tonic-gate log_update(log_t *target, queue_t *q, short flags, log_filter_t *filter) 3877c478bd9Sstevel@tonic-gate { 3887c478bd9Sstevel@tonic-gate log_t *lp; 3897c478bd9Sstevel@tonic-gate short active = SL_CONSOLE; 3907c478bd9Sstevel@tonic-gate zone_t *zptr = NULL; 3917c478bd9Sstevel@tonic-gate log_zone_t *lzp; 3927c478bd9Sstevel@tonic-gate zoneid_t zoneid = target->log_zoneid; 3937c478bd9Sstevel@tonic-gate int i; 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate log_enter(); 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate if (q != NULL) 3987c478bd9Sstevel@tonic-gate target->log_q = q; 3997c478bd9Sstevel@tonic-gate target->log_wanted = filter; 4007c478bd9Sstevel@tonic-gate target->log_flags = flags; 4017c478bd9Sstevel@tonic-gate target->log_overflow = 0; 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate /* 4047c478bd9Sstevel@tonic-gate * Need to special case the global zone here since this may be 4057c478bd9Sstevel@tonic-gate * called before zone_init. 4067c478bd9Sstevel@tonic-gate */ 4077c478bd9Sstevel@tonic-gate if (zoneid == GLOBAL_ZONEID) { 4087c478bd9Sstevel@tonic-gate lzp = &log_global; 4097c478bd9Sstevel@tonic-gate } else if ((zptr = zone_find_by_id(zoneid)) == NULL) { 4107c478bd9Sstevel@tonic-gate log_exit(); 4117c478bd9Sstevel@tonic-gate return; /* zone is being destroyed, ignore update */ 4127c478bd9Sstevel@tonic-gate } else { 4137c478bd9Sstevel@tonic-gate lzp = zone_getspecific(log_zone_key, zptr); 4147c478bd9Sstevel@tonic-gate } 4157c478bd9Sstevel@tonic-gate ASSERT(lzp != NULL); 4167c478bd9Sstevel@tonic-gate for (i = LOG_LOGMAXIDX; i >= LOG_LOGMINIDX; i--) { 4177c478bd9Sstevel@tonic-gate lp = &lzp->lz_clones[i]; 4187c478bd9Sstevel@tonic-gate if (zoneid == GLOBAL_ZONEID && (lp->log_flags & SL_CONSOLE)) 4197c478bd9Sstevel@tonic-gate log_consq = lp->log_q; 4207c478bd9Sstevel@tonic-gate active |= lp->log_flags; 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate lzp->lz_active = active; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate if (zptr) 4257c478bd9Sstevel@tonic-gate zone_rele(zptr); 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate if (log_consq == target->log_q) { 4287c478bd9Sstevel@tonic-gate if (flags & SL_CONSOLE) 4297c478bd9Sstevel@tonic-gate log_conswitch(&log_backlog, target); 4307c478bd9Sstevel@tonic-gate else 4317c478bd9Sstevel@tonic-gate log_conswitch(target, &log_backlog); 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate target->log_q = q; 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate log_exit(); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4397c478bd9Sstevel@tonic-gate int 4407c478bd9Sstevel@tonic-gate log_error(log_t *lp, log_ctl_t *lc) 4417c478bd9Sstevel@tonic-gate { 4427c478bd9Sstevel@tonic-gate if ((lc->pri & LOG_FACMASK) == LOG_KERN) 4437c478bd9Sstevel@tonic-gate lc->pri = LOG_KERN | LOG_ERR; 4447c478bd9Sstevel@tonic-gate return (1); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate int 4487c478bd9Sstevel@tonic-gate log_trace(log_t *lp, log_ctl_t *lc) 4497c478bd9Sstevel@tonic-gate { 4507c478bd9Sstevel@tonic-gate trace_ids_t *tid = (trace_ids_t *)lp->log_data->b_rptr; 4517c478bd9Sstevel@tonic-gate trace_ids_t *tidend = (trace_ids_t *)lp->log_data->b_wptr; 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate /* 4547c478bd9Sstevel@tonic-gate * We use `tid + 1 <= tidend' here rather than the more traditional 4557c478bd9Sstevel@tonic-gate * `tid < tidend', since the former ensures that there's at least 4567c478bd9Sstevel@tonic-gate * `sizeof (trace_ids_t)' bytes available before executing the 4577c478bd9Sstevel@tonic-gate * loop, whereas the latter only ensures that there's a single byte. 4587c478bd9Sstevel@tonic-gate */ 4597c478bd9Sstevel@tonic-gate for (; tid + 1 <= tidend; tid++) { 4607c478bd9Sstevel@tonic-gate if (tid->ti_level < lc->level && tid->ti_level >= 0) 4617c478bd9Sstevel@tonic-gate continue; 4627c478bd9Sstevel@tonic-gate if (tid->ti_mid != lc->mid && tid->ti_mid >= 0) 4637c478bd9Sstevel@tonic-gate continue; 4647c478bd9Sstevel@tonic-gate if (tid->ti_sid != lc->sid && tid->ti_sid >= 0) 4657c478bd9Sstevel@tonic-gate continue; 4667c478bd9Sstevel@tonic-gate if ((lc->pri & LOG_FACMASK) == LOG_KERN) 4677c478bd9Sstevel@tonic-gate lc->pri = LOG_KERN | LOG_DEBUG; 4687c478bd9Sstevel@tonic-gate return (1); 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate return (0); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4747c478bd9Sstevel@tonic-gate int 4757c478bd9Sstevel@tonic-gate log_console(log_t *lp, log_ctl_t *lc) 4767c478bd9Sstevel@tonic-gate { 4777c478bd9Sstevel@tonic-gate if ((lc->pri & LOG_FACMASK) == LOG_KERN) { 4787c478bd9Sstevel@tonic-gate if (lc->flags & SL_FATAL) 4797c478bd9Sstevel@tonic-gate lc->pri = LOG_KERN | LOG_CRIT; 4807c478bd9Sstevel@tonic-gate else if (lc->flags & SL_ERROR) 4817c478bd9Sstevel@tonic-gate lc->pri = LOG_KERN | LOG_ERR; 4827c478bd9Sstevel@tonic-gate else if (lc->flags & SL_WARN) 4837c478bd9Sstevel@tonic-gate lc->pri = LOG_KERN | LOG_WARNING; 4847c478bd9Sstevel@tonic-gate else if (lc->flags & SL_NOTE) 4857c478bd9Sstevel@tonic-gate lc->pri = LOG_KERN | LOG_NOTICE; 4867c478bd9Sstevel@tonic-gate else if (lc->flags & SL_TRACE) 4877c478bd9Sstevel@tonic-gate lc->pri = LOG_KERN | LOG_DEBUG; 4887c478bd9Sstevel@tonic-gate else 4897c478bd9Sstevel@tonic-gate lc->pri = LOG_KERN | LOG_INFO; 4907c478bd9Sstevel@tonic-gate } 4917c478bd9Sstevel@tonic-gate return (1); 4927c478bd9Sstevel@tonic-gate } 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate mblk_t * 4957c478bd9Sstevel@tonic-gate log_makemsg(int mid, int sid, int level, int sl, int pri, void *msg, 4967c478bd9Sstevel@tonic-gate size_t size, int on_intr) 4977c478bd9Sstevel@tonic-gate { 4987c478bd9Sstevel@tonic-gate mblk_t *mp = NULL; 4997c478bd9Sstevel@tonic-gate mblk_t *mp2; 5007c478bd9Sstevel@tonic-gate log_ctl_t *lc; 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate if (size <= LOG_MSGSIZE && 5037c478bd9Sstevel@tonic-gate (on_intr || log_freeq->q_count > log_freeq->q_lowat)) 5047c478bd9Sstevel@tonic-gate mp = getq_noenab(log_freeq); 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate if (mp == NULL) { 5077c478bd9Sstevel@tonic-gate if (on_intr || 5087c478bd9Sstevel@tonic-gate (mp = allocb(sizeof (log_ctl_t), BPRI_HI)) == NULL || 5097c478bd9Sstevel@tonic-gate (mp2 = allocb(MAX(size, LOG_MSGSIZE), BPRI_HI)) == NULL) { 5107c478bd9Sstevel@tonic-gate freemsg(mp); 5117c478bd9Sstevel@tonic-gate return (NULL); 5127c478bd9Sstevel@tonic-gate } 5137c478bd9Sstevel@tonic-gate DB_TYPE(mp) = M_PROTO; 5147c478bd9Sstevel@tonic-gate mp->b_wptr += sizeof (log_ctl_t); 5157c478bd9Sstevel@tonic-gate mp->b_cont = mp2; 5167c478bd9Sstevel@tonic-gate } else { 5177c478bd9Sstevel@tonic-gate mp2 = mp->b_cont; 5187c478bd9Sstevel@tonic-gate mp2->b_wptr = mp2->b_rptr; 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate lc = (log_ctl_t *)mp->b_rptr; 5227c478bd9Sstevel@tonic-gate lc->mid = mid; 5237c478bd9Sstevel@tonic-gate lc->sid = sid; 5247c478bd9Sstevel@tonic-gate lc->level = level; 5257c478bd9Sstevel@tonic-gate lc->flags = sl; 5267c478bd9Sstevel@tonic-gate lc->pri = pri; 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate bcopy(msg, mp2->b_wptr, size - 1); 5297c478bd9Sstevel@tonic-gate mp2->b_wptr[size - 1] = '\0'; 5307c478bd9Sstevel@tonic-gate mp2->b_wptr += strlen((char *)mp2->b_wptr) + 1; 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate return (mp); 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate void 5367c478bd9Sstevel@tonic-gate log_freemsg(mblk_t *mp) 5377c478bd9Sstevel@tonic-gate { 5387c478bd9Sstevel@tonic-gate mblk_t *mp2 = mp->b_cont; 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate ASSERT(MBLKL(mp) == sizeof (log_ctl_t)); 5417c478bd9Sstevel@tonic-gate ASSERT(mp2->b_rptr == mp2->b_datap->db_base); 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate if ((log_freeq->q_flag & QFULL) == 0 && 5447c478bd9Sstevel@tonic-gate MBLKL(mp2) <= LOG_MSGSIZE && MBLKSIZE(mp2) >= LOG_MSGSIZE) 5457c478bd9Sstevel@tonic-gate (void) putq(log_freeq, mp); 5467c478bd9Sstevel@tonic-gate else 5477c478bd9Sstevel@tonic-gate freemsg(mp); 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate void 5517c478bd9Sstevel@tonic-gate log_sendmsg(mblk_t *mp, zoneid_t zoneid) 5527c478bd9Sstevel@tonic-gate { 5537c478bd9Sstevel@tonic-gate log_t *lp; 5547c478bd9Sstevel@tonic-gate char *src, *dst; 5557c478bd9Sstevel@tonic-gate mblk_t *mp2 = mp->b_cont; 5567c478bd9Sstevel@tonic-gate log_ctl_t *lc = (log_ctl_t *)mp->b_rptr; 5577c478bd9Sstevel@tonic-gate int flags, fac; 5587c478bd9Sstevel@tonic-gate off_t facility = 0; 5597c478bd9Sstevel@tonic-gate off_t body = 0; 5607c478bd9Sstevel@tonic-gate zone_t *zptr = NULL; 5617c478bd9Sstevel@tonic-gate log_zone_t *lzp; 5627c478bd9Sstevel@tonic-gate int i; 5637c478bd9Sstevel@tonic-gate int backlog; 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate /* 5667c478bd9Sstevel@tonic-gate * Need to special case the global zone here since this may be 5677c478bd9Sstevel@tonic-gate * called before zone_init. 5687c478bd9Sstevel@tonic-gate */ 5697c478bd9Sstevel@tonic-gate if (zoneid == GLOBAL_ZONEID) { 5707c478bd9Sstevel@tonic-gate lzp = &log_global; 5717c478bd9Sstevel@tonic-gate } else if ((zptr = zone_find_by_id(zoneid)) == NULL) { 5727c478bd9Sstevel@tonic-gate /* specified zone doesn't exist, free message and return */ 5737c478bd9Sstevel@tonic-gate log_freemsg(mp); 5747c478bd9Sstevel@tonic-gate return; 5757c478bd9Sstevel@tonic-gate } else { 5767c478bd9Sstevel@tonic-gate lzp = zone_getspecific(log_zone_key, zptr); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate ASSERT(lzp != NULL); 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate if ((lc->flags & lzp->lz_active) == 0) { 5817c478bd9Sstevel@tonic-gate if (zptr) 5827c478bd9Sstevel@tonic-gate zone_rele(zptr); 5837c478bd9Sstevel@tonic-gate log_freemsg(mp); 5847c478bd9Sstevel@tonic-gate return; 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate if (panicstr) { 5887c478bd9Sstevel@tonic-gate /* 5897c478bd9Sstevel@tonic-gate * Raise the console queue's q_hiwat to ensure that we 5907c478bd9Sstevel@tonic-gate * capture all panic messages. 5917c478bd9Sstevel@tonic-gate */ 5927c478bd9Sstevel@tonic-gate log_consq->q_hiwat = 2 * LOG_HIWAT; 5937c478bd9Sstevel@tonic-gate log_consq->q_flag &= ~QFULL; 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate /* Message was created while panicking. */ 5967c478bd9Sstevel@tonic-gate lc->flags |= SL_PANICMSG; 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate src = (char *)mp2->b_rptr; 6007c478bd9Sstevel@tonic-gate dst = strstr(src, "FACILITY_AND_PRIORITY] "); 6017c478bd9Sstevel@tonic-gate if (dst != NULL) { 6027c478bd9Sstevel@tonic-gate facility = dst - src; 6037c478bd9Sstevel@tonic-gate body = facility + 23; /* strlen("FACILITY_AND_PRIORITY] ") */ 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate log_enter(); 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate lc->ltime = lbolt; 6097c478bd9Sstevel@tonic-gate lc->ttime = gethrestime_sec(); 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate flags = lc->flags & lzp->lz_active; 6127c478bd9Sstevel@tonic-gate log_seq_no[flags & SL_ERROR]++; 6137c478bd9Sstevel@tonic-gate log_seq_no[flags & SL_TRACE]++; 6147c478bd9Sstevel@tonic-gate log_seq_no[flags & SL_CONSOLE]++; 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate /* 6177c478bd9Sstevel@tonic-gate * If this is in the global zone, start with the backlog, then 6187c478bd9Sstevel@tonic-gate * walk through the clone logs. If not, just do the clone logs. 6197c478bd9Sstevel@tonic-gate */ 6207c478bd9Sstevel@tonic-gate backlog = (zoneid == GLOBAL_ZONEID); 6217c478bd9Sstevel@tonic-gate i = LOG_LOGMINIDX; 6227c478bd9Sstevel@tonic-gate while (i <= LOG_LOGMAXIDX) { 6237c478bd9Sstevel@tonic-gate if (backlog) { 6247c478bd9Sstevel@tonic-gate /* 6257c478bd9Sstevel@tonic-gate * Do the backlog this time, then start on the 6267c478bd9Sstevel@tonic-gate * others. 6277c478bd9Sstevel@tonic-gate */ 6287c478bd9Sstevel@tonic-gate backlog = 0; 6297c478bd9Sstevel@tonic-gate lp = &log_backlog; 6307c478bd9Sstevel@tonic-gate } else { 6317c478bd9Sstevel@tonic-gate lp = &lzp->lz_clones[i++]; 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate if ((lp->log_flags & flags) && lp->log_wanted(lp, lc)) { 6357c478bd9Sstevel@tonic-gate if (canput(lp->log_q)) { 6367c478bd9Sstevel@tonic-gate lp->log_overflow = 0; 6377c478bd9Sstevel@tonic-gate lc->seq_no = log_seq_no[lp->log_flags]; 6387c478bd9Sstevel@tonic-gate if ((mp2 = copymsg(mp)) == NULL) 6397c478bd9Sstevel@tonic-gate break; 6407c478bd9Sstevel@tonic-gate if (facility != 0) { 6417c478bd9Sstevel@tonic-gate src = (char *)mp2->b_cont->b_rptr; 6427c478bd9Sstevel@tonic-gate dst = src + facility; 6437c478bd9Sstevel@tonic-gate fac = (lc->pri & LOG_FACMASK) >> 3; 6447c478bd9Sstevel@tonic-gate dst += snprintf(dst, 6457c478bd9Sstevel@tonic-gate LOG_FACSIZE + LOG_PRISIZE, "%s.%s", 6467c478bd9Sstevel@tonic-gate log_fac[MIN(fac, LOG_NFACILITIES)], 6477c478bd9Sstevel@tonic-gate log_pri[lc->pri & LOG_PRIMASK]); 6487c478bd9Sstevel@tonic-gate src += body - 2; /* copy "] " too */ 6497c478bd9Sstevel@tonic-gate while (*src != '\0') 6507c478bd9Sstevel@tonic-gate *dst++ = *src++; 6517c478bd9Sstevel@tonic-gate *dst++ = '\0'; 6527c478bd9Sstevel@tonic-gate mp2->b_cont->b_wptr = (uchar_t *)dst; 6537c478bd9Sstevel@tonic-gate } 6547c478bd9Sstevel@tonic-gate (void) putq(lp->log_q, mp2); 6557c478bd9Sstevel@tonic-gate } else if (++lp->log_overflow == 1) { 6567c478bd9Sstevel@tonic-gate if (lp->log_q == log_consq) { 6577c478bd9Sstevel@tonic-gate console_printf(log_overflow_msg, 6587c478bd9Sstevel@tonic-gate lp->log_minor, 6597c478bd9Sstevel@tonic-gate " -- is syslogd(1M) running?"); 6607c478bd9Sstevel@tonic-gate } else { 6617c478bd9Sstevel@tonic-gate printf(log_overflow_msg, 6627c478bd9Sstevel@tonic-gate lp->log_minor, ""); 6637c478bd9Sstevel@tonic-gate } 6647c478bd9Sstevel@tonic-gate } 6657c478bd9Sstevel@tonic-gate } 6667c478bd9Sstevel@tonic-gate } 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate if (zptr) 6697c478bd9Sstevel@tonic-gate zone_rele(zptr); 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate if ((flags & SL_CONSOLE) && (lc->pri & LOG_FACMASK) == LOG_KERN) { 6727c478bd9Sstevel@tonic-gate if ((mp2 == NULL || log_consq == log_backlogq || panicstr) && 6737c478bd9Sstevel@tonic-gate (lc->flags & SL_LOGONLY) == 0) 6747c478bd9Sstevel@tonic-gate console_printf("%s", (char *)mp->b_cont->b_rptr + body); 6757c478bd9Sstevel@tonic-gate if ((lc->flags & SL_CONSONLY) == 0 && 6767c478bd9Sstevel@tonic-gate (mp2 = copymsg(mp)) != NULL) { 6777c478bd9Sstevel@tonic-gate mp2->b_cont->b_rptr += body; 6787c478bd9Sstevel@tonic-gate if (log_recentq->q_flag & QFULL) 6797c478bd9Sstevel@tonic-gate freemsg(getq_noenab(log_recentq)); 6807c478bd9Sstevel@tonic-gate (void) putq(log_recentq, mp2); 6817c478bd9Sstevel@tonic-gate } 6827c478bd9Sstevel@tonic-gate } 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate log_freemsg(mp); 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate log_exit(); 6877c478bd9Sstevel@tonic-gate } 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate /* 6907c478bd9Sstevel@tonic-gate * Print queued messages to console. 6917c478bd9Sstevel@tonic-gate */ 6927c478bd9Sstevel@tonic-gate void 6937c478bd9Sstevel@tonic-gate log_printq(queue_t *qfirst) 6947c478bd9Sstevel@tonic-gate { 6957c478bd9Sstevel@tonic-gate mblk_t *mp; 6967c478bd9Sstevel@tonic-gate queue_t *q, *qlast; 6977c478bd9Sstevel@tonic-gate char *cp, *msgp; 6987c478bd9Sstevel@tonic-gate log_ctl_t *lc; 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate /* 7017c478bd9Sstevel@tonic-gate * Look ahead to first queued message in the stream. 7027c478bd9Sstevel@tonic-gate */ 7037c478bd9Sstevel@tonic-gate qlast = NULL; 7047c478bd9Sstevel@tonic-gate do { 7057c478bd9Sstevel@tonic-gate for (q = qfirst; q->q_next != qlast; q = q->q_next) 7067c478bd9Sstevel@tonic-gate continue; 7077c478bd9Sstevel@tonic-gate for (mp = q->q_first; mp != NULL; mp = mp->b_next) { 7087c478bd9Sstevel@tonic-gate lc = (log_ctl_t *)mp->b_rptr; 7097c478bd9Sstevel@tonic-gate /* 7107c478bd9Sstevel@tonic-gate * Check if message is already displayed at 7117c478bd9Sstevel@tonic-gate * /dev/console. 7127c478bd9Sstevel@tonic-gate */ 7137c478bd9Sstevel@tonic-gate if (lc->flags & SL_PANICMSG) 7147c478bd9Sstevel@tonic-gate continue; 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate cp = (char *)mp->b_cont->b_rptr; 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate /* Strip off the message ID. */ 7197c478bd9Sstevel@tonic-gate if ((msgp = strstr(cp, "[ID ")) != NULL && 7207c478bd9Sstevel@tonic-gate (msgp = strstr(msgp, "] ")) != NULL) { 7217c478bd9Sstevel@tonic-gate cp = msgp + 2; 7227c478bd9Sstevel@tonic-gate } 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate /* 7257c478bd9Sstevel@tonic-gate * Using console_printf instead of printf to avoid 7267c478bd9Sstevel@tonic-gate * queueing messages to log_consq. 7277c478bd9Sstevel@tonic-gate */ 7287c478bd9Sstevel@tonic-gate console_printf("%s", cp); 7297c478bd9Sstevel@tonic-gate } 7307c478bd9Sstevel@tonic-gate } while ((qlast = q) != qfirst); 7317c478bd9Sstevel@tonic-gate } 732*068ccd7aSns92644 733*068ccd7aSns92644 /* ARGSUSED */ 734*068ccd7aSns92644 static int 735*068ccd7aSns92644 log_cons_constructor(void *buf, void *cdrarg, int kmflags) 736*068ccd7aSns92644 { 737*068ccd7aSns92644 struct log *lp = buf; 738*068ccd7aSns92644 739*068ccd7aSns92644 lp->log_zoneid = GLOBAL_ZONEID; 740*068ccd7aSns92644 lp->log_major = LOG_CONSMIN; /* Indicate which device type */ 741*068ccd7aSns92644 lp->log_data = NULL; 742*068ccd7aSns92644 return (0); 743*068ccd7aSns92644 } 744*068ccd7aSns92644 745*068ccd7aSns92644 /* ARGSUSED */ 746*068ccd7aSns92644 static void 747*068ccd7aSns92644 log_cons_destructor(void *buf, void *cdrarg) 748*068ccd7aSns92644 { 749*068ccd7aSns92644 struct log *lp = buf; 750*068ccd7aSns92644 751*068ccd7aSns92644 ASSERT(lp->log_zoneid == GLOBAL_ZONEID); 752*068ccd7aSns92644 ASSERT(lp->log_major == LOG_CONSMIN); 753*068ccd7aSns92644 ASSERT(lp->log_data == NULL); 754*068ccd7aSns92644 } 755