From: Yu Watanabe Date: Sun, 7 Jan 2018 16:36:08 +0000 (+0900) Subject: sd-device: support the case that /sys is a symlink X-Git-Tag: v237~136^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e1ec12ec3329dddaa74d3ae1e819505166fe9ad;p=platform%2Fupstream%2Fsystemd.git sd-device: support the case that /sys is a symlink When /sys is a symlink to the sysfs mountpoint, e.g. /path/to/sysfs. Then, device->syspath was set to like /path/to/sysfs/devices/foo/baz. This converts the path to /sys/devices/foo/baz. Fixes #7676. --- diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 49c157b..1297dfa 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -175,6 +175,29 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { 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;