Merge pull request #7740 from yuwata/fix-7676

sd-device: support the case that /sys is a symlink
This commit is contained in:
Lennart Poettering
2018-01-08 15:15:57 +01:00
committed by GitHub

View File

@@ -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;