journald-kmsg.c revision 07630cea1f3a845c09309f197ac7c4f11edd3b62
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d710d36375bacbf9cfb8903107bedf2c0aada84eMichal Schmidt This file is part of systemd.
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek Copyright 2011 Lennart Poettering
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt systemd is free software; you can redistribute it and/or modify it
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt under the terms of the GNU Lesser General Public License as published by
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt the Free Software Foundation; either version 2.1 of the License, or
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier (at your option) any later version.
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt systemd is distributed in the hope that it will be useful, but
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt WITHOUT ANY WARRANTY; without even the implied warranty of
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41a5ef639b248aa3d10609d9af5d0043b909d93cHarald Hoyer Lesser General Public License for more details.
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt You should have received a copy of the GNU Lesser General Public License
41a5ef639b248aa3d10609d9af5d0043b909d93cHarald Hoyer along with systemd; If not, see <http://www.gnu.org/licenses/>.
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt char header_priority[DECIMAL_STR_MAX(priority) + 3],
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt header_pid[sizeof("[]: ")-1 + DECIMAL_STR_MAX(pid_t) + 1];
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt if (_unlikely_(LOG_PRI(priority) > s->max_level_kmsg))
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt /* Never allow messages with kernel facility to be written to
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt * kmsg, regardless where the data comes from. */
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt /* First: priority field */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier IOVEC_SET_STRING(iovec[n++], header_priority);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /* Second: identifier and PID */
b5da077ddf01546c4a85688624d6957766d6c00cMichal Schmidt xsprintf(header_pid, "["PID_FMT"]: ", ucred->pid);
} else if (identifier) {
pid_t t;
return t == getpid();
char *message = NULL, *syslog_priority = NULL, *syslog_pid = NULL, *syslog_facility = NULL, *syslog_identifier = NULL, *source_time = NULL;
int priority, r;
unsigned long long usec;
assert(s);
assert(p);
if (s->kernel_seqnum) {
pl = e - p;
for (j = 0; l > 0 && j < N_IOVEC_KERNEL_FIELDS; j++) {
if (kernel_device) {
if (ud) {
if (j > N_IOVEC_UDEV_FIELDS)
goto finish;
if (identifier) {
if (syslog_identifier)
if (pid) {
if (syslog_pid)
ssize_t l;
assert(s);
return -errno;
assert(s);
if (s->dev_kmsg_fd < 0)
if (!s->dev_kmsg_readable)
r = server_read_dev_kmsg(s);
assert(s);
return server_read_dev_kmsg(s);
assert(s);
if (s->dev_kmsg_fd < 0) {
r = sd_event_add_io(s->event, &s->dev_kmsg_event_source, s->dev_kmsg_fd, EPOLLIN, dispatch_dev_kmsg, s);
if (r == -EPERM) {
goto fail;
goto fail;
goto fail;
s->dev_kmsg_readable = true;
fail:
uint64_t *p;
assert(s);
fd = open("/run/systemd/journal/kernel-seqnum", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0644);
if (fd < 0) {
if (p == MAP_FAILED) {
s->kernel_seqnum = p;