diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-19 07:36:09 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-19 19:44:33 +0900 |
commit | 97268bdf6fbbe1cec3823861285e99d80cd54aa9 (patch) | |
tree | bbe767b3b4c29ec9d3b4cafe280ebae1fae0bf79 /src/udev/udev-builtin-net_id.c | |
parent | 62ccd11d38ccd2959c7ab2674890fb44bde5943b (diff) | |
download | systemd-97268bdf6fbbe1cec3823861285e99d80cd54aa9.tar.gz |
udev: use device_opendir()
Diffstat (limited to 'src/udev/udev-builtin-net_id.c')
-rw-r--r-- | src/udev/udev-builtin-net_id.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 76ea34ffa6..4acbc87b96 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) { |