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 sx_slock(&proctree_lock);
185 if ((p->p_flag & P_CONTROLT) == 0) {
187 sx_sunlock(&proctree_lock);
190 SESS_LOCK(p->p_session);
191 pca.tty = p->p_session->s_ttyp;
192 SESS_UNLOCK(p->p_session);
194 if (pca.tty == NULL) {
195 sx_sunlock(&proctree_lock);
202 sx_sunlock(&proctree_lock);
203 retval = kvprintf(fmt, putchar, &pca, 10, ap);
210 * tprintf and vtprintf print on the controlling terminal associated with the
211 * given session, possibly to the log as well.
214 tprintf(struct proc *p, int pri, const char *fmt, ...)
219 vtprintf(p, pri, fmt, ap);
224 vtprintf(struct proc *p, int pri, const char *fmt, va_list ap)
226 struct tty *tp = NULL;
228 struct putchar_arg pca;
229 struct session *sess = NULL;
231 sx_slock(&proctree_lock);
236 if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
241 if (tp != NULL && tty_checkoutq(tp))
254 sx_sunlock(&proctree_lock);
255 kvprintf(fmt, putchar, &pca, 10, ap);
264 _vprintf(int level, int flags, const char *fmt, va_list ap)
266 struct putchar_arg pca;
268 #ifdef PRINTF_BUFR_SIZE
269 char bufr[PRINTF_BUFR_SIZE];
276 #ifdef PRINTF_BUFR_SIZE
278 pca.p_next = pca.p_bufr;
279 pca.n_bufr = sizeof(bufr);
280 pca.remain = sizeof(bufr);
283 /* Don't buffer console output. */
287 retval = kvprintf(fmt, putchar, &pca, 10, ap);
289 #ifdef PRINTF_BUFR_SIZE
290 /* Write any buffered console/log output: */
291 if (*pca.p_bufr != '\0') {
292 if (pca.flags & TOLOG)
293 msglogstr(pca.p_bufr, level, /*filter_cr*/1);
295 if (pca.flags & TOCONS)
305 * Log writes to the log buffer, and guarantees not to sleep (so can be
306 * called by interrupt routines). If there is no process reading the
307 * log yet, it writes to the console also.
310 log(int level, const char *fmt, ...)
315 vlog(level, fmt, ap);
320 vlog(int level, const char *fmt, va_list ap)
323 (void)_vprintf(level, log_open ? TOLOG : TOCONS | TOLOG, fmt, ap);
327 #define CONSCHUNK 128
330 log_console(struct uio *uio)
336 if (!log_console_output)
339 pri = LOG_INFO | LOG_CONSOLE;
341 consbuffer = malloc(CONSCHUNK, M_TEMP, M_WAITOK);
344 while (uio->uio_resid > 0) {
345 c = imin(uio->uio_resid, CONSCHUNK - 1);
346 error = uiomove(consbuffer, c, uio);
349 /* Make sure we're NUL-terminated */
350 consbuffer[c] = '\0';
351 if (consbuffer[c - 1] == '\n')
355 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
358 * The previous behavior in log_console() is preserved when
359 * log_console_add_linefeed is non-zero. For that behavior, if an
360 * individual console write came in that was not terminated with a
361 * line feed, it would add a line feed.
363 * This results in different data in the message buffer than
364 * appears on the system console (which doesn't add extra line feed
367 * A number of programs and rc scripts write a line feed, or a period
368 * and a line feed when they have completed their operation. On
369 * the console, this looks seamless, but when displayed with
370 * 'dmesg -a', you wind up with output that looks like this:
375 * On the console, it looks like this:
378 * We could add logic to detect that situation, or just not insert
379 * the extra newlines. Set the kern.log_console_add_linefeed
380 * sysctl/tunable variable to get the old behavior.
382 if (!nl && log_console_add_linefeed) {
383 consbuffer[0] = '\n';
384 consbuffer[1] = '\0';
385 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
389 free(consbuffer, M_TEMP);
393 printf(const char *fmt, ...)
399 retval = vprintf(fmt, ap);
406 vprintf(const char *fmt, va_list ap)
410 retval = _vprintf(-1, TOCONS | TOLOG, fmt, ap);
419 prf_putbuf(char *bufr, int flags, int pri)
423 msglogstr(bufr, pri, /*filter_cr*/1);
425 if (flags & TOCONS) {
426 if ((panicstr == NULL) && (constty != NULL))
427 msgbuf_addstr(&consmsgbuf, -1,
428 bufr, /*filter_cr*/ 0);
430 if ((constty == NULL) ||(always_console_output))
436 putbuf(int c, struct putchar_arg *ap)
438 /* Check if no console output buffer was provided. */
439 if (ap->p_bufr == NULL) {
440 /* Output direct to the console. */
441 if (ap->flags & TOCONS)
444 if (ap->flags & TOLOG)
445 msglogchar(c, ap->pri);
447 /* Buffer the character: */
451 /* Always leave the buffer zero terminated. */
454 /* Check if the buffer needs to be flushed. */
455 if (ap->remain == 2 || c == '\n') {
456 prf_putbuf(ap->p_bufr, ap->flags, ap->pri);
458 ap->p_next = ap->p_bufr;
459 ap->remain = ap->n_bufr;
464 * Since we fill the buffer up one character at a time,
465 * this should not happen. We should always catch it when
466 * ap->remain == 2 (if not sooner due to a newline), flush
467 * the buffer and move on. One way this could happen is
468 * if someone sets PRINTF_BUFR_SIZE to 1 or something
471 KASSERT(ap->remain > 2, ("Bad buffer logic, remain = %zd",
477 * Print a character on console or users terminal. If destination is
478 * the console then the last bunch of characters are saved in msgbuf for
482 putchar(int c, void *arg)
484 struct putchar_arg *ap = (struct putchar_arg*) arg;
485 struct tty *tp = ap->tty;
486 int flags = ap->flags;
488 /* Don't use the tty code after a panic or while in ddb. */
495 if ((flags & TOTTY) && tp != NULL && panicstr == NULL)
498 if ((flags & (TOCONS | TOLOG)) && c != '\0')
503 * Scaled down version of sprintf(3).
506 sprintf(char *buf, const char *cfmt, ...)
512 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
519 * Scaled down version of vsprintf(3).
522 vsprintf(char *buf, const char *cfmt, va_list ap)
526 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
532 * Scaled down version of snprintf(3).
535 snprintf(char *str, size_t size, const char *format, ...)
540 va_start(ap, format);
541 retval = vsnprintf(str, size, format, ap);
547 * Scaled down version of vsnprintf(3).
550 vsnprintf(char *str, size_t size, const char *format, va_list ap)
552 struct snprintf_arg info;
557 retval = kvprintf(format, snprintf_func, &info, 10, ap);
558 if (info.remain >= 1)
564 * Kernel version which takes radix argument vsnprintf(3).
567 vsnrprintf(char *str, size_t size, int radix, const char *format, va_list ap)
569 struct snprintf_arg info;
574 retval = kvprintf(format, snprintf_func, &info, radix, ap);
575 if (info.remain >= 1)
581 snprintf_func(int ch, void *arg)
583 struct snprintf_arg *const info = arg;
585 if (info->remain >= 2) {
592 * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse
593 * order; return an optional length and a pointer to the last character
594 * written in the buffer (i.e., the first character of the string).
595 * The buffer pointed to by `nbuf' must have length >= MAXNBUF.
598 ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
605 c = hex2ascii(num % base);
606 *++p = upper ? toupper(c) : c;
607 } while (num /= base);
614 * Scaled down version of printf(3).
616 * Two additional formats:
618 * The format %b is supported to decode error registers.
621 * printf("reg=%b\n", regval, "<base><arg>*");
623 * where <base> is the output base expressed as a control character, e.g.
624 * \10 gives octal; \20 gives hex. Each arg is a sequence of characters,
625 * the first of which gives the bit number to be inspected (origin 1), and
626 * the next characters (up to a control character, i.e. a character <= 32),
627 * give the name of the register. Thus:
629 * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE");
631 * would produce output:
633 * reg=3<BITTWO,BITONE>
635 * XXX: %D -- Hexdump, takes pointer and separator string:
636 * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX
637 * ("%*D", len, ptr, " " -> XX XX XX XX ...
640 kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_list ap)
642 #define PCHAR(c) {int cc=(c); if (func) (*func)(cc,arg); else *d++ = cc; retval++; }
645 const char *p, *percent, *q;
649 int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot;
650 int cflag, hflag, jflag, tflag, zflag;
651 int bconv, dwidth, upper;
653 int stop = 0, retval = 0;
663 fmt = "(fmt null)\n";
665 if (radix < 2 || radix > 36)
671 while ((ch = (u_char)*fmt++) != '%' || stop) {
677 qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0;
678 sign = 0; dot = 0; bconv = 0; dwidth = 0; upper = 0;
679 cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0;
680 reswitch: switch (ch = (u_char)*fmt++) {
698 width = va_arg(ap, int);
704 dwidth = va_arg(ap, int);
713 case '1': case '2': case '3': case '4':
714 case '5': case '6': case '7': case '8': case '9':
715 for (n = 0;; ++fmt) {
716 n = n * 10 + ch - '0';
718 if (ch < '0' || ch > '9')
733 if (!ladjust && width > 0)
736 PCHAR(va_arg(ap, int));
737 if (ladjust && width > 0)
742 up = va_arg(ap, u_char *);
743 p = va_arg(ap, char *);
747 PCHAR(hex2ascii(*up >> 4));
748 PCHAR(hex2ascii(*up & 0x0f));
779 *(va_arg(ap, intmax_t *)) = retval;
781 *(va_arg(ap, quad_t *)) = retval;
783 *(va_arg(ap, long *)) = retval;
785 *(va_arg(ap, size_t *)) = retval;
787 *(va_arg(ap, short *)) = retval;
789 *(va_arg(ap, char *)) = retval;
791 *(va_arg(ap, int *)) = retval;
798 sharpflag = (width == 0);
800 num = (uintptr_t)va_arg(ap, void *);
811 p = va_arg(ap, char *);
817 for (n = 0; n < dwidth && p[n]; n++)
822 if (!ladjust && width > 0)
827 if (ladjust && width > 0)
852 num = va_arg(ap, uintmax_t);
854 num = va_arg(ap, u_quad_t);
856 num = va_arg(ap, ptrdiff_t);
858 num = va_arg(ap, u_long);
860 num = va_arg(ap, size_t);
862 num = (u_short)va_arg(ap, int);
864 num = (u_char)va_arg(ap, int);
866 num = va_arg(ap, u_int);
868 q = va_arg(ap, char *);
874 num = va_arg(ap, intmax_t);
876 num = va_arg(ap, quad_t);
878 num = va_arg(ap, ptrdiff_t);
880 num = va_arg(ap, long);
882 num = va_arg(ap, ssize_t);
884 num = (short)va_arg(ap, int);
886 num = (char)va_arg(ap, int);
888 num = va_arg(ap, int);
890 if (sign && (intmax_t)num < 0) {
892 num = -(intmax_t)num;
894 p = ksprintn(nbuf, num, base, &n, upper);
896 if (sharpflag && num != 0) {
905 if (!ladjust && padc == '0')
906 dwidth = width - tmp;
907 width -= tmp + imax(dwidth, n);
914 if (sharpflag && num != 0) {
917 } else if (base == 16) {
928 if (bconv && num != 0) {
929 /* %b conversion flag format. */
933 if (num & (1 << (n - 1))) {
934 PCHAR(retval != tmp ?
936 for (; (n = *q) > ' '; ++q)
939 for (; *q > ' '; ++q)
944 width -= retval - tmp;
954 while (percent < fmt)
957 * Since we ignore a formatting argument it is no
958 * longer safe to obey the remaining formatting
959 * arguments as the arguments will no longer match
970 * Put character in log buffer with a particular priority.
973 msglogchar(int c, int pri)
975 static int lastpri = -1;
982 if (c == '\0' || c == '\r')
984 if (pri != -1 && pri != lastpri) {
986 msgbuf_addchar(msgbufp, '\n');
989 msgbuf_addchar(msgbufp, '<');
990 for (p = ksprintn(nbuf, (uintmax_t)pri, 10, NULL, 0); *p;)
991 msgbuf_addchar(msgbufp, *p--);
992 msgbuf_addchar(msgbufp, '>');
995 msgbuf_addchar(msgbufp, c);
1005 msglogstr(char *str, int pri, int filter_cr)
1010 msgbuf_addstr(msgbufp, pri, str, filter_cr);
1014 msgbufinit(void *ptr, int size)
1017 static struct msgbuf *oldp = NULL;
1018 bool print_boot_tag;
1020 size -= sizeof(*msgbufp);
1022 print_boot_tag = !msgbufmapped;
1023 /* Attempt to fetch kern.boot_tag tunable on first mapping */
1025 TUNABLE_STR_FETCH("kern.boot_tag", current_boot_tag,
1026 sizeof(current_boot_tag));
1027 msgbufp = (struct msgbuf *)(cp + size);
1028 msgbuf_reinit(msgbufp, cp, size);
1029 if (msgbufmapped && oldp != msgbufp)
1030 msgbuf_copy(oldp, msgbufp);
1031 msgbufmapped = true;
1032 if (print_boot_tag && *current_boot_tag != '\0')
1033 printf("%s\n", current_boot_tag);
1037 /* Sysctls for accessing/clearing the msgbuf */
1039 sysctl_kern_msgbuf(SYSCTL_HANDLER_ARGS)
1045 error = priv_check(req->td, PRIV_MSGBUF);
1049 /* Read the whole buffer, one chunk at a time. */
1050 mtx_lock(&msgbuf_lock);
1051 msgbuf_peekbytes(msgbufp, NULL, 0, &seq);
1053 len = msgbuf_peekbytes(msgbufp, buf, sizeof(buf), &seq);
1054 mtx_unlock(&msgbuf_lock);
1056 return (SYSCTL_OUT(req, "", 1)); /* add nulterm */
1058 error = sysctl_handle_opaque(oidp, buf, len, req);
1062 mtx_lock(&msgbuf_lock);
1066 SYSCTL_PROC(_kern, OID_AUTO, msgbuf,
1067 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1068 NULL, 0, sysctl_kern_msgbuf, "A", "Contents of kernel message buffer");
1070 static int msgbuf_clearflag;
1073 sysctl_kern_msgbuf_clear(SYSCTL_HANDLER_ARGS)
1076 error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req);
1077 if (!error && req->newptr) {
1078 mtx_lock(&msgbuf_lock);
1079 msgbuf_clear(msgbufp);
1080 mtx_unlock(&msgbuf_lock);
1081 msgbuf_clearflag = 0;
1086 SYSCTL_PROC(_kern, OID_AUTO, msgbuf_clear,
1087 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE | CTLFLAG_MPSAFE,
1088 &msgbuf_clearflag, 0, sysctl_kern_msgbuf_clear, "I",
1089 "Clear kernel message buffer");
1093 DB_SHOW_COMMAND(msgbuf, db_show_msgbuf)
1097 if (!msgbufmapped) {
1098 db_printf("msgbuf not mapped yet\n");
1101 db_printf("msgbufp = %p\n", msgbufp);
1102 db_printf("magic = %x, size = %d, r= %u, w = %u, ptr = %p, cksum= %u\n",
1103 msgbufp->msg_magic, msgbufp->msg_size, msgbufp->msg_rseq,
1104 msgbufp->msg_wseq, msgbufp->msg_ptr, msgbufp->msg_cksum);
1105 for (i = 0; i < msgbufp->msg_size && !db_pager_quit; i++) {
1106 j = MSGBUF_SEQ_TO_POS(msgbufp, i + msgbufp->msg_rseq);
1107 db_printf("%c", msgbufp->msg_ptr[j]);
1115 hexdump(const void *ptr, int length, const char *hdr, int flags)
1119 const unsigned char *cp;
1122 if ((flags & HD_DELIM_MASK) != 0)
1123 delim = (flags & HD_DELIM_MASK) >> 8;
1127 if ((flags & HD_COLUMN_MASK) != 0)
1128 cols = flags & HD_COLUMN_MASK;
1133 for (i = 0; i < length; i+= cols) {
1137 if ((flags & HD_OMIT_COUNT) == 0)
1140 if ((flags & HD_OMIT_HEX) == 0) {
1141 for (j = 0; j < cols; j++) {
1144 printf("%c%02x", delim, cp[k]);
1150 if ((flags & HD_OMIT_CHARS) == 0) {
1152 for (j = 0; j < cols; j++) {
1156 else if (cp[k] >= ' ' && cp[k] <= '~')
1157 printf("%c", cp[k]);
1166 #endif /* _KERNEL */
1169 sbuf_hexdump(struct sbuf *sb, const void *ptr, int length, const char *hdr,
1174 const unsigned char *cp;
1177 if ((flags & HD_DELIM_MASK) != 0)
1178 delim = (flags & HD_DELIM_MASK) >> 8;
1182 if ((flags & HD_COLUMN_MASK) != 0)
1183 cols = flags & HD_COLUMN_MASK;
1188 for (i = 0; i < length; i+= cols) {
1190 sbuf_printf(sb, "%s", hdr);
1192 if ((flags & HD_OMIT_COUNT) == 0)
1193 sbuf_printf(sb, "%04x ", i);
1195 if ((flags & HD_OMIT_HEX) == 0) {
1196 for (j = 0; j < cols; j++) {
1199 sbuf_printf(sb, "%c%02x", delim, cp[k]);
1201 sbuf_printf(sb, " ");
1205 if ((flags & HD_OMIT_CHARS) == 0) {
1206 sbuf_printf(sb, " |");
1207 for (j = 0; j < cols; j++) {
1210 sbuf_printf(sb, " ");
1211 else if (cp[k] >= ' ' && cp[k] <= '~')
1212 sbuf_printf(sb, "%c", cp[k]);
1214 sbuf_printf(sb, ".");
1216 sbuf_printf(sb, "|");
1218 sbuf_printf(sb, "\n");
1224 counted_warning(unsigned *counter, const char *msg)
1233 if (atomic_cmpset_int(counter, c, c - 1)) {
1235 log(LOG_INFO, "pid %d (%s) %s%s\n",
1236 td->td_proc->p_pid, td->td_name, msg,
1237 c > 1 ? "" : " - not logging anymore");
1246 sbuf_putbuf(struct sbuf *sb)
1249 prf_putbuf(sbuf_data(sb), TOLOG | TOCONS, -1);
1253 sbuf_putbuf(struct sbuf *sb)
1256 printf("%s", sbuf_data(sb));
1261 sbuf_printf_drain(void *arg, const char *data, int len)
1270 * This is allowed as an extra byte is always resvered for
1271 * terminating NUL byte. Save and restore the byte because
1272 * we might be flushing a record, and there may be valid
1273 * data after the buffer.
1276 dataptr = __DECONST(char *, data);
1277 dataptr[len] = '\0';
1279 prf_putbuf(dataptr, TOLOG | TOCONS, -1);
1282 dataptr[len] = oldchr;
1284 #else /* !_KERNEL */
1286 r = printf("%.*s", len, data);
1293 if (retvalptr != NULL)