struct iovec iovec[5];
char header_priority[DECIMAL_STR_MAX(priority) + 3],
header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t) + 1];
- int n = 0;
+ size_t n = 0;
assert(s);
assert(priority >= 0);
identifier = ident_buf;
}
- xsprintf(header_pid, "["PID_FMT"]: ", ucred->pid);
-
if (identifier)
iovec[n++] = IOVEC_MAKE_STRING(identifier);
+ xsprintf(header_pid, "["PID_FMT"]: ", ucred->pid);
iovec[n++] = IOVEC_MAKE_STRING(header_pid);
} else if (identifier) {
iovec[n++] = IOVEC_MAKE_STRING(identifier);
iovec[n++] = IOVEC_MAKE_STRING("\n");
if (writev(s->dev_kmsg_fd, iovec, n) < 0)
- log_debug_errno(errno, "Failed to write to /dev/kmsg for logging: %m");
+ log_debug_errno(errno, "Failed to write to /dev/kmsg for logging, ignoring: %m");
}
static bool is_us(const char *identifier, const char *pid) {
if (cunescape_length_with_prefix(p, pl, "MESSAGE=", UNESCAPE_RELAX, &message) >= 0)
iovec[n++] = IOVEC_MAKE_STRING(message);
-
server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), c, NULL, priority, 0);
if (saved_log_max_level != INT_MAX)
if (l == 0)
return 0;
if (l < 0) {
- /* Old kernels who don't allow reading from /dev/kmsg
- * return EINVAL when we try. So handle this cleanly,
- * but don't try to ever read from it again. */
+ /* Old kernels which don't allow reading from /dev/kmsg return EINVAL when we try. So handle
+ * this cleanly, but don't try to ever read from it again. */
if (errno == EINVAL) {
s->dev_kmsg_event_source = sd_event_source_unref(s->dev_kmsg_event_source);
+ s->dev_kmsg_readable = false;
return 0;
}
return 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) { /* This will fail with EPERM on older kernels where /dev/kmsg is not readable. */
+ r = 0;
+ goto finish;
+ }
if (r < 0) {
-
- /* This will fail with EPERM on older kernels where
- * /dev/kmsg is not readable. */
- if (r == -EPERM) {
- r = 0;
- goto fail;
- }
-
log_error_errno(r, "Failed to add /dev/kmsg fd to event loop: %m");
- goto fail;
+ goto finish;
}
r = sd_event_source_set_priority(s->dev_kmsg_event_source, SD_EVENT_PRIORITY_IMPORTANT+10);
if (r < 0) {
log_error_errno(r, "Failed to adjust priority of kmsg event source: %m");
- goto fail;
+ goto finish;
}
s->dev_kmsg_readable = true;
-
return 0;
-fail:
+finish:
s->dev_kmsg_event_source = sd_event_source_unref(s->dev_kmsg_event_source);
s->dev_kmsg_fd = safe_close(s->dev_kmsg_fd);
-
return r;
}
/* We store the seqnum we last read in an mmapped file. That way we can just use it like a variable,
* but it is persistent and automatically flushed at reboot. */
- if (!s->read_kmsg)
+ if (!s->dev_kmsg_readable)
return 0;
fn = strjoina(s->runtime_directory, "/kernel-seqnum");