xref: /linux/Documentation/ABI/testing/dev-kmsg (revision 3b552b92817c63fdccfe9d5f3ce7424b57e9ee8f)
1*3b552b92SKay SieversWhat:		/dev/kmsg
2*3b552b92SKay SieversDate:		Mai 2012
3*3b552b92SKay SieversKernelVersion:	3.5
4*3b552b92SKay SieversContact:	Kay Sievers <kay@vrfy.org>
5*3b552b92SKay SieversDescription:	The /dev/kmsg character device node provides userspace access
6*3b552b92SKay Sievers		to the kernel's printk buffer.
7*3b552b92SKay Sievers
8*3b552b92SKay Sievers		Injecting messages:
9*3b552b92SKay Sievers		Every write() to the opened device node places a log entry in
10*3b552b92SKay Sievers		the kernel's printk buffer.
11*3b552b92SKay Sievers
12*3b552b92SKay Sievers		The logged line can be prefixed with a <N> syslog prefix, which
13*3b552b92SKay Sievers		carries the syslog priority and facility. The single decimal
14*3b552b92SKay Sievers		prefix number is composed of the 3 lowest bits being the syslog
15*3b552b92SKay Sievers		priority and the higher bits the syslog facility number.
16*3b552b92SKay Sievers
17*3b552b92SKay Sievers		If no prefix is given, the priority number is the default kernel
18*3b552b92SKay Sievers		log priority and the facility number is set to LOG_USER (1). It
19*3b552b92SKay Sievers		is not possible to inject messages from userspace with the
20*3b552b92SKay Sievers		facility number LOG_KERN (0), to make sure that the origin of
21*3b552b92SKay Sievers		the messages can always be reliably determined.
22*3b552b92SKay Sievers
23*3b552b92SKay Sievers		Accessing the buffer:
24*3b552b92SKay Sievers		Every read() from the opened device node receives one record
25*3b552b92SKay Sievers		of the kernel's printk buffer.
26*3b552b92SKay Sievers
27*3b552b92SKay Sievers		The first read() directly following an open() always returns
28*3b552b92SKay Sievers		first message in the buffer; there is no kernel-internal
29*3b552b92SKay Sievers		persistent state; many readers can concurrently open the device
30*3b552b92SKay Sievers		and read from it, without affecting other readers.
31*3b552b92SKay Sievers
32*3b552b92SKay Sievers		Every read() will receive the next available record. If no more
33*3b552b92SKay Sievers		records are available read() will block, or if O_NONBLOCK is
34*3b552b92SKay Sievers		used -EAGAIN returned.
35*3b552b92SKay Sievers
36*3b552b92SKay Sievers		Messages in the record ring buffer get overwritten as whole,
37*3b552b92SKay Sievers		there are never partial messages received by read().
38*3b552b92SKay Sievers
39*3b552b92SKay Sievers		In case messages get overwritten in the circular buffer while
40*3b552b92SKay Sievers		the device is kept open, the next read() will return -EPIPE,
41*3b552b92SKay Sievers		and the seek position be updated to the next available record.
42*3b552b92SKay Sievers		Subsequent reads() will return available records again.
43*3b552b92SKay Sievers
44*3b552b92SKay Sievers		Unlike the classic syslog() interface, the 64 bit record
45*3b552b92SKay Sievers		sequence numbers allow to calculate the amount of lost
46*3b552b92SKay Sievers		messages, in case the buffer gets overwritten. And they allow
47*3b552b92SKay Sievers		to reconnect to the buffer and reconstruct the read position
48*3b552b92SKay Sievers		if needed, without limiting the interface to a single reader.
49*3b552b92SKay Sievers
50*3b552b92SKay Sievers		The device supports seek with the following parameters:
51*3b552b92SKay Sievers		SEEK_SET, 0
52*3b552b92SKay Sievers		  seek to the first entry in the buffer
53*3b552b92SKay Sievers		SEEK_END, 0
54*3b552b92SKay Sievers		  seek after the last entry in the buffer
55*3b552b92SKay Sievers		SEEK_DATA, 0
56*3b552b92SKay Sievers		  seek after the last record available at the time
57*3b552b92SKay Sievers		  the last SYSLOG_ACTION_CLEAR was issued.
58*3b552b92SKay Sievers
59*3b552b92SKay Sievers		The output format consists of a prefix carrying the syslog
60*3b552b92SKay Sievers		prefix including priority and facility, the 64 bit message
61*3b552b92SKay Sievers		sequence number and the monotonic timestamp in microseconds.
62*3b552b92SKay Sievers		The values are separated by a ','. Future extensions might
63*3b552b92SKay Sievers		add more comma separated values before the terminating ';'.
64*3b552b92SKay Sievers		Unknown values should be gracefully ignored.
65*3b552b92SKay Sievers
66*3b552b92SKay Sievers		The human readable text string starts directly after the ';'
67*3b552b92SKay Sievers		and is terminated by a '\n'. Untrusted values derived from
68*3b552b92SKay Sievers		hardware or other facilities are printed, therefore
69*3b552b92SKay Sievers		all non-printable characters in the log message are escaped
70*3b552b92SKay Sievers		by "\x00" C-style hex encoding.
71*3b552b92SKay Sievers
72*3b552b92SKay Sievers		A line starting with ' ', is a continuation line, adding
73*3b552b92SKay Sievers		key/value pairs to the log message, which provide the machine
74*3b552b92SKay Sievers		readable context of the message, for reliable processing in
75*3b552b92SKay Sievers		userspace.
76*3b552b92SKay Sievers
77*3b552b92SKay Sievers		Example:
78*3b552b92SKay Sievers		7,160,424069;pci_root PNP0A03:00: host bridge window [io  0x0000-0x0cf7] (ignored)
79*3b552b92SKay Sievers		 SUBSYSTEM=acpi
80*3b552b92SKay Sievers		 DEVICE=+acpi:PNP0A03:00
81*3b552b92SKay Sievers		6,339,5140900;NET: Registered protocol family 10
82*3b552b92SKay Sievers		30,340,5690716;udevd[80]: starting version 181
83*3b552b92SKay Sievers
84*3b552b92SKay Sievers		The DEVICE= key uniquely identifies devices the following way:
85*3b552b92SKay Sievers		  b12:8        - block dev_t
86*3b552b92SKay Sievers		  c127:3       - char dev_t
87*3b552b92SKay Sievers		  n8           - netdev ifindex
88*3b552b92SKay Sievers		  +sound:card0 - subsystem:devname
89*3b552b92SKay Sievers
90*3b552b92SKay SieversUsers:		dmesg(1), userspace kernel log consumers
91