#include <sys/socket.h>
#include <unistd.h>
-#include "libudev.h"
+#include "sd-device.h"
#include "sd-messages.h"
#include "alloc-util.h"
+#include "device-util.h"
#include "escape.h"
#include "fd-util.h"
#include "format-util.h"
#include "string-util.h"
void server_forward_kmsg(
- Server *s,
- int priority,
- const char *identifier,
- const char *message,
- const struct ucred *ucred) {
+ Server *s,
+ int priority,
+ const char *identifier,
+ const char *message,
+ const struct ucred *ucred) {
_cleanup_free_ char *ident_buf = NULL;
struct iovec iovec[5];
streq(identifier, program_invocation_short_name);
}
-static void dev_kmsg_record(Server *s, char *p, size_t l) {
+void dev_kmsg_record(Server *s, char *p, size_t l) {
_cleanup_free_ char *message = NULL, *syslog_priority = NULL, *syslog_pid = NULL, *syslog_facility = NULL, *syslog_identifier = NULL, *source_time = NULL, *identifier = NULL, *pid = NULL;
struct iovec iovec[N_IOVEC_META_FIELDS + 7 + N_IOVEC_KERNEL_FIELDS + 2 + N_IOVEC_UDEV_FIELDS];
}
if (kernel_device) {
- struct udev_device *ud;
+ _cleanup_(sd_device_unrefp) sd_device *d = NULL;
- ud = udev_device_new_from_device_id(s->udev, kernel_device);
- if (ud) {
+ if (sd_device_new_from_device_id(&d, kernel_device) >= 0) {
const char *g;
- struct udev_list_entry *ll;
char *b;
- g = udev_device_get_devnode(ud);
- if (g) {
- b = strappend("_UDEV_DEVNODE=", g);
+ if (sd_device_get_devname(d, &g) >= 0) {
+ b = strjoin("_UDEV_DEVNODE=", g);
if (b) {
iovec[n++] = IOVEC_MAKE_STRING(b);
z++;
}
}
- g = udev_device_get_sysname(ud);
- if (g) {
- b = strappend("_UDEV_SYSNAME=", g);
+ if (sd_device_get_sysname(d, &g) >= 0) {
+ b = strjoin("_UDEV_SYSNAME=", g);
if (b) {
iovec[n++] = IOVEC_MAKE_STRING(b);
z++;
}
j = 0;
- ll = udev_device_get_devlinks_list_entry(ud);
- udev_list_entry_foreach(ll, ll) {
+ FOREACH_DEVICE_DEVLINK(d, g) {
- if (j > N_IOVEC_UDEV_FIELDS)
+ if (j >= N_IOVEC_UDEV_FIELDS)
break;
- g = udev_list_entry_get_name(ll);
- if (g) {
- b = strappend("_UDEV_DEVLINK=", g);
- if (b) {
- iovec[n++] = IOVEC_MAKE_STRING(b);
- z++;
- }
+ b = strjoin("_UDEV_DEVLINK=", g);
+ if (b) {
+ iovec[n++] = IOVEC_MAKE_STRING(b);
+ z++;
}
j++;
}
-
- udev_device_unref(ud);
}
}
goto finish;
if (identifier) {
- syslog_identifier = strappend("SYSLOG_IDENTIFIER=", identifier);
+ syslog_identifier = strjoin("SYSLOG_IDENTIFIER=", identifier);
if (syslog_identifier)
iovec[n++] = IOVEC_MAKE_STRING(syslog_identifier);
}
if (pid) {
- syslog_pid = strappend("SYSLOG_PID=", pid);
+ syslog_pid = strjoin("SYSLOG_PID=", pid);
if (syslog_pid)
iovec[n++] = IOVEC_MAKE_STRING(syslog_pid);
}
if (IN_SET(errno, EAGAIN, EINTR, EPIPE))
return 0;
- return log_error_errno(errno, "Failed to read from kernel: %m");
+ return log_error_errno(errno, "Failed to read from /dev/kmsg: %m");
}
dev_kmsg_record(s, buffer, l);
}
int server_open_kernel_seqnum(Server *s) {
- _cleanup_close_ int fd;
+ _cleanup_close_ int fd = -1;
+ const char *fn;
uint64_t *p;
int r;
assert(s);
- /* We store the seqnum we last read in an mmaped file. That
- * way we can just use it like a variable, but it is
- * persistent and automatically flushed at reboot. */
+ /* 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)
+ return 0;
- fd = open("/run/systemd/journal/kernel-seqnum", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0644);
+ fn = strjoina(s->runtime_directory, "/kernel-seqnum");
+ fd = open(fn, O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0644);
if (fd < 0) {
- log_error_errno(errno, "Failed to open /run/systemd/journal/kernel-seqnum, ignoring: %m");
+ log_error_errno(errno, "Failed to open %s, ignoring: %m", fn);
return 0;
}