2 * Copyright (c) 1986, 1988, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
42 #include "opt_printf.h"
45 #include <sys/param.h>
47 #include <sys/systm.h>
50 #include <sys/mutex.h>
52 #include <sys/kernel.h>
53 #include <sys/msgbuf.h>
54 #include <sys/malloc.h>
57 #include <sys/stddef.h>
58 #include <sys/sysctl.h>
60 #include <sys/syslog.h>
64 #include <sys/ctype.h>
72 * Note that stdarg.h and the ANSI style va_start macro is used for both
73 * ANSI and traditional C compilers.
76 #include <machine/stdarg.h>
82 * This is needed for sbuf_putbuf() when compiled into userland. Due to the
83 * shared nature of this file, it's the only place to put it.
95 /* Max number conversion buffer length: a u_quad_t in base 2, plus NUL byte. */
96 #define MAXNBUF (sizeof(intmax_t) * NBBY + 1)
108 struct snprintf_arg {
115 static void msglogchar(int c, int pri);
116 static void msglogstr(char *str, int pri, int filter_cr);
117 static void putchar(int ch, void *arg);
118 static char *ksprintn(char *nbuf, uintmax_t num, int base, int *len, int upper);
119 static void snprintf_func(int ch, void *arg);
121 static bool msgbufmapped; /* Set when safe to use msgbuf */
125 #define BOOT_TAG_SZ 32
128 /* Tag used to mark the start of a boot in dmesg */
132 static char current_boot_tag[BOOT_TAG_SZ + 1] = BOOT_TAG;
133 SYSCTL_STRING(_kern, OID_AUTO, boot_tag, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
134 current_boot_tag, 0, "Tag added to dmesg at start of boot");
136 static int log_console_output = 1;
137 SYSCTL_INT(_kern, OID_AUTO, log_console_output, CTLFLAG_RWTUN,
138 &log_console_output, 0, "Duplicate console output to the syslog");
141 * See the comment in log_console() below for more explanation of this.
143 static int log_console_add_linefeed;
144 SYSCTL_INT(_kern, OID_AUTO, log_console_add_linefeed, CTLFLAG_RWTUN,
145 &log_console_add_linefeed, 0, "log_console() adds extra newlines");
147 static int always_console_output;
148 SYSCTL_INT(_kern, OID_AUTO, always_console_output, CTLFLAG_RWTUN,
149 &always_console_output, 0, "Always output to console despite TIOCCONS");
152 * Warn that a system table is full.
155 tablefull(const char *tab)
158 log(LOG_ERR, "%s: table is full\n", tab);
162 * Uprintf prints to the controlling terminal for the current process.
165 uprintf(const char *fmt, ...)
168 struct putchar_arg pca;
174 if (TD_IS_IDLETHREAD(td))
177 sx_slock(&proctree_lock);
180 if ((p->p_flag & P_CONTROLT) == 0) {
182 sx_sunlock(&proctree_lock);
185 SESS_LOCK(p->p_session);
186 pca.tty = p->p_session->s_ttyp;
187 SESS_UNLOCK(p->p_session);
189 if (pca.tty == NULL) {
190 sx_sunlock(&proctree_lock);
197 sx_sunlock(&proctree_lock);
198 retval = kvprintf(fmt, putchar, &pca, 10, ap);
205 * tprintf and vtprintf print on the controlling terminal associated with the
206 * given session, possibly to the log as well.
209 tprintf(struct proc *p, int pri, const char *fmt, ...)
214 vtprintf(p, pri, fmt, ap);
219 vtprintf(struct proc *p, int pri, const char *fmt, va_list ap)
221 struct tty *tp = NULL;
223 struct putchar_arg pca;
224 struct session *sess = NULL;
226 sx_slock(&proctree_lock);
231 if (p->p_flag & P_CONTROLT && p->p_session->s_ttyvp) {
236 if (tp != NULL && tty_checkoutq(tp))
249 sx_sunlock(&proctree_lock);
250 kvprintf(fmt, putchar, &pca, 10, ap);
259 * Ttyprintf displays a message on a tty; it should be used only by
260 * the tty driver, or anything that knows the underlying tty will not
261 * be revoke(2)'d away. Other callers should use tprintf.
264 ttyprintf(struct tty *tp, const char *fmt, ...)
267 struct putchar_arg pca;
274 retval = kvprintf(fmt, putchar, &pca, 10, ap);
280 _vprintf(int level, int flags, const char *fmt, va_list ap)
282 struct putchar_arg pca;
284 #ifdef PRINTF_BUFR_SIZE
285 char bufr[PRINTF_BUFR_SIZE];
291 #ifdef PRINTF_BUFR_SIZE
293 pca.p_next = pca.p_bufr;
294 pca.n_bufr = sizeof(bufr);
295 pca.remain = sizeof(bufr);
298 /* Don't buffer console output. */
302 retval = kvprintf(fmt, putchar, &pca, 10, ap);
304 #ifdef PRINTF_BUFR_SIZE
305 /* Write any buffered console/log output: */
306 if (*pca.p_bufr != '\0') {
307 if (pca.flags & TOLOG)
308 msglogstr(pca.p_bufr, level, /*filter_cr*/1);
310 if (pca.flags & TOCONS)
319 * Log writes to the log buffer, and guarantees not to sleep (so can be
320 * called by interrupt routines). If there is no process reading the
321 * log yet, it writes to the console also.
324 log(int level, const char *fmt, ...)
329 vlog(level, fmt, ap);
334 vlog(int level, const char *fmt, va_list ap)
337 (void)_vprintf(level, log_open ? TOLOG : TOCONS | TOLOG, fmt, ap);
341 #define CONSCHUNK 128
344 log_console(struct uio *uio)
350 if (!log_console_output)
353 pri = LOG_INFO | LOG_CONSOLE;
355 consbuffer = malloc(CONSCHUNK, M_TEMP, M_WAITOK);
358 while (uio->uio_resid > 0) {
359 c = imin(uio->uio_resid, CONSCHUNK - 1);
360 error = uiomove(consbuffer, c, uio);
363 /* Make sure we're NUL-terminated */
364 consbuffer[c] = '\0';
365 if (consbuffer[c - 1] == '\n')
369 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
372 * The previous behavior in log_console() is preserved when
373 * log_console_add_linefeed is non-zero. For that behavior, if an
374 * individual console write came in that was not terminated with a
375 * line feed, it would add a line feed.
377 * This results in different data in the message buffer than
378 * appears on the system console (which doesn't add extra line feed
381 * A number of programs and rc scripts write a line feed, or a period
382 * and a line feed when they have completed their operation. On
383 * the console, this looks seamless, but when displayed with
384 * 'dmesg -a', you wind up with output that looks like this:
389 * On the console, it looks like this:
392 * We could add logic to detect that situation, or just not insert
393 * the extra newlines. Set the kern.log_console_add_linefeed
394 * sysctl/tunable variable to get the old behavior.
396 if (!nl && log_console_add_linefeed) {
397 consbuffer[0] = '\n';
398 consbuffer[1] = '\0';
399 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
403 free(consbuffer, M_TEMP);
407 printf(const char *fmt, ...)
413 retval = vprintf(fmt, ap);
420 vprintf(const char *fmt, va_list ap)
424 retval = _vprintf(-1, TOCONS | TOLOG, fmt, ap);
433 prf_putbuf(char *bufr, int flags, int pri)
437 msglogstr(bufr, pri, /*filter_cr*/1);
439 if (flags & TOCONS) {
440 if ((panicstr == NULL) && (constty != NULL))
441 msgbuf_addstr(&consmsgbuf, -1,
442 bufr, /*filter_cr*/ 0);
444 if ((constty == NULL) ||(always_console_output))
450 putbuf(int c, struct putchar_arg *ap)
452 /* Check if no console output buffer was provided. */
453 if (ap->p_bufr == NULL) {
454 /* Output direct to the console. */
455 if (ap->flags & TOCONS)
458 if (ap->flags & TOLOG)
459 msglogchar(c, ap->pri);
461 /* Buffer the character: */
465 /* Always leave the buffer zero terminated. */
468 /* Check if the buffer needs to be flushed. */
469 if (ap->remain == 2 || c == '\n') {
470 prf_putbuf(ap->p_bufr, ap->flags, ap->pri);
472 ap->p_next = ap->p_bufr;
473 ap->remain = ap->n_bufr;
478 * Since we fill the buffer up one character at a time,
479 * this should not happen. We should always catch it when
480 * ap->remain == 2 (if not sooner due to a newline), flush
481 * the buffer and move on. One way this could happen is
482 * if someone sets PRINTF_BUFR_SIZE to 1 or something
485 KASSERT(ap->remain > 2, ("Bad buffer logic, remain = %zd",
491 * Print a character on console or users terminal. If destination is
492 * the console then the last bunch of characters are saved in msgbuf for
496 putchar(int c, void *arg)
498 struct putchar_arg *ap = (struct putchar_arg*) arg;
499 struct tty *tp = ap->tty;
500 int flags = ap->flags;
502 /* Don't use the tty code after a panic or while in ddb. */
509 if ((flags & TOTTY) && tp != NULL && panicstr == NULL)
512 if ((flags & (TOCONS | TOLOG)) && c != '\0')
517 * Scaled down version of sprintf(3).
520 sprintf(char *buf, const char *cfmt, ...)
526 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
533 * Scaled down version of vsprintf(3).
536 vsprintf(char *buf, const char *cfmt, va_list ap)
540 retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
546 * Scaled down version of snprintf(3).
549 snprintf(char *str, size_t size, const char *format, ...)
554 va_start(ap, format);
555 retval = vsnprintf(str, size, format, ap);
561 * Scaled down version of vsnprintf(3).
564 vsnprintf(char *str, size_t size, const char *format, va_list ap)
566 struct snprintf_arg info;
571 retval = kvprintf(format, snprintf_func, &info, 10, ap);
572 if (info.remain >= 1)
578 * Kernel version which takes radix argument vsnprintf(3).
581 vsnrprintf(char *str, size_t size, int radix, const char *format, va_list ap)
583 struct snprintf_arg info;
588 retval = kvprintf(format, snprintf_func, &info, radix, ap);
589 if (info.remain >= 1)
595 snprintf_func(int ch, void *arg)
597 struct snprintf_arg *const info = arg;
599 if (info->remain >= 2) {
606 * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse
607 * order; return an optional length and a pointer to the last character
608 * written in the buffer (i.e., the first character of the string).
609 * The buffer pointed to by `nbuf' must have length >= MAXNBUF.
612 ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
619 c = hex2ascii(num % base);
620 *++p = upper ? toupper(c) : c;
621 } while (num /= base);
628 * Scaled down version of printf(3).
630 * Two additional formats:
632 * The format %b is supported to decode error registers.
635 * printf("reg=%b\n", regval, "<base><arg>*");
637 * where <base> is the output base expressed as a control character, e.g.
638 * \10 gives octal; \20 gives hex. Each arg is a sequence of characters,
639 * the first of which gives the bit number to be inspected (origin 1), and
640 * the next characters (up to a control character, i.e. a character <= 32),
641 * give the name of the register. Thus:
643 * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE");
645 * would produce output:
647 * reg=3<BITTWO,BITONE>
649 * XXX: %D -- Hexdump, takes pointer and separator string:
650 * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX
651 * ("%*D", len, ptr, " " -> XX XX XX XX ...
654 kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_list ap)
656 #define PCHAR(c) {int cc=(c); if (func) (*func)(cc,arg); else *d++ = cc; retval++; }
659 const char *p, *percent, *q;
663 int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot;
664 int cflag, hflag, jflag, tflag, zflag;
667 int stop = 0, retval = 0;
676 fmt = "(fmt null)\n";
678 if (radix < 2 || radix > 36)
684 while ((ch = (u_char)*fmt++) != '%' || stop) {
690 qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0;
691 sign = 0; dot = 0; dwidth = 0; upper = 0;
692 cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0;
693 reswitch: switch (ch = (u_char)*fmt++) {
711 width = va_arg(ap, int);
717 dwidth = va_arg(ap, int);
726 case '1': case '2': case '3': case '4':
727 case '5': case '6': case '7': case '8': case '9':
728 for (n = 0;; ++fmt) {
729 n = n * 10 + ch - '0';
731 if (ch < '0' || ch > '9')
740 num = (u_int)va_arg(ap, int);
741 p = va_arg(ap, char *);
742 for (q = ksprintn(nbuf, num, *p++, NULL, 0); *q;)
750 if (num & (1 << (n - 1))) {
751 PCHAR(tmp ? ',' : '<');
752 for (; (n = *p) > ' '; ++p)
756 for (; *p > ' '; ++p)
765 if (!ladjust && width > 0)
768 PCHAR(va_arg(ap, int));
769 if (ladjust && width > 0)
774 up = va_arg(ap, u_char *);
775 p = va_arg(ap, char *);
779 PCHAR(hex2ascii(*up >> 4));
780 PCHAR(hex2ascii(*up & 0x0f));
811 *(va_arg(ap, intmax_t *)) = retval;
813 *(va_arg(ap, quad_t *)) = retval;
815 *(va_arg(ap, long *)) = retval;
817 *(va_arg(ap, size_t *)) = retval;
819 *(va_arg(ap, short *)) = retval;
821 *(va_arg(ap, char *)) = retval;
823 *(va_arg(ap, int *)) = retval;
830 sharpflag = (width == 0);
832 num = (uintptr_t)va_arg(ap, void *);
843 p = va_arg(ap, char *);
849 for (n = 0; n < dwidth && p[n]; n++)
854 if (!ladjust && width > 0)
859 if (ladjust && width > 0)
884 num = va_arg(ap, uintmax_t);
886 num = va_arg(ap, u_quad_t);
888 num = va_arg(ap, ptrdiff_t);
890 num = va_arg(ap, u_long);
892 num = va_arg(ap, size_t);
894 num = (u_short)va_arg(ap, int);
896 num = (u_char)va_arg(ap, int);
898 num = va_arg(ap, u_int);
902 num = va_arg(ap, intmax_t);
904 num = va_arg(ap, quad_t);
906 num = va_arg(ap, ptrdiff_t);
908 num = va_arg(ap, long);
910 num = va_arg(ap, ssize_t);
912 num = (short)va_arg(ap, int);
914 num = (char)va_arg(ap, int);
916 num = va_arg(ap, int);
918 if (sign && (intmax_t)num < 0) {
920 num = -(intmax_t)num;
922 p = ksprintn(nbuf, num, base, &n, upper);
924 if (sharpflag && num != 0) {
933 if (!ladjust && padc == '0')
934 dwidth = width - tmp;
935 width -= tmp + imax(dwidth, n);
942 if (sharpflag && num != 0) {
945 } else if (base == 16) {
962 while (percent < fmt)
965 * Since we ignore a formatting argument it is no
966 * longer safe to obey the remaining formatting
967 * arguments as the arguments will no longer match
978 * Put character in log buffer with a particular priority.
981 msglogchar(int c, int pri)
983 static int lastpri = -1;
990 if (c == '\0' || c == '\r')
992 if (pri != -1 && pri != lastpri) {
994 msgbuf_addchar(msgbufp, '\n');
997 msgbuf_addchar(msgbufp, '<');
998 for (p = ksprintn(nbuf, (uintmax_t)pri, 10, NULL, 0); *p;)
999 msgbuf_addchar(msgbufp, *p--);
1000 msgbuf_addchar(msgbufp, '>');
1003 msgbuf_addchar(msgbufp, c);
1013 msglogstr(char *str, int pri, int filter_cr)
1018 msgbuf_addstr(msgbufp, pri, str, filter_cr);
1022 msgbufinit(void *ptr, int size)
1025 static struct msgbuf *oldp = NULL;
1026 bool print_boot_tag;
1028 size -= sizeof(*msgbufp);
1030 print_boot_tag = !msgbufmapped;
1031 /* Attempt to fetch kern.boot_tag tunable on first mapping */
1033 TUNABLE_STR_FETCH("kern.boot_tag", current_boot_tag,
1034 sizeof(current_boot_tag));
1035 msgbufp = (struct msgbuf *)(cp + size);
1036 msgbuf_reinit(msgbufp, cp, size);
1037 if (msgbufmapped && oldp != msgbufp)
1038 msgbuf_copy(oldp, msgbufp);
1039 msgbufmapped = true;
1040 if (print_boot_tag && *current_boot_tag != '\0')
1041 printf("%s\n", current_boot_tag);
1045 /* Sysctls for accessing/clearing the msgbuf */
1047 sysctl_kern_msgbuf(SYSCTL_HANDLER_ARGS)
1053 error = priv_check(req->td, PRIV_MSGBUF);
1057 /* Read the whole buffer, one chunk at a time. */
1058 mtx_lock(&msgbuf_lock);
1059 msgbuf_peekbytes(msgbufp, NULL, 0, &seq);
1061 len = msgbuf_peekbytes(msgbufp, buf, sizeof(buf), &seq);
1062 mtx_unlock(&msgbuf_lock);
1064 return (SYSCTL_OUT(req, "", 1)); /* add nulterm */
1066 error = sysctl_handle_opaque(oidp, buf, len, req);
1070 mtx_lock(&msgbuf_lock);
1074 SYSCTL_PROC(_kern, OID_AUTO, msgbuf,
1075 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1076 NULL, 0, sysctl_kern_msgbuf, "A", "Contents of kernel message buffer");
1078 static int msgbuf_clearflag;
1081 sysctl_kern_msgbuf_clear(SYSCTL_HANDLER_ARGS)
1084 error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req);
1085 if (!error && req->newptr) {
1086 mtx_lock(&msgbuf_lock);
1087 msgbuf_clear(msgbufp);
1088 mtx_unlock(&msgbuf_lock);
1089 msgbuf_clearflag = 0;
1094 SYSCTL_PROC(_kern, OID_AUTO, msgbuf_clear,
1095 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE | CTLFLAG_MPSAFE,
1096 &msgbuf_clearflag, 0, sysctl_kern_msgbuf_clear, "I",
1097 "Clear kernel message buffer");
1101 DB_SHOW_COMMAND(msgbuf, db_show_msgbuf)
1105 if (!msgbufmapped) {
1106 db_printf("msgbuf not mapped yet\n");
1109 db_printf("msgbufp = %p\n", msgbufp);
1110 db_printf("magic = %x, size = %d, r= %u, w = %u, ptr = %p, cksum= %u\n",
1111 msgbufp->msg_magic, msgbufp->msg_size, msgbufp->msg_rseq,
1112 msgbufp->msg_wseq, msgbufp->msg_ptr, msgbufp->msg_cksum);
1113 for (i = 0; i < msgbufp->msg_size && !db_pager_quit; i++) {
1114 j = MSGBUF_SEQ_TO_POS(msgbufp, i + msgbufp->msg_rseq);
1115 db_printf("%c", msgbufp->msg_ptr[j]);
1123 hexdump(const void *ptr, int length, const char *hdr, int flags)
1127 const unsigned char *cp;
1130 if ((flags & HD_DELIM_MASK) != 0)
1131 delim = (flags & HD_DELIM_MASK) >> 8;
1135 if ((flags & HD_COLUMN_MASK) != 0)
1136 cols = flags & HD_COLUMN_MASK;
1141 for (i = 0; i < length; i+= cols) {
1145 if ((flags & HD_OMIT_COUNT) == 0)
1148 if ((flags & HD_OMIT_HEX) == 0) {
1149 for (j = 0; j < cols; j++) {
1152 printf("%c%02x", delim, cp[k]);
1158 if ((flags & HD_OMIT_CHARS) == 0) {
1160 for (j = 0; j < cols; j++) {
1164 else if (cp[k] >= ' ' && cp[k] <= '~')
1165 printf("%c", cp[k]);
1174 #endif /* _KERNEL */
1177 sbuf_hexdump(struct sbuf *sb, const void *ptr, int length, const char *hdr,
1182 const unsigned char *cp;
1185 if ((flags & HD_DELIM_MASK) != 0)
1186 delim = (flags & HD_DELIM_MASK) >> 8;
1190 if ((flags & HD_COLUMN_MASK) != 0)
1191 cols = flags & HD_COLUMN_MASK;
1196 for (i = 0; i < length; i+= cols) {
1198 sbuf_printf(sb, "%s", hdr);
1200 if ((flags & HD_OMIT_COUNT) == 0)
1201 sbuf_printf(sb, "%04x ", i);
1203 if ((flags & HD_OMIT_HEX) == 0) {
1204 for (j = 0; j < cols; j++) {
1207 sbuf_printf(sb, "%c%02x", delim, cp[k]);
1209 sbuf_printf(sb, " ");
1213 if ((flags & HD_OMIT_CHARS) == 0) {
1214 sbuf_printf(sb, " |");
1215 for (j = 0; j < cols; j++) {
1218 sbuf_printf(sb, " ");
1219 else if (cp[k] >= ' ' && cp[k] <= '~')
1220 sbuf_printf(sb, "%c", cp[k]);
1222 sbuf_printf(sb, ".");
1224 sbuf_printf(sb, "|");
1226 sbuf_printf(sb, "\n");
1232 counted_warning(unsigned *counter, const char *msg)
1241 if (atomic_cmpset_int(counter, c, c - 1)) {
1243 log(LOG_INFO, "pid %d (%s) %s%s\n",
1244 td->td_proc->p_pid, td->td_name, msg,
1245 c > 1 ? "" : " - not logging anymore");
1254 sbuf_putbuf(struct sbuf *sb)
1257 prf_putbuf(sbuf_data(sb), TOLOG | TOCONS, -1);
1261 sbuf_putbuf(struct sbuf *sb)
1264 printf("%s", sbuf_data(sb));