2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1986, 1988, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
40 #include "opt_printf.h"
43 #include <sys/param.h>
45 #include <sys/systm.h>
48 #include <sys/mutex.h>
50 #include <sys/kernel.h>
51 #include <sys/msgbuf.h>
52 #include <sys/malloc.h>
55 #include <sys/stddef.h>
56 #include <sys/sysctl.h>
57 #include <sys/tslog.h>
59 #include <sys/syslog.h>
65 #include <sys/ctype.h>
73 * Note that stdarg.h and the ANSI style va_start macro is used for both
74 * ANSI and traditional C compilers.
77 #include <machine/stdarg.h>
83 * This is needed for sbuf_putbuf() when compiled into userland. Due to the
84 * shared nature of this file, it's the only place to put it.
96 /* Max number conversion buffer length: a u_quad_t in base 2, plus NUL byte. */
97 #define MAXNBUF (sizeof(intmax_t) * NBBY + 1)
109 struct snprintf_arg {
116 static void msglogchar(int c, int pri);
117 static void msglogstr(char *str, int pri, int filter_cr);
118 static void prf_putbuf(char *bufr, int flags, int pri);
119 static void putchar(int ch, void *arg);
120 static char *ksprintn(char *nbuf, uintmax_t num, int base, int *len, int upper);
121 static void snprintf_func(int ch, void *arg);
123 static bool msgbufmapped; /* Set when safe to use msgbuf */
125 struct msgbuf *msgbufp;
128 #define BOOT_TAG_SZ 32
131 /* Tag used to mark the start of a boot in dmesg */
132 #define BOOT_TAG "---<<BOOT>>---"
135 static char current_boot_tag[BOOT_TAG_SZ + 1] = BOOT_TAG;
136 SYSCTL_STRING(_kern, OID_AUTO, boot_tag, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
137 current_boot_tag, 0, "Tag added to dmesg at start of boot");
139 static int log_console_output = 1;
140 SYSCTL_INT(_kern, OID_AUTO, log_console_output, CTLFLAG_RWTUN,
141 &log_console_output, 0, "Duplicate console output to the syslog");
144 * See the comment in log_console() below for more explanation of this.
146 static int log_console_add_linefeed;
147 SYSCTL_INT(_kern, OID_AUTO, log_console_add_linefeed, CTLFLAG_RWTUN,
148 &log_console_add_linefeed, 0, "log_console() adds extra newlines");
150 static int always_console_output;
151 SYSCTL_INT(_kern, OID_AUTO, always_console_output, CTLFLAG_RWTUN,
152 &always_console_output, 0, "Always output to console despite TIOCCONS");
155 * Warn that a system table is full.
158 tablefull(const char *tab)
161 log(LOG_ERR, "%s: table is full\n", tab);
165 * Uprintf prints to the controlling terminal for the current process.
168 uprintf(const char *fmt, ...)
171 struct putchar_arg pca;
177 if (TD_IS_IDLETHREAD(td))
180 if (td->td_proc == initproc) {
181 /* Produce output when we fail to load /sbin/init: */
183 retval = vprintf(fmt, ap);
188 sx_slock(&proctree_lock);
191 if ((p->p_flag & P_CONTROLT) == 0) {
193 sx_sunlock(&proctree_lock);
196 SESS_LOCK(p->p_session);
197 pca.tty = p->p_session->s_ttyp;
198 SESS_UNLOCK(p->p_session);
200 if (pca.tty == NULL) {
201 sx_sunlock(&proctree_lock);
208 sx_sunlock(&proctree_lock);
209 retval = kvprintf(fmt, putchar, &pca, 10, ap);
216 * tprintf and vtprintf print on the controlling terminal associated with the
217 * given session, possibly to the log as well.
220 tprintf(struct proc *p, int pri, const char *fmt, ...)
225 vtprintf(p, pri, fmt, ap);
230 vtprintf(struct proc *p, int pri, const char *fmt, va_list ap)
232 struct tty *tp = NULL;
234 struct putchar_arg pca;
235 struct session *sess = NULL;
237 sx_slock(&proctree_lock);
242 if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
247 if (tp != NULL && tty_checkoutq(tp))
260 sx_sunlock(&proctree_lock);
261 kvprintf(fmt, putchar, &pca, 10, ap);
270 _vprintf(int level, int flags, const char *fmt, va_list ap)
272 struct putchar_arg pca;
274 #ifdef PRINTF_BUFR_SIZE
275 char bufr[PRINTF_BUFR_SIZE];
282 #ifdef PRINTF_BUFR_SIZE
284 pca.p_next = pca.p_bufr;
285 pca.n_bufr = sizeof(bufr);
286 pca.remain = sizeof(bufr);
289 /* Don't buffer console output. */
293 retval = kvprintf(fmt, putchar, &pca, 10, ap);
295 #ifdef PRINTF_BUFR_SIZE
296 /* Write any buffered console/log output: */
297 if (*pca.p_bufr != '\0')
298 prf_putbuf(pca.p_bufr, flags, level);
306 * Log writes to the log buffer, and guarantees not to sleep (so can be
307 * called by interrupt routines). If there is no process reading the
308 * log yet, it writes to the console also.
311 log(int level, const char *fmt, ...)
316 vlog(level, fmt, ap);
321 vlog(int level, const char *fmt, va_list ap)
324 (void)_vprintf(level, log_open ? TOLOG : TOCONS | TOLOG, fmt, ap);
328 #define CONSCHUNK 128
331 log_console(struct uio *uio)
337 if (!log_console_output)
340 pri = LOG_INFO | LOG_CONSOLE;
342 consbuffer = malloc(CONSCHUNK, M_TEMP, M_WAITOK);
345 while (uio->uio_resid > 0) {
346 c = imin(uio->uio_resid, CONSCHUNK - 1);
347 error = uiomove(consbuffer, c, uio);
350 /* Make sure we're NUL-terminated */
351 consbuffer[c] = '\0';
352 if (consbuffer[c - 1] == '\n')
356 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
359 * The previous behavior in log_console() is preserved when
360 * log_console_add_linefeed is non-zero. For that behavior, if an
361 * individual console write came in that was not terminated with a
362 * line feed, it would add a line feed.
364 * This results in different data in the message buffer than
365 * appears on the system console (which doesn't add extra line feed
368 * A number of programs and rc scripts write a line feed, or a period
369 * and a line feed when they have completed their operation. On
370 * the console, this looks seamless, but when displayed with
371 * 'dmesg -a', you wind up with output that looks like this:
376 * On the console, it looks like this:
379 * We could add logic to detect that situation, or just not insert
380 * the extra newlines. Set the kern.log_console_add_linefeed
381 * sysctl/tunable variable to get the old behavior.
383 if (!nl && log_console_add_linefeed) {
384 consbuffer[0] = '\n';
385 consbuffer[1] = '\0';
386 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
390 free(consbuffer, M_TEMP);
394 printf(const char *fmt, ...)
400 retval = vprintf(fmt, ap);
407 vprintf(const char *fmt, va_list ap)
411 retval = _vprintf(-1, TOCONS | TOLOG, fmt, ap);
413 if (!KERNEL_PANICKED())
420 prf_putchar(int c, int flags, int pri)
428 if (flags & TOCONS) {
429 if ((!KERNEL_PANICKED()) && (constty != NULL))
430 msgbuf_addchar(&consmsgbuf, c);
432 if ((constty == NULL) || always_console_output)
438 prf_putbuf(char *bufr, int flags, int pri)
442 msglogstr(bufr, pri, /*filter_cr*/1);
446 if (flags & TOCONS) {
447 if ((!KERNEL_PANICKED()) && (constty != NULL))
448 msgbuf_addstr(&consmsgbuf, -1,
449 bufr, /*filter_cr*/ 0);
451 if ((constty == NULL) || always_console_output)
457 putbuf(int c, struct putchar_arg *ap)
459 /* Check if no console output buffer was provided. */
460 if (ap->p_bufr == NULL) {
461 prf_putchar(c, ap->flags, ap->pri);
463 /* Buffer the character: */
467 /* Always leave the buffer zero terminated. */
470 /* Check if the buffer needs to be flushed. */
471 if (ap->remain == 2 || c == '\n') {
472 prf_putbuf(ap->p_bufr, ap->flags, ap->pri);
474 ap->p_next = ap->p_bufr;
475 ap->remain = ap->n_bufr;
480 * Since we fill the buffer up one character at a time,
481 * this should not happen. We should always catch it when
482 * ap->remain == 2 (if not sooner due to a newline), flush
483 * the buffer and move on. One way this could happen is
484 * if someone sets PRINTF_BUFR_SIZE to 1 or something
487 KASSERT(ap->remain > 2, ("Bad buffer logic, remain = %zd",
493 * Print a character on console or users terminal. If destination is
494 * the console then the last bunch of characters are saved in msgbuf for
498 putchar(int c, void *arg)
500 struct putchar_arg *ap = (struct putchar_arg*) arg;
501 struct tty *tp = ap->tty;
502 int flags = ap->flags;
504 /* Don't use the tty code after a panic or while in ddb. */
511 if ((flags & TOTTY) && tp != NULL && !KERNEL_PANICKED())
514 if ((flags & (TOCONS | TOLOG)) && c != '\0')
519 * Scaled down version of sprintf(3).
522 sprintf(char *buf, const char *cfmt, ...)
528 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
535 * Scaled down version of vsprintf(3).
538 vsprintf(char *buf, const char *cfmt, va_list ap)
542 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
548 * Scaled down version of snprintf(3).
551 snprintf(char *str, size_t size, const char *format, ...)
556 va_start(ap, format);
557 retval = vsnprintf(str, size, format, ap);
563 * Scaled down version of vsnprintf(3).
566 vsnprintf(char *str, size_t size, const char *format, va_list ap)
568 struct snprintf_arg info;
573 retval = kvprintf(format, snprintf_func, &info, 10, ap);
574 if (info.remain >= 1)
580 * Kernel version which takes radix argument vsnprintf(3).
583 vsnrprintf(char *str, size_t size, int radix, const char *format, va_list ap)
585 struct snprintf_arg info;
590 retval = kvprintf(format, snprintf_func, &info, radix, ap);
591 if (info.remain >= 1)
597 snprintf_func(int ch, void *arg)
599 struct snprintf_arg *const info = arg;
601 if (info->remain >= 2) {
608 * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse
609 * order; return an optional length and a pointer to the last character
610 * written in the buffer (i.e., the first character of the string).
611 * The buffer pointed to by `nbuf' must have length >= MAXNBUF.
614 ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
621 c = hex2ascii(num % base);
622 *++p = upper ? toupper(c) : c;
623 } while (num /= base);
630 * Scaled down version of printf(3).
632 * Two additional formats:
634 * The format %b is supported to decode error registers.
637 * printf("reg=%b\n", regval, "<base><arg>*");
639 * where <base> is the output base expressed as a control character, e.g.
640 * \10 gives octal; \20 gives hex. Each arg is a sequence of characters,
641 * the first of which gives the bit number to be inspected (origin 1), and
642 * the next characters (up to a control character, i.e. a character <= 32),
643 * give the name of the register. Thus:
645 * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE");
647 * would produce output:
649 * reg=3<BITTWO,BITONE>
651 * XXX: %D -- Hexdump, takes pointer and separator string:
652 * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX
653 * ("%*D", len, ptr, " " -> XX XX XX XX ...
656 kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_list ap)
658 #define PCHAR(c) {int cc=(c); if (func) (*func)(cc,arg); else *d++ = cc; retval++; }
661 const char *p, *percent, *q;
665 int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot;
666 int cflag, hflag, jflag, tflag, zflag;
667 int bconv, dwidth, upper;
669 int stop = 0, retval = 0;
679 fmt = "(fmt null)\n";
681 if (radix < 2 || radix > 36)
687 while ((ch = (u_char)*fmt++) != '%' || stop) {
693 qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0;
694 sign = 0; dot = 0; bconv = 0; dwidth = 0; upper = 0;
695 cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0;
696 reswitch: switch (ch = (u_char)*fmt++) {
714 width = va_arg(ap, int);
720 dwidth = va_arg(ap, int);
729 case '1': case '2': case '3': case '4':
730 case '5': case '6': case '7': case '8': case '9':
731 for (n = 0;; ++fmt) {
732 n = n * 10 + ch - '0';
734 if (ch < '0' || ch > '9')
749 if (!ladjust && width > 0)
752 PCHAR(va_arg(ap, int));
753 if (ladjust && width > 0)
758 up = va_arg(ap, u_char *);
759 p = va_arg(ap, char *);
763 PCHAR(hex2ascii(*up >> 4));
764 PCHAR(hex2ascii(*up & 0x0f));
795 * We do not support %n in kernel, but consume the
799 (void)va_arg(ap, intmax_t *);
801 (void)va_arg(ap, quad_t *);
803 (void)va_arg(ap, long *);
805 (void)va_arg(ap, size_t *);
807 (void)va_arg(ap, short *);
809 (void)va_arg(ap, char *);
811 (void)va_arg(ap, int *);
818 sharpflag = (width == 0);
820 num = (uintptr_t)va_arg(ap, void *);
831 p = va_arg(ap, char *);
837 for (n = 0; n < dwidth && p[n]; n++)
842 if (!ladjust && width > 0)
847 if (ladjust && width > 0)
873 num = va_arg(ap, uintmax_t);
875 num = va_arg(ap, u_quad_t);
877 num = va_arg(ap, ptrdiff_t);
879 num = va_arg(ap, u_long);
881 num = va_arg(ap, size_t);
883 num = (u_short)va_arg(ap, int);
885 num = (u_char)va_arg(ap, int);
887 num = va_arg(ap, u_int);
889 q = va_arg(ap, char *);
895 num = va_arg(ap, intmax_t);
897 num = va_arg(ap, quad_t);
899 num = va_arg(ap, ptrdiff_t);
901 num = va_arg(ap, long);
903 num = va_arg(ap, ssize_t);
905 num = (short)va_arg(ap, int);
907 num = (char)va_arg(ap, int);
909 num = va_arg(ap, int);
911 if (sign && (intmax_t)num < 0) {
913 num = -(intmax_t)num;
915 p = ksprintn(nbuf, num, base, &n, upper);
917 if (sharpflag && num != 0) {
926 if (!ladjust && padc == '0')
927 dwidth = width - tmp;
928 width -= tmp + imax(dwidth, n);
935 if (sharpflag && num != 0) {
938 } else if (base == 16) {
949 if (bconv && num != 0) {
950 /* %b conversion flag format. */
954 if (num & (1 << (n - 1))) {
955 PCHAR(retval != tmp ?
957 for (; (n = *q) > ' '; ++q)
960 for (; *q > ' '; ++q)
965 width -= retval - tmp;
975 while (percent < fmt)
978 * Since we ignore a formatting argument it is no
979 * longer safe to obey the remaining formatting
980 * arguments as the arguments will no longer match
991 * Put character in log buffer with a particular priority.
994 msglogchar(int c, int pri)
996 static int lastpri = -1;
1003 if (c == '\0' || c == '\r')
1005 if (pri != -1 && pri != lastpri) {
1007 msgbuf_addchar(msgbufp, '\n');
1010 msgbuf_addchar(msgbufp, '<');
1011 for (p = ksprintn(nbuf, (uintmax_t)pri, 10, NULL, 0); *p;)
1012 msgbuf_addchar(msgbufp, *p--);
1013 msgbuf_addchar(msgbufp, '>');
1016 msgbuf_addchar(msgbufp, c);
1026 msglogstr(char *str, int pri, int filter_cr)
1031 msgbuf_addstr(msgbufp, pri, str, filter_cr);
1035 msgbufinit(void *ptr, int size)
1038 static struct msgbuf *oldp = NULL;
1039 bool print_boot_tag;
1042 size -= sizeof(*msgbufp);
1044 print_boot_tag = !msgbufmapped;
1045 /* Attempt to fetch kern.boot_tag tunable on first mapping */
1047 TUNABLE_STR_FETCH("kern.boot_tag", current_boot_tag,
1048 sizeof(current_boot_tag));
1049 msgbufp = (struct msgbuf *)(cp + size);
1050 msgbuf_reinit(msgbufp, cp, size);
1051 if (msgbufmapped && oldp != msgbufp)
1052 msgbuf_copy(oldp, msgbufp);
1053 msgbufmapped = true;
1054 if (print_boot_tag && *current_boot_tag != '\0')
1055 printf("%s\n", current_boot_tag);
1060 /* Sysctls for accessing/clearing the msgbuf */
1062 sysctl_kern_msgbuf(SYSCTL_HANDLER_ARGS)
1069 error = priv_check(req->td, PRIV_MSGBUF);
1073 /* Read the whole buffer, one chunk at a time. */
1074 mtx_lock(&msgbuf_lock);
1075 msgbuf_peekbytes(msgbufp, NULL, 0, &seq);
1078 len = msgbuf_peekbytes(msgbufp, buf, sizeof(buf), &seq);
1079 mtx_unlock(&msgbuf_lock);
1081 return (SYSCTL_OUT(req, "", 1)); /* add nulterm */
1083 /* Skip the first line, as it is probably incomplete. */
1084 bp = memchr(buf, '\n', len);
1086 mtx_lock(&msgbuf_lock);
1093 mtx_lock(&msgbuf_lock);
1098 error = sysctl_handle_opaque(oidp, bp, len, req);
1102 mtx_lock(&msgbuf_lock);
1106 SYSCTL_PROC(_kern, OID_AUTO, msgbuf,
1107 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1108 NULL, 0, sysctl_kern_msgbuf, "A", "Contents of kernel message buffer");
1110 static int msgbuf_clearflag;
1113 sysctl_kern_msgbuf_clear(SYSCTL_HANDLER_ARGS)
1116 error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req);
1117 if (!error && req->newptr) {
1118 mtx_lock(&msgbuf_lock);
1119 msgbuf_clear(msgbufp);
1120 mtx_unlock(&msgbuf_lock);
1121 msgbuf_clearflag = 0;
1126 SYSCTL_PROC(_kern, OID_AUTO, msgbuf_clear,
1127 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE | CTLFLAG_MPSAFE,
1128 &msgbuf_clearflag, 0, sysctl_kern_msgbuf_clear, "I",
1129 "Clear kernel message buffer");
1133 DB_SHOW_COMMAND_FLAGS(msgbuf, db_show_msgbuf, DB_CMD_MEMSAFE)
1137 if (!msgbufmapped) {
1138 db_printf("msgbuf not mapped yet\n");
1141 db_printf("msgbufp = %p\n", msgbufp);
1142 db_printf("magic = %x, size = %d, r= %u, w = %u, ptr = %p, cksum= %u\n",
1143 msgbufp->msg_magic, msgbufp->msg_size, msgbufp->msg_rseq,
1144 msgbufp->msg_wseq, msgbufp->msg_ptr, msgbufp->msg_cksum);
1145 for (i = 0; i < msgbufp->msg_size && !db_pager_quit; i++) {
1146 j = MSGBUF_SEQ_TO_POS(msgbufp, i + msgbufp->msg_rseq);
1147 db_printf("%c", msgbufp->msg_ptr[j]);
1155 hexdump(const void *ptr, int length, const char *hdr, int flags)
1159 const unsigned char *cp;
1162 if ((flags & HD_DELIM_MASK) != 0)
1163 delim = (flags & HD_DELIM_MASK) >> 8;
1167 if ((flags & HD_COLUMN_MASK) != 0)
1168 cols = flags & HD_COLUMN_MASK;
1173 for (i = 0; i < length; i+= cols) {
1177 if ((flags & HD_OMIT_COUNT) == 0)
1180 if ((flags & HD_OMIT_HEX) == 0) {
1181 for (j = 0; j < cols; j++) {
1184 printf("%c%02x", delim, cp[k]);
1190 if ((flags & HD_OMIT_CHARS) == 0) {
1192 for (j = 0; j < cols; j++) {
1196 else if (cp[k] >= ' ' && cp[k] <= '~')
1197 printf("%c", cp[k]);
1206 #endif /* _KERNEL */
1209 sbuf_hexdump(struct sbuf *sb, const void *ptr, int length, const char *hdr,
1214 const unsigned char *cp;
1217 if ((flags & HD_DELIM_MASK) != 0)
1218 delim = (flags & HD_DELIM_MASK) >> 8;
1222 if ((flags & HD_COLUMN_MASK) != 0)
1223 cols = flags & HD_COLUMN_MASK;
1228 for (i = 0; i < length; i+= cols) {
1230 sbuf_printf(sb, "%s", hdr);
1232 if ((flags & HD_OMIT_COUNT) == 0)
1233 sbuf_printf(sb, "%04x ", i);
1235 if ((flags & HD_OMIT_HEX) == 0) {
1236 for (j = 0; j < cols; j++) {
1239 sbuf_printf(sb, "%c%02x", delim, cp[k]);
1245 if ((flags & HD_OMIT_CHARS) == 0) {
1247 for (j = 0; j < cols; j++) {
1251 else if (cp[k] >= ' ' && cp[k] <= '~')
1252 sbuf_putc(sb, cp[k]);
1258 sbuf_putc(sb, '\n');
1264 counted_warning(unsigned *counter, const char *msg)
1273 if (atomic_cmpset_int(counter, c, c - 1)) {
1275 log(LOG_INFO, "pid %d (%s) %s%s\n",
1276 td->td_proc->p_pid, td->td_name, msg,
1277 c > 1 ? "" : " - not logging anymore");
1286 sbuf_putbuf(struct sbuf *sb)
1289 prf_putbuf(sbuf_data(sb), TOLOG | TOCONS, -1);
1293 sbuf_putbuf(struct sbuf *sb)
1296 printf("%s", sbuf_data(sb));
1301 sbuf_printf_drain(void *arg, const char *data, int len)
1310 * This is allowed as an extra byte is always resvered for
1311 * terminating NUL byte. Save and restore the byte because
1312 * we might be flushing a record, and there may be valid
1313 * data after the buffer.
1316 dataptr = __DECONST(char *, data);
1317 dataptr[len] = '\0';
1319 prf_putbuf(dataptr, TOLOG | TOCONS, -1);
1322 dataptr[len] = oldchr;
1324 #else /* !_KERNEL */
1326 r = printf("%.*s", len, data);
1333 if (retvalptr != NULL)