diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-01-08 15:15:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-08 15:15:57 +0100 |
commit | 009e9fbcfdcf0462604e3eb000c0546503511f06 (patch) | |
tree | 7971725285f2ead3992f09dbb8e0b65a9d242265 | |
parent | fd007b3b52ca385e4249b7a8cde5e13bdd7924f9 (diff) | |
parent | 2e1ec12ec3329dddaa74d3ae1e819505166fe9ad (diff) | |
download | systemd-009e9fbcfdcf0462604e3eb000c0546503511f06.tar.gz |
Merge pull request #7740 from yuwata/fix-7676
sd-device: support the case that /sys is a symlink
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index a96d7445ce..1297dfa911 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -166,25 +166,38 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { } if (verify) { - r = readlink_and_canonicalize(_syspath, NULL, &syspath); + r = chase_symlinks(_syspath, NULL, 0, &syspath); if (r == -ENOENT) /* the device does not exist (any more?) */ return -ENODEV; - else if (r == -EINVAL) { - /* not a symlink */ - syspath = canonicalize_file_name(_syspath); - if (!syspath) { - if (errno == ENOENT) - /* the device does not exist (any more?) */ - return -ENODEV; - - return log_debug_errno(errno, "sd-device: could not canonicalize '%s': %m", _syspath); - } - } else if (r < 0) { + else if (r < 0) { log_debug_errno(r, "sd-device: could not get target of '%s': %m", _syspath); return r; } + if (!path_startswith(syspath, "/sys")) { + _cleanup_free_ char *real_sys = NULL, *new_syspath = NULL; + char *p; + + /* /sys is a symlink to somewhere sysfs is mounted on? In that case, we convert the path to real sysfs to "/sys". */ + r = chase_symlinks("/sys", NULL, 0, &real_sys); + if (r < 0) + return log_debug_errno(r, "sd-device: could not chase symlink /sys: %m"); + + p = path_startswith(syspath, real_sys); + if (!p) { + log_debug("sd-device: canonicalized path '%s' does not starts with sysfs mount point '%s'", syspath, real_sys); + return -ENODEV; + } + + new_syspath = strjoin("/sys/", p); + if (!new_syspath) + return log_oom(); + + free_and_replace(syspath, new_syspath); + path_kill_slashes(syspath); + } + if (path_startswith(syspath, "/sys/devices/")) { char *path; |