From 8bebb09ce7fe98b75932f9f24d2b07fa245677ce Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 22 Aug 2018 14:04:11 +0900 Subject: [PATCH] journal: replace udev_device by sd_device --- src/journal/journalctl.c | 46 +++++++++++++++++++------------------------ src/journal/journald-kmsg.c | 31 +++++++++++------------------ src/journal/journald-server.c | 7 ------- src/journal/journald-server.h | 2 -- 4 files changed, 31 insertions(+), 55 deletions(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index be37b87..a9e4af1 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -22,6 +22,7 @@ #endif #include "sd-bus.h" +#include "sd-device.h" #include "sd-journal.h" #include "acl-util.h" @@ -30,6 +31,7 @@ #include "bus-util.h" #include "catalog.h" #include "chattr-util.h" +#include "device-private.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -57,8 +59,6 @@ #include "strv.h" #include "syslog-util.h" #include "terminal-util.h" -#include "udev-util.h" -#include "udev.h" #include "unit-name.h" #include "user-util.h" @@ -177,9 +177,8 @@ typedef struct BootId { } BootId; static int add_matches_for_device(sd_journal *j, const char *devpath) { - _cleanup_(udev_unrefp) struct udev *udev = NULL; - _cleanup_(udev_device_unrefp) struct udev_device *device = NULL; - struct udev_device *d = NULL; + _cleanup_(sd_device_unrefp) sd_device *device = NULL; + sd_device *d = NULL; struct stat st; int r; @@ -191,33 +190,25 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) { return -EINVAL; } - udev = udev_new(); - if (!udev) - return log_oom(); - if (stat(devpath, &st) < 0) return log_error_errno(errno, "Couldn't stat file: %m"); - r = udev_device_new_from_stat_rdev(udev, &st, &device); + r = device_new_from_stat_rdev(&device, &st); if (r < 0) - return log_error_errno(r, "Failed to get udev device from devnum %u:%u: %m", major(st.st_rdev), minor(st.st_rdev)); + return log_error_errno(r, "Failed to get device from devnum %u:%u: %m", major(st.st_rdev), minor(st.st_rdev)); - d = device; - while (d) { + for (d = device; d; ) { _cleanup_free_ char *match = NULL; const char *subsys, *sysname, *devnode; + sd_device *parent; - subsys = udev_device_get_subsystem(d); - if (!subsys) { - d = udev_device_get_parent(d); - continue; - } + r = sd_device_get_subsystem(d, &subsys); + if (r < 0) + goto get_parent; - sysname = udev_device_get_sysname(d); - if (!sysname) { - d = udev_device_get_parent(d); - continue; - } + r = sd_device_get_sysname(d, &sysname); + if (r < 0) + goto get_parent; match = strjoin("_KERNEL_DEVICE=+", subsys, ":", sysname); if (!match) @@ -227,8 +218,7 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) { if (r < 0) return log_error_errno(r, "Failed to add match: %m"); - devnode = udev_device_get_devnode(d); - if (devnode) { + if (sd_device_get_devname(d, &devnode) >= 0) { _cleanup_free_ char *match1 = NULL; r = stat(devnode, &st); @@ -244,7 +234,11 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) { return log_error_errno(r, "Failed to add match: %m"); } - d = udev_device_get_parent(d); +get_parent: + if (sd_device_get_parent(d, &parent) < 0) + break; + + d = parent; } r = add_match_this_boot(j, arg_machine); diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 7644beb..9fe9231 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -6,10 +6,11 @@ #include #include -#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" @@ -209,16 +210,13 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) { } 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) { + if (sd_device_get_devname(d, &g) >= 0) { b = strappend("_UDEV_DEVNODE=", g); if (b) { iovec[n++] = IOVEC_MAKE_STRING(b); @@ -226,8 +224,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) { } } - g = udev_device_get_sysname(ud); - if (g) { + if (sd_device_get_sysname(d, &g) >= 0) { b = strappend("_UDEV_SYSNAME=", g); if (b) { iovec[n++] = IOVEC_MAKE_STRING(b); @@ -236,25 +233,19 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) { } 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) 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 = strappend("_UDEV_DEVLINK=", g); + if (b) { + iovec[n++] = IOVEC_MAKE_STRING(b); + z++; } j++; } - - udev_device_unref(ud); } } diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 7a11fee..edcdc9d 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -9,7 +9,6 @@ #include #include -#include "libudev.h" #include "sd-daemon.h" #include "sd-journal.h" #include "sd-messages.h" @@ -1845,10 +1844,6 @@ int server_init(Server *s) { if (r < 0) return r; - s->udev = udev_new(); - if (!s->udev) - return -ENOMEM; - s->rate_limit = journal_rate_limit_new(s->rate_limit_interval, s->rate_limit_burst); if (!s->rate_limit) return -ENOMEM; @@ -1949,8 +1944,6 @@ void server_done(Server *s) { if (s->mmap) mmap_cache_unref(s->mmap); - - udev_unref(s->udev); } static const char* const storage_table[_STORAGE_MAX] = { diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index 983be8b..6d4847b 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -137,8 +137,6 @@ struct Server { Set *deferred_closes; - struct udev *udev; - uint64_t *kernel_seqnum; bool dev_kmsg_readable:1; -- 2.7.4