From: Yu Watanabe Date: Sun, 10 Apr 2022 18:29:07 +0000 (+0900) Subject: udev: use readlinkat_malloc() X-Git-Tag: v252-rc1~207^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faadf97500dc8e76350a409c127f3f0fed116f9a;p=thirdparty%2Fsystemd.git udev: use readlinkat_malloc() And try to read it only when the file is symlink. --- diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 6ead839a5f5..0320f2d041b 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -147,7 +147,6 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir, return r; FOREACH_DIRENT_ALL(de, dir, break) { - _cleanup_free_ char *path = NULL, *buf = NULL; int tmp_prio; if (de->d_name[0] == '.') @@ -157,15 +156,18 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir, if (streq(de->d_name, id)) continue; - path = path_join(stackdir, de->d_name); - if (!path) - return -ENOMEM; - - if (readlink_malloc(path, &buf) >= 0) { + if (de->d_type == DT_LNK) { + _cleanup_free_ char *buf = NULL; char *devnode; /* New format. The devnode and priority can be obtained from symlink. */ + r = readlinkat_malloc(dirfd(dir), de->d_name, &buf); + if (r < 0) { + log_device_debug_errno(dev, r, "Failed to read symlink %s, ignoring: %m", de->d_name); + continue; + } + devnode = strchr(buf, ':'); if (!devnode || devnode == buf) continue; @@ -183,7 +185,8 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir, r = free_and_strdup(&target, devnode); if (r < 0) return r; - } else { + + } else if (de->d_type == DT_REG) { _cleanup_(sd_device_unrefp) sd_device *tmp_dev = NULL; const char *devnode; @@ -205,7 +208,8 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir, r = free_and_strdup(&target, devnode); if (r < 0) return r; - } + } else + continue; priority = tmp_prio; }