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 prf_putbuf(char *bufr, int flags, int pri);
122 static void putchar(int ch, void *arg);
123 static char *ksprintn(char *nbuf, uintmax_t num, int base, int *len, int upper);
124 static void snprintf_func(int ch, void *arg);
126 static bool msgbufmapped; /* Set when safe to use msgbuf */
128 struct msgbuf *msgbufp;
131 #define BOOT_TAG_SZ 32
134 /* Tag used to mark the start of a boot in dmesg */
135 #define BOOT_TAG "---<<BOOT>>---"
138 static char current_boot_tag[BOOT_TAG_SZ + 1] = BOOT_TAG;
139 SYSCTL_STRING(_kern, OID_AUTO, boot_tag, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
140 current_boot_tag, 0, "Tag added to dmesg at start of boot");
142 static int log_console_output = 1;
143 SYSCTL_INT(_kern, OID_AUTO, log_console_output, CTLFLAG_RWTUN,
144 &log_console_output, 0, "Duplicate console output to the syslog");
147 * See the comment in log_console() below for more explanation of this.
149 static int log_console_add_linefeed;
150 SYSCTL_INT(_kern, OID_AUTO, log_console_add_linefeed, CTLFLAG_RWTUN,
151 &log_console_add_linefeed, 0, "log_console() adds extra newlines");
153 static int always_console_output;
154 SYSCTL_INT(_kern, OID_AUTO, always_console_output, CTLFLAG_RWTUN,
155 &always_console_output, 0, "Always output to console despite TIOCCONS");
158 * Warn that a system table is full.
161 tablefull(const char *tab)
164 log(LOG_ERR, "%s: table is full\n", tab);
168 * Uprintf prints to the controlling terminal for the current process.
171 uprintf(const char *fmt, ...)
174 struct putchar_arg pca;
180 if (TD_IS_IDLETHREAD(td))
183 if (td->td_proc == initproc) {
184 /* Produce output when we fail to load /sbin/init: */
186 retval = vprintf(fmt, ap);
191 sx_slock(&proctree_lock);
194 if ((p->p_flag & P_CONTROLT) == 0) {
196 sx_sunlock(&proctree_lock);
199 SESS_LOCK(p->p_session);
200 pca.tty = p->p_session->s_ttyp;
201 SESS_UNLOCK(p->p_session);
203 if (pca.tty == NULL) {
204 sx_sunlock(&proctree_lock);
211 sx_sunlock(&proctree_lock);
212 retval = kvprintf(fmt, putchar, &pca, 10, ap);
219 * tprintf and vtprintf print on the controlling terminal associated with the
220 * given session, possibly to the log as well.
223 tprintf(struct proc *p, int pri, const char *fmt, ...)
228 vtprintf(p, pri, fmt, ap);
233 vtprintf(struct proc *p, int pri, const char *fmt, va_list ap)
235 struct tty *tp = NULL;
237 struct putchar_arg pca;
238 struct session *sess = NULL;
240 sx_slock(&proctree_lock);
245 if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
250 if (tp != NULL && tty_checkoutq(tp))
263 sx_sunlock(&proctree_lock);
264 kvprintf(fmt, putchar, &pca, 10, ap);
273 _vprintf(int level, int flags, const char *fmt, va_list ap)
275 struct putchar_arg pca;
277 #ifdef PRINTF_BUFR_SIZE
278 char bufr[PRINTF_BUFR_SIZE];
285 #ifdef PRINTF_BUFR_SIZE
287 pca.p_next = pca.p_bufr;
288 pca.n_bufr = sizeof(bufr);
289 pca.remain = sizeof(bufr);
292 /* Don't buffer console output. */
296 retval = kvprintf(fmt, putchar, &pca, 10, ap);
298 #ifdef PRINTF_BUFR_SIZE
299 /* Write any buffered console/log output: */
300 if (*pca.p_bufr != '\0')
301 prf_putbuf(pca.p_bufr, flags, level);
309 * Log writes to the log buffer, and guarantees not to sleep (so can be
310 * called by interrupt routines). If there is no process reading the
311 * log yet, it writes to the console also.
314 log(int level, const char *fmt, ...)
319 vlog(level, fmt, ap);
324 vlog(int level, const char *fmt, va_list ap)
327 (void)_vprintf(level, log_open ? TOLOG : TOCONS | TOLOG, fmt, ap);
331 #define CONSCHUNK 128
334 log_console(struct uio *uio)
340 if (!log_console_output)
343 pri = LOG_INFO | LOG_CONSOLE;
345 consbuffer = malloc(CONSCHUNK, M_TEMP, M_WAITOK);
348 while (uio->uio_resid > 0) {
349 c = imin(uio->uio_resid, CONSCHUNK - 1);
350 error = uiomove(consbuffer, c, uio);
353 /* Make sure we're NUL-terminated */
354 consbuffer[c] = '\0';
355 if (consbuffer[c - 1] == '\n')
359 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
362 * The previous behavior in log_console() is preserved when
363 * log_console_add_linefeed is non-zero. For that behavior, if an
364 * individual console write came in that was not terminated with a
365 * line feed, it would add a line feed.
367 * This results in different data in the message buffer than
368 * appears on the system console (which doesn't add extra line feed
371 * A number of programs and rc scripts write a line feed, or a period
372 * and a line feed when they have completed their operation. On
373 * the console, this looks seamless, but when displayed with
374 * 'dmesg -a', you wind up with output that looks like this:
379 * On the console, it looks like this:
382 * We could add logic to detect that situation, or just not insert
383 * the extra newlines. Set the kern.log_console_add_linefeed
384 * sysctl/tunable variable to get the old behavior.
386 if (!nl && log_console_add_linefeed) {
387 consbuffer[0] = '\n';
388 consbuffer[1] = '\0';
389 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
393 free(consbuffer, M_TEMP);
397 printf(const char *fmt, ...)
403 retval = vprintf(fmt, ap);
410 vprintf(const char *fmt, va_list ap)
414 retval = _vprintf(-1, TOCONS | TOLOG, fmt, ap);
416 if (!KERNEL_PANICKED())
423 prf_putchar(int c, int flags, int pri)
429 if (flags & TOCONS) {
430 if ((!KERNEL_PANICKED()) && (constty != NULL))
431 msgbuf_addchar(&consmsgbuf, c);
433 if ((constty == NULL) || always_console_output)
439 prf_putbuf(char *bufr, int flags, int pri)
443 msglogstr(bufr, pri, /*filter_cr*/1);
445 if (flags & TOCONS) {
446 if ((!KERNEL_PANICKED()) && (constty != NULL))
447 msgbuf_addstr(&consmsgbuf, -1,
448 bufr, /*filter_cr*/ 0);
450 if ((constty == NULL) || always_console_output)
456 putbuf(int c, struct putchar_arg *ap)
458 /* Check if no console output buffer was provided. */
459 if (ap->p_bufr == NULL) {
460 prf_putchar(c, ap->flags, ap->pri);
462 /* Buffer the character: */
466 /* Always leave the buffer zero terminated. */
469 /* Check if the buffer needs to be flushed. */
470 if (ap->remain == 2 || c == '\n') {
471 prf_putbuf(ap->p_bufr, ap->flags, ap->pri);
473 ap->p_next = ap->p_bufr;
474 ap->remain = ap->n_bufr;
479 * Since we fill the buffer up one character at a time,
480 * this should not happen. We should always catch it when
481 * ap->remain == 2 (if not sooner due to a newline), flush
482 * the buffer and move on. One way this could happen is
483 * if someone sets PRINTF_BUFR_SIZE to 1 or something
486 KASSERT(ap->remain > 2, ("Bad buffer logic, remain = %zd",
492 * Print a character on console or users terminal. If destination is
493 * the console then the last bunch of characters are saved in msgbuf for
497 putchar(int c, void *arg)
499 struct putchar_arg *ap = (struct putchar_arg*) arg;
500 struct tty *tp = ap->tty;
501 int flags = ap->flags;
503 /* Don't use the tty code after a panic or while in ddb. */
510 if ((flags & TOTTY) && tp != NULL && !KERNEL_PANICKED())
513 if ((flags & (TOCONS | TOLOG)) && c != '\0')
518 * Scaled down version of sprintf(3).
521 sprintf(char *buf, const char *cfmt, ...)
527 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
534 * Scaled down version of vsprintf(3).
537 vsprintf(char *buf, const char *cfmt, va_list ap)
541 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
547 * Scaled down version of snprintf(3).
550 snprintf(char *str, size_t size, const char *format, ...)
555 va_start(ap, format);
556 retval = vsnprintf(str, size, format, ap);
562 * Scaled down version of vsnprintf(3).
565 vsnprintf(char *str, size_t size, const char *format, va_list ap)
567 struct snprintf_arg info;
572 retval = kvprintf(format, snprintf_func, &info, 10, ap);
573 if (info.remain >= 1)
579 * Kernel version which takes radix argument vsnprintf(3).
582 vsnrprintf(char *str, size_t size, int radix, const char *format, va_list ap)
584 struct snprintf_arg info;
589 retval = kvprintf(format, snprintf_func, &info, radix, ap);
590 if (info.remain >= 1)
596 snprintf_func(int ch, void *arg)
598 struct snprintf_arg *const info = arg;
600 if (info->remain >= 2) {
607 * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse
608 * order; return an optional length and a pointer to the last character
609 * written in the buffer (i.e., the first character of the string).
610 * The buffer pointed to by `nbuf' must have length >= MAXNBUF.
613 ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
620 c = hex2ascii(num % base);
621 *++p = upper ? toupper(c) : c;
622 } while (num /= base);
629 * Scaled down version of printf(3).
631 * Two additional formats:
633 * The format %b is supported to decode error registers.
636 * printf("reg=%b\n", regval, "<base><arg>*");
638 * where <base> is the output base expressed as a control character, e.g.
639 * \10 gives octal; \20 gives hex. Each arg is a sequence of characters,
640 * the first of which gives the bit number to be inspected (origin 1), and
641 * the next characters (up to a control character, i.e. a character <= 32),
642 * give the name of the register. Thus:
644 * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE");
646 * would produce output:
648 * reg=3<BITTWO,BITONE>
650 * XXX: %D -- Hexdump, takes pointer and separator string:
651 * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX
652 * ("%*D", len, ptr, " " -> XX XX XX XX ...
655 kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_list ap)
657 #define PCHAR(c) {int cc=(c); if (func) (*func)(cc,arg); else *d++ = cc; retval++; }
660 const char *p, *percent, *q;
664 int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot;
665 int cflag, hflag, jflag, tflag, zflag;
666 int bconv, dwidth, upper;
668 int stop = 0, retval = 0;
678 fmt = "(fmt null)\n";
680 if (radix < 2 || radix > 36)
686 while ((ch = (u_char)*fmt++) != '%' || stop) {
692 qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0;
693 sign = 0; dot = 0; bconv = 0; dwidth = 0; upper = 0;
694 cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0;
695 reswitch: switch (ch = (u_char)*fmt++) {
713 width = va_arg(ap, int);
719 dwidth = va_arg(ap, int);
728 case '1': case '2': case '3': case '4':
729 case '5': case '6': case '7': case '8': case '9':
730 for (n = 0;; ++fmt) {
731 n = n * 10 + ch - '0';
733 if (ch < '0' || ch > '9')
748 if (!ladjust && width > 0)
751 PCHAR(va_arg(ap, int));
752 if (ladjust && width > 0)
757 up = va_arg(ap, u_char *);
758 p = va_arg(ap, char *);
762 PCHAR(hex2ascii(*up >> 4));
763 PCHAR(hex2ascii(*up & 0x0f));
794 * We do not support %n in kernel, but consume the
798 (void)va_arg(ap, intmax_t *);
800 (void)va_arg(ap, quad_t *);
802 (void)va_arg(ap, long *);
804 (void)va_arg(ap, size_t *);
806 (void)va_arg(ap, short *);
808 (void)va_arg(ap, char *);
810 (void)va_arg(ap, int *);
817 sharpflag = (width == 0);
819 num = (uintptr_t)va_arg(ap, void *);
830 p = va_arg(ap, char *);
836 for (n = 0; n < dwidth && p[n]; n++)
841 if (!ladjust && width > 0)
846 if (ladjust && width > 0)
872 num = va_arg(ap, uintmax_t);
874 num = va_arg(ap, u_quad_t);
876 num = va_arg(ap, ptrdiff_t);
878 num = va_arg(ap, u_long);
880 num = va_arg(ap, size_t);
882 num = (u_short)va_arg(ap, int);
884 num = (u_char)va_arg(ap, int);
886 num = va_arg(ap, u_int);
888 q = va_arg(ap, char *);
894 num = va_arg(ap, intmax_t);
896 num = va_arg(ap, quad_t);
898 num = va_arg(ap, ptrdiff_t);
900 num = va_arg(ap, long);
902 num = va_arg(ap, ssize_t);
904 num = (short)va_arg(ap, int);
906 num = (char)va_arg(ap, int);
908 num = va_arg(ap, int);
910 if (sign && (intmax_t)num < 0) {
912 num = -(intmax_t)num;
914 p = ksprintn(nbuf, num, base, &n, upper);
916 if (sharpflag && num != 0) {
925 if (!ladjust && padc == '0')
926 dwidth = width - tmp;
927 width -= tmp + imax(dwidth, n);
934 if (sharpflag && num != 0) {
937 } else if (base == 16) {
948 if (bconv && num != 0) {
949 /* %b conversion flag format. */
953 if (num & (1 << (n - 1))) {
954 PCHAR(retval != tmp ?
956 for (; (n = *q) > ' '; ++q)
959 for (; *q > ' '; ++q)
964 width -= retval - tmp;
974 while (percent < fmt)
977 * Since we ignore a formatting argument it is no
978 * longer safe to obey the remaining formatting
979 * arguments as the arguments will no longer match
990 * Put character in log buffer with a particular priority.
993 msglogchar(int c, int pri)
995 static int lastpri = -1;
1002 if (c == '\0' || c == '\r')
1004 if (pri != -1 && pri != lastpri) {
1006 msgbuf_addchar(msgbufp, '\n');
1009 msgbuf_addchar(msgbufp, '<');
1010 for (p = ksprintn(nbuf, (uintmax_t)pri, 10, NULL, 0); *p;)
1011 msgbuf_addchar(msgbufp, *p--);
1012 msgbuf_addchar(msgbufp, '>');
1015 msgbuf_addchar(msgbufp, c);
1025 msglogstr(char *str, int pri, int filter_cr)
1030 msgbuf_addstr(msgbufp, pri, str, filter_cr);
1034 msgbufinit(void *ptr, int size)
1037 static struct msgbuf *oldp = NULL;
1038 bool print_boot_tag;
1040 size -= sizeof(*msgbufp);
1042 print_boot_tag = !msgbufmapped;
1043 /* Attempt to fetch kern.boot_tag tunable on first mapping */
1045 TUNABLE_STR_FETCH("kern.boot_tag", current_boot_tag,
1046 sizeof(current_boot_tag));
1047 msgbufp = (struct msgbuf *)(cp + size);
1048 msgbuf_reinit(msgbufp, cp, size);
1049 if (msgbufmapped && oldp != msgbufp)
1050 msgbuf_copy(oldp, msgbufp);
1051 msgbufmapped = true;
1052 if (print_boot_tag && *current_boot_tag != '\0')
1053 printf("%s\n", current_boot_tag);
1057 /* Sysctls for accessing/clearing the msgbuf */
1059 sysctl_kern_msgbuf(SYSCTL_HANDLER_ARGS)
1065 error = priv_check(req->td, PRIV_MSGBUF);
1069 /* Read the whole buffer, one chunk at a time. */
1070 mtx_lock(&msgbuf_lock);
1071 msgbuf_peekbytes(msgbufp, NULL, 0, &seq);
1073 len = msgbuf_peekbytes(msgbufp, buf, sizeof(buf), &seq);
1074 mtx_unlock(&msgbuf_lock);
1076 return (SYSCTL_OUT(req, "", 1)); /* add nulterm */
1078 error = sysctl_handle_opaque(oidp, buf, len, req);
1082 mtx_lock(&msgbuf_lock);
1086 SYSCTL_PROC(_kern, OID_AUTO, msgbuf,
1087 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1088 NULL, 0, sysctl_kern_msgbuf, "A", "Contents of kernel message buffer");
1090 static int msgbuf_clearflag;
1093 sysctl_kern_msgbuf_clear(SYSCTL_HANDLER_ARGS)
1096 error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req);
1097 if (!error && req->newptr) {
1098 mtx_lock(&msgbuf_lock);
1099 msgbuf_clear(msgbufp);
1100 mtx_unlock(&msgbuf_lock);
1101 msgbuf_clearflag = 0;
1106 SYSCTL_PROC(_kern, OID_AUTO, msgbuf_clear,
1107 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE | CTLFLAG_MPSAFE,
1108 &msgbuf_clearflag, 0, sysctl_kern_msgbuf_clear, "I",
1109 "Clear kernel message buffer");
1113 DB_SHOW_COMMAND(msgbuf, db_show_msgbuf)
1117 if (!msgbufmapped) {
1118 db_printf("msgbuf not mapped yet\n");
1121 db_printf("msgbufp = %p\n", msgbufp);
1122 db_printf("magic = %x, size = %d, r= %u, w = %u, ptr = %p, cksum= %u\n",
1123 msgbufp->msg_magic, msgbufp->msg_size, msgbufp->msg_rseq,
1124 msgbufp->msg_wseq, msgbufp->msg_ptr, msgbufp->msg_cksum);
1125 for (i = 0; i < msgbufp->msg_size && !db_pager_quit; i++) {
1126 j = MSGBUF_SEQ_TO_POS(msgbufp, i + msgbufp->msg_rseq);
1127 db_printf("%c", msgbufp->msg_ptr[j]);
1135 hexdump(const void *ptr, int length, const char *hdr, int flags)
1139 const unsigned char *cp;
1142 if ((flags & HD_DELIM_MASK) != 0)
1143 delim = (flags & HD_DELIM_MASK) >> 8;
1147 if ((flags & HD_COLUMN_MASK) != 0)
1148 cols = flags & HD_COLUMN_MASK;
1153 for (i = 0; i < length; i+= cols) {
1157 if ((flags & HD_OMIT_COUNT) == 0)
1160 if ((flags & HD_OMIT_HEX) == 0) {
1161 for (j = 0; j < cols; j++) {
1164 printf("%c%02x", delim, cp[k]);
1170 if ((flags & HD_OMIT_CHARS) == 0) {
1172 for (j = 0; j < cols; j++) {
1176 else if (cp[k] >= ' ' && cp[k] <= '~')
1177 printf("%c", cp[k]);
1186 #endif /* _KERNEL */
1189 sbuf_hexdump(struct sbuf *sb, const void *ptr, int length, const char *hdr,
1194 const unsigned char *cp;
1197 if ((flags & HD_DELIM_MASK) != 0)
1198 delim = (flags & HD_DELIM_MASK) >> 8;
1202 if ((flags & HD_COLUMN_MASK) != 0)
1203 cols = flags & HD_COLUMN_MASK;
1208 for (i = 0; i < length; i+= cols) {
1210 sbuf_printf(sb, "%s", hdr);
1212 if ((flags & HD_OMIT_COUNT) == 0)
1213 sbuf_printf(sb, "%04x ", i);
1215 if ((flags & HD_OMIT_HEX) == 0) {
1216 for (j = 0; j < cols; j++) {
1219 sbuf_printf(sb, "%c%02x", delim, cp[k]);
1221 sbuf_printf(sb, " ");
1225 if ((flags & HD_OMIT_CHARS) == 0) {
1226 sbuf_printf(sb, " |");
1227 for (j = 0; j < cols; j++) {
1230 sbuf_printf(sb, " ");
1231 else if (cp[k] >= ' ' && cp[k] <= '~')
1232 sbuf_printf(sb, "%c", cp[k]);
1234 sbuf_printf(sb, ".");
1236 sbuf_printf(sb, "|");
1238 sbuf_printf(sb, "\n");
1244 counted_warning(unsigned *counter, const char *msg)
1253 if (atomic_cmpset_int(counter, c, c - 1)) {
1255 log(LOG_INFO, "pid %d (%s) %s%s\n",
1256 td->td_proc->p_pid, td->td_name, msg,
1257 c > 1 ? "" : " - not logging anymore");
1266 sbuf_putbuf(struct sbuf *sb)
1269 prf_putbuf(sbuf_data(sb), TOLOG | TOCONS, -1);
1273 sbuf_putbuf(struct sbuf *sb)
1276 printf("%s", sbuf_data(sb));
1281 sbuf_printf_drain(void *arg, const char *data, int len)
1290 * This is allowed as an extra byte is always resvered for
1291 * terminating NUL byte. Save and restore the byte because
1292 * we might be flushing a record, and there may be valid
1293 * data after the buffer.
1296 dataptr = __DECONST(char *, data);
1297 dataptr[len] = '\0';
1299 prf_putbuf(dataptr, TOLOG | TOCONS, -1);
1302 dataptr[len] = oldchr;
1304 #else /* !_KERNEL */
1306 r = printf("%.*s", len, data);
1313 if (retvalptr != NULL)