From: Yu Watanabe Date: Sun, 18 Sep 2022 22:36:09 +0000 (+0900) Subject: udev: use device_opendir() X-Git-Tag: v252-rc1~142^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F24731%2Fhead;p=thirdparty%2Fsystemd.git udev: use device_opendir() --- diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 76ea34ffa68..4acbc87b967 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -24,6 +24,7 @@ #include "alloc-util.h" #include "chase-symlinks.h" +#include "device-private.h" #include "device-util.h" #include "dirent-util.h" #include "fd-util.h" @@ -98,7 +99,7 @@ static sd_device *skip_virtio(sd_device *dev) { static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, char **ret_suffix) { _cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL; - const char *physfn_syspath, *syspath; + const char *syspath; _cleanup_closedir_ DIR *dir = NULL; int r; @@ -115,15 +116,11 @@ static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, cha if (r < 0) return r; - r = sd_device_get_syspath(physfn_pcidev, &physfn_syspath); + /* Find the virtual function number by finding the right virtfn link. */ + r = device_opendir(physfn_pcidev, NULL, &dir); if (r < 0) return r; - /* Find the virtual function number by finding the right virtfn link. */ - dir = opendir(physfn_syspath); - if (!dir) - return -errno; - FOREACH_DIRENT_ALL(de, dir, break) { _cleanup_(sd_device_unrefp) sd_device *virtfn_pcidev = NULL; const char *n, *s; @@ -330,15 +327,15 @@ static int parse_hotplug_slot_from_function_id(sd_device *dev, int slots_dirfd, } static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) { - const char *sysname, *attr, *syspath; + const char *sysname, *attr; _cleanup_(sd_device_unrefp) sd_device *pci = NULL; _cleanup_closedir_ DIR *dir = NULL; unsigned domain, bus, slot, func; sd_device *hotplug_slot_dev; unsigned long dev_port = 0; uint32_t hotplug_slot = 0; - char slots[PATH_MAX], *s; size_t l; + char *s; int r; assert(dev); @@ -409,17 +406,9 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) { if (r < 0) return log_debug_errno(r, "sd_device_new_from_subsystem_sysname() failed: %m"); - r = sd_device_get_syspath(pci, &syspath); + r = device_opendir(pci, "slots", &dir); if (r < 0) - return log_device_debug_errno(pci, r, "sd_device_get_syspath() failed: %m"); - - if (!snprintf_ok(slots, sizeof slots, "%s/slots", syspath)) - return log_device_debug_errno(dev, SYNTHETIC_ERRNO(ENAMETOOLONG), - "Cannot access %s/slots: %m", syspath); - - dir = opendir(slots); - if (!dir) - return log_device_debug_errno(dev, errno, "Cannot access %s: %m", slots); + return log_device_debug_errno(dev, r, "Cannot access 'slots' subdirectory: %m"); hotplug_slot_dev = names->pcidev; while (hotplug_slot_dev) {