DragonFly On-Line Manual Pages

Search: Section:  


KPRINTF(9)            DragonFly Kernel Developer's Manual           KPRINTF(9)

NAME

kprintf, ksprintf, ksnprintf, kvprintf, kvsprintf, kvsnprintf, krateprintf, tprintf, uprintf, log - formatted output conversion

SYNOPSIS

#include <sys/types.h> #include <sys/systm.h> int kprintf(const char *format, ...); int ksprintf(char *str, const char *format, ...); int ksnprintf(char *str, size_t size, const char *format, ...); int kvprintf(const char *format, __va_list ap); int kvsprintf(char *str, const char *format, __va_list ap); int kvsnprintf(char *str, size_t size, const char *format, __va_list ap); int krateprintf(struct krate *rate, const char *format, ...); int uprintf(const char *format, ...); #include <sys/tprintf.h> int tprintf(struct proc *p, int pri, const char *format, ...); #include <sys/syslog.h> int log(int pri, const char *format, ...);

DESCRIPTION

The kprintf family of functions are similar to the printf(3) family of functions. The different functions each use a different output stream. The uprintf() function outputs to the current process' controlling tty, while kprintf(), ksprintf(), ksnprintf(), kvprintf(), kvsprintf() and kvsnprintf() write to the console as well as to the logging facility. The tprintf() function outputs to the tty associated with the process p and the logging facility if pri is not -1. The log() function sends the message to the kernel logging facility, using the log level as indicated by pri. Each of these related functions use the format, str, size and ap parameters in the same manner as printf(3). However, the kprintf functions add another conversion specifier to format: The %pb%i identifier expects two arguments: an char * and a int. These are used as a register value and a print mask for decoding bitmasks. The print mask is made up of two parts: the base and the arguments. The base value is the output base expressed as an integer value; for example, \10 gives octal and \20 gives hexadecimal. The arguments are made up of a sequence of bit identifiers. Each bit identifier begins with an integer value which is the number of the bit (starting from 1) this identifier describes. The rest of the identifier is a string of characters containing the name of the bit. The string is terminated by either the bit number at the start of the next bit identifier or NUL for the last bit identifier. The log() function uses syslog(3) level values LOG_DEBUG through LOG_EMERG for its pri parameter (mistakenly called `priority' here). Alternatively, if a pri of -1 is given, the message will be appended to the last log message started by a previous call to log(). As these messages are generated by the kernel itself, the facility will always be LOG_KERN. The krateprintf() function is a rate controlled version of kprintf(). The freq member of the struct krate pointed to by rate must be initialized with the desired reporting frequency. A freq of 0 will result in no output. Initializing count to a negative value allows an initial burst.

RETURN VALUES

The kprintf(), ksprintf(), ksnprintf(), kvprintf(), kvsprintf(), kvsnprintf(), tprintf(), uprintf(), and log() functions return the number of characters displayed. The krateprintf() function returns 1 or 0, depending on whether anything was printed or not, allowing code to issue additional kprintf()s if desired.

LOADER TUNABLES

Tunables can be set at the loader(8) prompt before booting the kernel or stored in loader.conf(5). kern.kprintf_logging A bit mask that specifies the targets of kprintf(). Supported targets are the console (0x1) and the dmesg buffer (0x4). The default value is 5 (print to both). kern.log_console_output Specifies whether console output is duplicated to the syslog. The default value is 1. security.ptr_restrict Specifying 1 masks out the upper bits of pointers printed with %p, and specifying 2 masks out pointer values altogether. The default value is 0. security.unprivileged_read_msgbuf Specifies if unprivileged processes may read the kernel buffer. The default value is 1.

SYSCTL VARIABLES

The loader tunables described in LOADER TUNABLES are also available as sysctl(8) variables of the same names.

EXAMPLES

This example demonstrates the use of the %pb%i conversion specifier. The function void kprintf_test(void) { kprintf("reg=%pb%i\n", "\10\2BITTWO\1BITONE\n", 3); } will produce the following output: reg=3<BITTWO,BITONE> The call log(LOG_DEBUG, "%s%d: been there.\n", sc->sc_name, sc->sc_unit); will add the appropriate debug message at priority "kern.debug" to the system log.

SEE ALSO

printf(3), syslog(3) DragonFly 6.1-DEVELOPMENT March 13, 2020 DragonFly 6.1-DEVELOPMENT

Search: Section: