Unify console output.

Without this change when virtual console enabled depending on buffer
presence and state different parts of output go to different consoles.

MFC after:	1 month
This commit is contained in:
Alexander Motin 2021-09-03 23:13:42 -04:00
parent bd6085c6ae
commit a264594d4f

View File

@ -118,6 +118,7 @@ extern int log_open;
static void msglogchar(int c, int pri); static void msglogchar(int c, int pri);
static void msglogstr(char *str, int pri, int filter_cr); static void msglogstr(char *str, int pri, int filter_cr);
static void prf_putbuf(char *bufr, int flags, int pri);
static void putchar(int ch, void *arg); static void putchar(int ch, void *arg);
static char *ksprintn(char *nbuf, uintmax_t num, int base, int *len, int upper); static char *ksprintn(char *nbuf, uintmax_t num, int base, int *len, int upper);
static void snprintf_func(int ch, void *arg); static void snprintf_func(int ch, void *arg);
@ -296,13 +297,8 @@ _vprintf(int level, int flags, const char *fmt, va_list ap)
#ifdef PRINTF_BUFR_SIZE #ifdef PRINTF_BUFR_SIZE
/* Write any buffered console/log output: */ /* Write any buffered console/log output: */
if (*pca.p_bufr != '\0') { if (*pca.p_bufr != '\0')
if (pca.flags & TOLOG) prf_putbuf(pca.p_bufr, flags, level);
msglogstr(pca.p_bufr, level, /*filter_cr*/1);
if (pca.flags & TOCONS)
cnputs(pca.p_bufr);
}
#endif #endif
TSEXIT(); TSEXIT();
@ -423,6 +419,22 @@ vprintf(const char *fmt, va_list ap)
return (retval); return (retval);
} }
static void
prf_putchar(int c, int flags, int pri)
{
if (flags & TOLOG)
msglogchar(c, pri);
if (flags & TOCONS) {
if ((!KERNEL_PANICKED()) && (constty != NULL))
msgbuf_addchar(&consmsgbuf, c);
if ((constty == NULL) || always_console_output)
cnputc(c);
}
}
static void static void
prf_putbuf(char *bufr, int flags, int pri) prf_putbuf(char *bufr, int flags, int pri)
{ {
@ -435,7 +447,7 @@ prf_putbuf(char *bufr, int flags, int pri)
msgbuf_addstr(&consmsgbuf, -1, msgbuf_addstr(&consmsgbuf, -1,
bufr, /*filter_cr*/ 0); bufr, /*filter_cr*/ 0);
if ((constty == NULL) ||(always_console_output)) if ((constty == NULL) || always_console_output)
cnputs(bufr); cnputs(bufr);
} }
} }
@ -445,12 +457,7 @@ putbuf(int c, struct putchar_arg *ap)
{ {
/* Check if no console output buffer was provided. */ /* Check if no console output buffer was provided. */
if (ap->p_bufr == NULL) { if (ap->p_bufr == NULL) {
/* Output direct to the console. */ prf_putchar(c, ap->flags, ap->pri);
if (ap->flags & TOCONS)
cnputc(c);
if (ap->flags & TOLOG)
msglogchar(c, ap->pri);
} else { } else {
/* Buffer the character: */ /* Buffer the character: */
*ap->p_next++ = c; *ap->p_next++ = c;