MCPcopy Create free account
hub / github.com/F-Stack/f-stack / log_console

Function log_console

freebsd/kern/subr_prf.c:337–398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335#define CONSCHUNK 128
336
337void
338log_console(struct uio *uio)
339{
340 int c, error, nl;
341 char *consbuffer;
342 int pri;
343
344 if (!log_console_output)
345 return;
346
347 pri = LOG_INFO | LOG_CONSOLE;
348 uio = cloneuio(uio);
349 consbuffer = malloc(CONSCHUNK, M_TEMP, M_WAITOK);
350
351 nl = 0;
352 while (uio->uio_resid > 0) {
353 c = imin(uio->uio_resid, CONSCHUNK - 1);
354 error = uiomove(consbuffer, c, uio);
355 if (error != 0)
356 break;
357 /* Make sure we're NUL-terminated */
358 consbuffer[c] = '\0';
359 if (consbuffer[c - 1] == '\n')
360 nl = 1;
361 else
362 nl = 0;
363 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
364 }
365 /*
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.
370 *
371 * This results in different data in the message buffer than
372 * appears on the system console (which doesn't add extra line feed
373 * characters).
374 *
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:
379 *
380 * Updating motd:
381 * .
382 *
383 * On the console, it looks like this:
384 * Updating motd:.
385 *
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.
389 */
390 if (!nl && log_console_add_linefeed) {
391 consbuffer[0] = '\n';
392 consbuffer[1] = '\0';
393 msglogstr(consbuffer, pri, /*filter_cr*/ 1);
394 }

Callers 1

ttyconsdev_writeFunction · 0.85

Calls 6

cloneuioFunction · 0.85
mallocFunction · 0.85
iminFunction · 0.85
msglogstrFunction · 0.85
uiomoveFunction · 0.70
freeFunction · 0.70

Tested by

no test coverage detected