18c2ecf20Sopenharmony_ciWhat:		/dev/kmsg
28c2ecf20Sopenharmony_ciDate:		Mai 2012
38c2ecf20Sopenharmony_ciKernelVersion:	3.5
48c2ecf20Sopenharmony_ciContact:	Kay Sievers <kay@vrfy.org>
58c2ecf20Sopenharmony_ciDescription:	The /dev/kmsg character device node provides userspace access
68c2ecf20Sopenharmony_ci		to the kernel's printk buffer.
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci		Injecting messages:
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci		Every write() to the opened device node places a log entry in
118c2ecf20Sopenharmony_ci		the kernel's printk buffer.
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci		The logged line can be prefixed with a <N> syslog prefix, which
148c2ecf20Sopenharmony_ci		carries the syslog priority and facility. The single decimal
158c2ecf20Sopenharmony_ci		prefix number is composed of the 3 lowest bits being the syslog
168c2ecf20Sopenharmony_ci		priority and the next 8 bits the syslog facility number.
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci		If no prefix is given, the priority number is the default kernel
198c2ecf20Sopenharmony_ci		log priority and the facility number is set to LOG_USER (1). It
208c2ecf20Sopenharmony_ci		is not possible to inject messages from userspace with the
218c2ecf20Sopenharmony_ci		facility number LOG_KERN (0), to make sure that the origin of
228c2ecf20Sopenharmony_ci		the messages can always be reliably determined.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci		Accessing the buffer:
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci		Every read() from the opened device node receives one record
278c2ecf20Sopenharmony_ci		of the kernel's printk buffer.
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci		The first read() directly following an open() always returns
308c2ecf20Sopenharmony_ci		first message in the buffer; there is no kernel-internal
318c2ecf20Sopenharmony_ci		persistent state; many readers can concurrently open the device
328c2ecf20Sopenharmony_ci		and read from it, without affecting other readers.
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci		Every read() will receive the next available record. If no more
358c2ecf20Sopenharmony_ci		records are available read() will block, or if O_NONBLOCK is
368c2ecf20Sopenharmony_ci		used -EAGAIN returned.
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci		Messages in the record ring buffer get overwritten as whole,
398c2ecf20Sopenharmony_ci		there are never partial messages received by read().
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci		In case messages get overwritten in the circular buffer while
428c2ecf20Sopenharmony_ci		the device is kept open, the next read() will return -EPIPE,
438c2ecf20Sopenharmony_ci		and the seek position be updated to the next available record.
448c2ecf20Sopenharmony_ci		Subsequent reads() will return available records again.
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci		Unlike the classic syslog() interface, the 64 bit record
478c2ecf20Sopenharmony_ci		sequence numbers allow to calculate the amount of lost
488c2ecf20Sopenharmony_ci		messages, in case the buffer gets overwritten. And they allow
498c2ecf20Sopenharmony_ci		to reconnect to the buffer and reconstruct the read position
508c2ecf20Sopenharmony_ci		if needed, without limiting the interface to a single reader.
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci		The device supports seek with the following parameters:
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci		SEEK_SET, 0
558c2ecf20Sopenharmony_ci		  seek to the first entry in the buffer
568c2ecf20Sopenharmony_ci		SEEK_END, 0
578c2ecf20Sopenharmony_ci		  seek after the last entry in the buffer
588c2ecf20Sopenharmony_ci		SEEK_DATA, 0
598c2ecf20Sopenharmony_ci		  seek after the last record available at the time
608c2ecf20Sopenharmony_ci		  the last SYSLOG_ACTION_CLEAR was issued.
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci		Other seek operations or offsets are not supported because of
638c2ecf20Sopenharmony_ci		the special behavior this device has. The device allows to read
648c2ecf20Sopenharmony_ci		or write only whole variable length messages (records) that are
658c2ecf20Sopenharmony_ci		stored in a ring buffer.
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci		Because of the non-standard behavior also the error values are
688c2ecf20Sopenharmony_ci		non-standard. -ESPIPE is returned for non-zero offset. -EINVAL
698c2ecf20Sopenharmony_ci		is returned for other operations, e.g. SEEK_CUR. This behavior
708c2ecf20Sopenharmony_ci		and values are historical and could not be modified without the
718c2ecf20Sopenharmony_ci		risk of breaking userspace.
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci		The output format consists of a prefix carrying the syslog
748c2ecf20Sopenharmony_ci		prefix including priority and facility, the 64 bit message
758c2ecf20Sopenharmony_ci		sequence number and the monotonic timestamp in microseconds,
768c2ecf20Sopenharmony_ci		and a flag field. All fields are separated by a ','.
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci		Future extensions might add more comma separated values before
798c2ecf20Sopenharmony_ci		the terminating ';'. Unknown fields and values should be
808c2ecf20Sopenharmony_ci		gracefully ignored.
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci		The human readable text string starts directly after the ';'
838c2ecf20Sopenharmony_ci		and is terminated by a '\n'. Untrusted values derived from
848c2ecf20Sopenharmony_ci		hardware or other facilities are printed, therefore
858c2ecf20Sopenharmony_ci		all non-printable characters and '\' itself in the log message
868c2ecf20Sopenharmony_ci		are escaped by "\x00" C-style hex encoding.
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci		A line starting with ' ', is a continuation line, adding
898c2ecf20Sopenharmony_ci		key/value pairs to the log message, which provide the machine
908c2ecf20Sopenharmony_ci		readable context of the message, for reliable processing in
918c2ecf20Sopenharmony_ci		userspace.
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci		Example::
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci		  7,160,424069,-;pci_root PNP0A03:00: host bridge window [io  0x0000-0x0cf7] (ignored)
968c2ecf20Sopenharmony_ci		   SUBSYSTEM=acpi
978c2ecf20Sopenharmony_ci		   DEVICE=+acpi:PNP0A03:00
988c2ecf20Sopenharmony_ci		  6,339,5140900,-;NET: Registered protocol family 10
998c2ecf20Sopenharmony_ci		  30,340,5690716,-;udevd[80]: starting version 181
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci		The DEVICE= key uniquely identifies devices the following way:
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci		  ============  =================
1048c2ecf20Sopenharmony_ci		  b12:8         block dev_t
1058c2ecf20Sopenharmony_ci		  c127:3        char dev_t
1068c2ecf20Sopenharmony_ci		  n8            netdev ifindex
1078c2ecf20Sopenharmony_ci		  +sound:card0  subsystem:devname
1088c2ecf20Sopenharmony_ci		  ============  =================
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci		The flags field carries '-' by default. A 'c' indicates a
1118c2ecf20Sopenharmony_ci		fragment of a line. Note, that these hints about continuation
1128c2ecf20Sopenharmony_ci		lines are not necessarily correct, and the stream could be
1138c2ecf20Sopenharmony_ci		interleaved with unrelated messages, but merging the lines in
1148c2ecf20Sopenharmony_ci		the output usually produces better human readable results. A
1158c2ecf20Sopenharmony_ci		similar logic is used internally when messages are printed to
1168c2ecf20Sopenharmony_ci		the console, /proc/kmsg or the syslog() syscall.
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci		By default, kernel tries to avoid fragments by concatenating
1198c2ecf20Sopenharmony_ci		when it can and fragments are rare; however, when extended
1208c2ecf20Sopenharmony_ci		console support is enabled, the in-kernel concatenation is
1218c2ecf20Sopenharmony_ci		disabled and /dev/kmsg output will contain more fragments. If
1228c2ecf20Sopenharmony_ci		the log consumer performs concatenation, the end result
1238c2ecf20Sopenharmony_ci		should be the same. In the future, the in-kernel concatenation
1248c2ecf20Sopenharmony_ci		may be removed entirely and /dev/kmsg users are recommended to
1258c2ecf20Sopenharmony_ci		implement fragment handling.
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ciUsers:		dmesg(1), userspace kernel log consumers
128