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
36 * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
44 #include "opt_printf.h"
47 #include <sys/param.h>
49 #include <sys/systm.h>
52 #include <sys/mutex.h>
54 #include <sys/kernel.h>
55 #include <sys/msgbuf.h>
56 #include <sys/malloc.h>
59 #include <sys/stddef.h>
60 #include <sys/sysctl.h>
62 #include <sys/syslog.h>
68 #include <sys/ctype.h>
76 * Note that stdarg.h and the ANSI style va_start macro is used for both
77 * ANSI and traditional C compilers.
80 #include <machine/stdarg.h>
86 * This is needed for sbuf_putbuf() when compiled into userland. Due to the
87 * shared nature of this file, it's the only place to put it.
99 /* Max number conversion buffer length: a u_quad_t in base 2, plus NUL byte. */
100 #define MAXNBUF (sizeof(intmax_t) * NBBY + 1)
112 struct snprintf_arg {
119 static void msglogchar(int c, int pri);
120 static void msglogstr(char *str, int pri, int filter_cr);
121 static void putchar(int ch, void *arg);
122 static char *ksprintn(char *nbuf, uintmax_t num, int base, int *len, int upper);
123 static void snprintf_func(int ch, void *arg);
125 static bool msgbufmapped; /* Set when safe to use msgbuf */
127 struct msgbuf *msgbufp;
130 #define BOOT_TAG_SZ 32
133 /* Tag used to mark the start of a boot in dmesg */
134 #define BOOT_TAG "---<<BOOT>>---"
137 static char current_boot_tag[BOOT_TAG_SZ + 1] = BOOT_TAG;
138 SYSCTL_STRING(_kern, OID_AUTO, boot_tag, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
139 current_boot_tag, 0, "Tag added to dmesg at start of boot");
141 static int log_console_output = 1;
142 SYSCTL_INT(_kern, OID_AUTO, log_console_output, CTLFLAG_RWTUN,
143 &log_console_output, 0, "Duplicate console output to the syslog");
146 * See the comment in log_console() below for more explanation of this.
148 static int log_console_add_linefeed;
149 SYSCTL_INT(_kern, OID_AUTO, log_console_add_linefeed, CTLFLAG_RWTUN,
150 &log_console_add_linefeed, 0, "log_console() adds extra newlines");
152 static int always_console_output;
153 SYSCTL_INT(_kern, OID_AUTO, always_console_output, CTLFLAG_RWTUN,
154 &always_console_output, 0, "Always output to console despite TIOCCONS");
157 * Warn that a system table is full.
160 tablefull(const char *tab)
163 log(LOG_ERR, "%s: table is full\n", tab);
167 * Uprintf prints to the controlling terminal for the current process.
170 uprintf(const char *fmt, ...)
173 struct putchar_arg pca;
179 if (TD_IS_IDLETHREAD(td))
182 if (td->td_proc == initproc) {
183 /* Produce output when we fail to load /sbin/init: */
185 retval = vprintf(fmt, ap);
190 sx_slock(&proctree_lock);
193 if ((p->p_flag & P_CONTROLT) == 0) {
195 sx_sunlock(&proctree_lock);
198 SESS_LOCK(p->p_session);
199 pca.tty = p->p_session->s_ttyp;
200 SESS_UNLOCK(p->p_session);
202 if (pca.tty == NULL) {
203 sx_sunlock(&proctree_lock);
210 sx_sunlock(&proctree_lock);
211 retval = kvprintf(fmt, putchar, &pca, 10, ap);
218 * tprintf and vtprintf print on the controlling terminal associated with the
219 * given session, possibly to the log as well.
222 tprintf(struct proc *p, int pri, const char *fmt, ...)
227 vtprintf(p, pri, fmt, ap);
232 vtprintf(struct proc *p, int pri, const char *fmt, va_list ap)
234 struct tty *tp = NULL;
236 struct putchar_arg pca;
237 struct session *sess = NULL;
239 sx_slock(&proctree_lock);
244 if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
249 if (tp != NULL && tty_checkoutq(tp))
262 sx_sunlock(&proctree_lock);
263 kvprintf(fmt, putchar, &pca, 10, ap);
272 _vprintf(int level, int flags, const char *fmt, va_list ap)
274 struct putchar_arg pca;
276 #ifdef PRINTF_BUFR_SIZE
277 char bufr[PRINTF_BUFR_SIZE];
284 #ifdef PRINTF_BUFR_SIZE
286 pca.p_next = pca.p_bufr;
287 pca.n_bufr = sizeof(bufr);
288 pca.remain = sizeof(bufr);
291 /* Don't buffer console output. */
295 retval = kvprintf(fmt, putchar, &pca, 10, ap);
297 #ifdef PRINTF_BUFR_SIZE
298 /* Write any buffered console/log output: */
299 if (*pca.p_bufr != '\0') {
300 if (pca.flags & TOLOG)
301 msglogstr(pca.p_bufr, level, /*filter_cr*/1);
303 if (pca.flags & TOCONS)
313 * Log writes to the log buffer, and guarantees not to sleep (so can be
314 * called by interrupt routines). If there is no process reading the
315 * log yet, it writes to the console also.
318 log(int level, const char *fmt, ...)
323 vlog(level, fmt, ap);
328 vlog(int level, const char *fmt, va_list ap)
331 (void)_vprintf(level, log_open ? TOLOG : TOCONS | TOLOG, fmt, ap);
335 #define CONSCHUNK 128
338 log_console(struct uio *uio)
344 if (!log_console_output)
347 pri = LOG_INFO | LOG_CONSOLE;
349 consbuffer = malloc(CONSCHUNK, M_TEMP, M_WAITOK);
352 while (uio->uio_resid > 0) {
353 c = imin(uio->uio_resid, CONSCHUNK - 1);
354 error = uiomove(consbuffer, c, uio);
357 /* Make sure we're NUL-terminated */
358 consbuffer[c] = '\0';
359 if (consbuffer[c - 1] == '\n')
363 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
366 * The previous behavior in log_console() is preserved when
367 * log_console_add_linefeed is non-zero. For that behavior, if an
368 * individual console write came in that was not terminated with a
369 * line feed, it would add a line feed.
371 * This results in different data in the message buffer than
372 * appears on the system console (which doesn't add extra line feed
375 * A number of programs and rc scripts write a line feed, or a period
376 * and a line feed when they have completed their operation. On
377 * the console, this looks seamless, but when displayed with
378 * 'dmesg -a', you wind up with output that looks like this:
383 * On the console, it looks like this:
386 * We could add logic to detect that situation, or just not insert
387 * the extra newlines. Set the kern.log_console_add_linefeed
388 * sysctl/tunable variable to get the old behavior.
390 if (!nl && log_console_add_linefeed) {
391 consbuffer[0] = '\n';
392 consbuffer[1] = '\0';
393 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
397 free(consbuffer, M_TEMP);
401 printf(const char *fmt, ...)
407 retval = vprintf(fmt, ap);
414 vprintf(const char *fmt, va_list ap)
418 retval = _vprintf(-1, TOCONS | TOLOG, fmt, ap);
420 if (!KERNEL_PANICKED())
427 prf_putbuf(char *bufr, int flags, int pri)
431 msglogstr(bufr, pri, /*filter_cr*/1);
433 if (flags & TOCONS) {
434 if ((!KERNEL_PANICKED()) && (constty != NULL))
435 msgbuf_addstr(&consmsgbuf, -1,
436 bufr, /*filter_cr*/ 0);
438 if ((constty == NULL) ||(always_console_output))
444 putbuf(int c, struct putchar_arg *ap)
446 /* Check if no console output buffer was provided. */
447 if (ap->p_bufr == NULL) {
448 /* Output direct to the console. */
449 if (ap->flags & TOCONS)
452 if (ap->flags & TOLOG)
453 msglogchar(c, ap->pri);
455 /* Buffer the character: */
459 /* Always leave the buffer zero terminated. */
462 /* Check if the buffer needs to be flushed. */
463 if (ap->remain == 2 || c == '\n') {
464 prf_putbuf(ap->p_bufr, ap->flags, ap->pri);
466 ap->p_next = ap->p_bufr;
467 ap->remain = ap->n_bufr;
472 * Since we fill the buffer up one character at a time,
473 * this should not happen. We should always catch it when
474 * ap->remain == 2 (if not sooner due to a newline), flush
475 * the buffer and move on. One way this could happen is
476 * if someone sets PRINTF_BUFR_SIZE to 1 or something
479 KASSERT(ap->remain > 2, ("Bad buffer logic, remain = %zd",
485 * Print a character on console or users terminal. If destination is
486 * the console then the last bunch of characters are saved in msgbuf for
490 putchar(int c, void *arg)
492 struct putchar_arg *ap = (struct putchar_arg*) arg;
493 struct tty *tp = ap->tty;
494 int flags = ap->flags;
496 /* Don't use the tty code after a panic or while in ddb. */
503 if ((flags & TOTTY) && tp != NULL && !KERNEL_PANICKED())
506 if ((flags & (TOCONS | TOLOG)) && c != '\0')
511 * Scaled down version of sprintf(3).
514 sprintf(char *buf, const char *cfmt, ...)
520 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
527 * Scaled down version of vsprintf(3).
530 vsprintf(char *buf, const char *cfmt, va_list ap)
534 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
540 * Scaled down version of snprintf(3).
543 snprintf(char *str, size_t size, const char *format, ...)
548 va_start(ap, format);
549 retval = vsnprintf(str, size, format, ap);
555 * Scaled down version of vsnprintf(3).
558 vsnprintf(char *str, size_t size, const char *format, va_list ap)
560 struct snprintf_arg info;
565 retval = kvprintf(format, snprintf_func, &info, 10, ap);
566 if (info.remain >= 1)
572 * Kernel version which takes radix argument vsnprintf(3).
575 vsnrprintf(char *str, size_t size, int radix, const char *format, va_list ap)
577 struct snprintf_arg info;
582 retval = kvprintf(format, snprintf_func, &info, radix, ap);
583 if (info.remain >= 1)
589 snprintf_func(int ch, void *arg)
591 struct snprintf_arg *const info = arg;
593 if (info->remain >= 2) {
600 * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse
601 * order; return an optional length and a pointer to the last character
602 * written in the buffer (i.e., the first character of the string).
603 * The buffer pointed to by `nbuf' must have length >= MAXNBUF.
606 ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
613 c = hex2ascii(num % base);
614 *++p = upper ? toupper(c) : c;
615 } while (num /= base);
622 * Scaled down version of printf(3).
624 * Two additional formats:
626 * The format %b is supported to decode error registers.
629 * printf("reg=%b\n", regval, "<base><arg>*");
631 * where <base> is the output base expressed as a control character, e.g.
632 * \10 gives octal; \20 gives hex. Each arg is a sequence of characters,
633 * the first of which gives the bit number to be inspected (origin 1), and
634 * the next characters (up to a control character, i.e. a character <= 32),
635 * give the name of the register. Thus:
637 * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE");
639 * would produce output:
641 * reg=3<BITTWO,BITONE>
643 * XXX: %D -- Hexdump, takes pointer and separator string:
644 * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX
645 * ("%*D", len, ptr, " " -> XX XX XX XX ...
648 kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_list ap)
650 #define PCHAR(c) {int cc=(c); if (func) (*func)(cc,arg); else *d++ = cc; retval++; }
653 const char *p, *percent, *q;
657 int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot;
658 int cflag, hflag, jflag, tflag, zflag;
659 int bconv, dwidth, upper;
661 int stop = 0, retval = 0;
671 fmt = "(fmt null)\n";
673 if (radix < 2 || radix > 36)
679 while ((ch = (u_char)*fmt++) != '%' || stop) {
685 qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0;
686 sign = 0; dot = 0; bconv = 0; dwidth = 0; upper = 0;
687 cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0;
688 reswitch: switch (ch = (u_char)*fmt++) {
706 width = va_arg(ap, int);
712 dwidth = va_arg(ap, int);
721 case '1': case '2': case '3': case '4':
722 case '5': case '6': case '7': case '8': case '9':
723 for (n = 0;; ++fmt) {
724 n = n * 10 + ch - '0';
726 if (ch < '0' || ch > '9')
741 if (!ladjust && width > 0)
744 PCHAR(va_arg(ap, int));
745 if (ladjust && width > 0)
750 up = va_arg(ap, u_char *);
751 p = va_arg(ap, char *);
755 PCHAR(hex2ascii(*up >> 4));
756 PCHAR(hex2ascii(*up & 0x0f));
787 * We do not support %n in kernel, but consume the
791 (void)va_arg(ap, intmax_t *);
793 (void)va_arg(ap, quad_t *);
795 (void)va_arg(ap, long *);
797 (void)va_arg(ap, size_t *);
799 (void)va_arg(ap, short *);
801 (void)va_arg(ap, char *);
803 (void)va_arg(ap, int *);
810 sharpflag = (width == 0);
812 num = (uintptr_t)va_arg(ap, void *);
823 p = va_arg(ap, char *);
829 for (n = 0; n < dwidth && p[n]; n++)
834 if (!ladjust && width > 0)
839 if (ladjust && width > 0)
865 num = va_arg(ap, uintmax_t);
867 num = va_arg(ap, u_quad_t);
869 num = va_arg(ap, ptrdiff_t);
871 num = va_arg(ap, u_long);
873 num = va_arg(ap, size_t);
875 num = (u_short)va_arg(ap, int);
877 num = (u_char)va_arg(ap, int);
879 num = va_arg(ap, u_int);
881 q = va_arg(ap, char *);
887 num = va_arg(ap, intmax_t);
889 num = va_arg(ap, quad_t);
891 num = va_arg(ap, ptrdiff_t);
893 num = va_arg(ap, long);
895 num = va_arg(ap, ssize_t);
897 num = (short)va_arg(ap, int);
899 num = (char)va_arg(ap, int);
901 num = va_arg(ap, int);
903 if (sign && (intmax_t)num < 0) {
905 num = -(intmax_t)num;
907 p = ksprintn(nbuf, num, base, &n, upper);
909 if (sharpflag && num != 0) {
918 if (!ladjust && padc == '0')
919 dwidth = width - tmp;
920 width -= tmp + imax(dwidth, n);
927 if (sharpflag && num != 0) {
930 } else if (base == 16) {
941 if (bconv && num != 0) {
942 /* %b conversion flag format. */
946 if (num & (1 << (n - 1))) {
947 PCHAR(retval != tmp ?
949 for (; (n = *q) > ' '; ++q)
952 for (; *q > ' '; ++q)
957 width -= retval - tmp;
967 while (percent < fmt)
970 * Since we ignore a formatting argument it is no
971 * longer safe to obey the remaining formatting
972 * arguments as the arguments will no longer match
983 * Put character in log buffer with a particular priority.
986 msglogchar(int c, int pri)
988 static int lastpri = -1;
995 if (c == '\0' || c == '\r')
997 if (pri != -1 && pri != lastpri) {
999 msgbuf_addchar(msgbufp, '\n');
1002 msgbuf_addchar(msgbufp, '<');
1003 for (p = ksprintn(nbuf, (uintmax_t)pri, 10, NULL, 0); *p;)
1004 msgbuf_addchar(msgbufp, *p--);
1005 msgbuf_addchar(msgbufp, '>');
1008 msgbuf_addchar(msgbufp, c);
1018 msglogstr(char *str, int pri, int filter_cr)
1023 msgbuf_addstr(msgbufp, pri, str, filter_cr);
1027 msgbufinit(void *ptr, int size)
1030 static struct msgbuf *oldp = NULL;
1031 bool print_boot_tag;
1033 size -= sizeof(*msgbufp);
1035 print_boot_tag = !msgbufmapped;
1036 /* Attempt to fetch kern.boot_tag tunable on first mapping */
1038 TUNABLE_STR_FETCH("kern.boot_tag", current_boot_tag,
1039 sizeof(current_boot_tag));
1040 msgbufp = (struct msgbuf *)(cp + size);
1041 msgbuf_reinit(msgbufp, cp, size);
1042 if (msgbufmapped && oldp != msgbufp)
1043 msgbuf_copy(oldp, msgbufp);
1044 msgbufmapped = true;
1045 if (print_boot_tag && *current_boot_tag != '\0')
1046 printf("%s\n", current_boot_tag);
1050 /* Sysctls for accessing/clearing the msgbuf */
1052 sysctl_kern_msgbuf(SYSCTL_HANDLER_ARGS)
1058 error = priv_check(req->td, PRIV_MSGBUF);
1062 /* Read the whole buffer, one chunk at a time. */
1063 mtx_lock(&msgbuf_lock);
1064 msgbuf_peekbytes(msgbufp, NULL, 0, &seq);
1066 len = msgbuf_peekbytes(msgbufp, buf, sizeof(buf), &seq);
1067 mtx_unlock(&msgbuf_lock);
1069 return (SYSCTL_OUT(req, "", 1)); /* add nulterm */
1071 error = sysctl_handle_opaque(oidp, buf, len, req);
1075 mtx_lock(&msgbuf_lock);
1079 SYSCTL_PROC(_kern, OID_AUTO, msgbuf,
1080 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1081 NULL, 0, sysctl_kern_msgbuf, "A", "Contents of kernel message buffer");
1083 static int msgbuf_clearflag;
1086 sysctl_kern_msgbuf_clear(SYSCTL_HANDLER_ARGS)
1089 error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req);
1090 if (!error && req->newptr) {
1091 mtx_lock(&msgbuf_lock);
1092 msgbuf_clear(msgbufp);
1093 mtx_unlock(&msgbuf_lock);
1094 msgbuf_clearflag = 0;
1099 SYSCTL_PROC(_kern, OID_AUTO, msgbuf_clear,
1100 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE | CTLFLAG_MPSAFE,
1101 &msgbuf_clearflag, 0, sysctl_kern_msgbuf_clear, "I",
1102 "Clear kernel message buffer");
1106 DB_SHOW_COMMAND(msgbuf, db_show_msgbuf)
1110 if (!msgbufmapped) {
1111 db_printf("msgbuf not mapped yet\n");
1114 db_printf("msgbufp = %p\n", msgbufp);
1115 db_printf("magic = %x, size = %d, r= %u, w = %u, ptr = %p, cksum= %u\n",
1116 msgbufp->msg_magic, msgbufp->msg_size, msgbufp->msg_rseq,
1117 msgbufp->msg_wseq, msgbufp->msg_ptr, msgbufp->msg_cksum);
1118 for (i = 0; i < msgbufp->msg_size && !db_pager_quit; i++) {
1119 j = MSGBUF_SEQ_TO_POS(msgbufp, i + msgbufp->msg_rseq);
1120 db_printf("%c", msgbufp->msg_ptr[j]);
1128 hexdump(const void *ptr, int length, const char *hdr, int flags)
1132 const unsigned char *cp;
1135 if ((flags & HD_DELIM_MASK) != 0)
1136 delim = (flags & HD_DELIM_MASK) >> 8;
1140 if ((flags & HD_COLUMN_MASK) != 0)
1141 cols = flags & HD_COLUMN_MASK;
1146 for (i = 0; i < length; i+= cols) {
1150 if ((flags & HD_OMIT_COUNT) == 0)
1153 if ((flags & HD_OMIT_HEX) == 0) {
1154 for (j = 0; j < cols; j++) {
1157 printf("%c%02x", delim, cp[k]);
1163 if ((flags & HD_OMIT_CHARS) == 0) {
1165 for (j = 0; j < cols; j++) {
1169 else if (cp[k] >= ' ' && cp[k] <= '~')
1170 printf("%c", cp[k]);
1179 #endif /* _KERNEL */
1182 sbuf_hexdump(struct sbuf *sb, const void *ptr, int length, const char *hdr,
1187 const unsigned char *cp;
1190 if ((flags & HD_DELIM_MASK) != 0)
1191 delim = (flags & HD_DELIM_MASK) >> 8;
1195 if ((flags & HD_COLUMN_MASK) != 0)
1196 cols = flags & HD_COLUMN_MASK;
1201 for (i = 0; i < length; i+= cols) {
1203 sbuf_printf(sb, "%s", hdr);
1205 if ((flags & HD_OMIT_COUNT) == 0)
1206 sbuf_printf(sb, "%04x ", i);
1208 if ((flags & HD_OMIT_HEX) == 0) {
1209 for (j = 0; j < cols; j++) {
1212 sbuf_printf(sb, "%c%02x", delim, cp[k]);
1214 sbuf_printf(sb, " ");
1218 if ((flags & HD_OMIT_CHARS) == 0) {
1219 sbuf_printf(sb, " |");
1220 for (j = 0; j < cols; j++) {
1223 sbuf_printf(sb, " ");
1224 else if (cp[k] >= ' ' && cp[k] <= '~')
1225 sbuf_printf(sb, "%c", cp[k]);
1227 sbuf_printf(sb, ".");
1229 sbuf_printf(sb, "|");
1231 sbuf_printf(sb, "\n");
1237 counted_warning(unsigned *counter, const char *msg)
1246 if (atomic_cmpset_int(counter, c, c - 1)) {
1248 log(LOG_INFO, "pid %d (%s) %s%s\n",
1249 td->td_proc->p_pid, td->td_name, msg,
1250 c > 1 ? "" : " - not logging anymore");
1259 sbuf_putbuf(struct sbuf *sb)
1262 prf_putbuf(sbuf_data(sb), TOLOG | TOCONS, -1);
1266 sbuf_putbuf(struct sbuf *sb)
1269 printf("%s", sbuf_data(sb));
1274 sbuf_printf_drain(void *arg, const char *data, int len)
1283 * This is allowed as an extra byte is always resvered for
1284 * terminating NUL byte. Save and restore the byte because
1285 * we might be flushing a record, and there may be valid
1286 * data after the buffer.
1289 dataptr = __DECONST(char *, data);
1290 dataptr[len] = '\0';
1292 prf_putbuf(dataptr, TOLOG | TOCONS, -1);
1295 dataptr[len] = oldchr;
1297 #else /* !_KERNEL */
1299 r = printf("%.*s", len, data);
1306 if (retvalptr != NULL)