diff options
Diffstat (limited to 'udev/lib')
-rw-r--r-- | udev/lib/Makefile.am | 1 | ||||
-rw-r--r-- | udev/lib/libudev-device.c | 2 | ||||
-rw-r--r-- | udev/lib/libudev-enumerate.c | 2 | ||||
-rw-r--r-- | udev/lib/libudev-private.h | 1 | ||||
-rw-r--r-- | udev/lib/libudev-utils.c | 31 | ||||
-rw-r--r-- | udev/lib/libudev.c | 5 |
6 files changed, 34 insertions, 8 deletions
diff --git a/udev/lib/Makefile.am b/udev/lib/Makefile.am index 33d0f633ab..a768daa817 100644 --- a/udev/lib/Makefile.am +++ b/udev/lib/Makefile.am @@ -32,7 +32,6 @@ libudev_la_SOURCES =\ ../udev.h \ ../udev_utils.c \ ../udev_utils_string.c \ - ../udev_sysfs.c \ ../udev_sysdeps.c libudev_la_LDFLAGS = \ diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c index e13146599c..416cae450d 100644 --- a/udev/lib/libudev-device.c +++ b/udev/lib/libudev-device.c @@ -205,7 +205,7 @@ struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char * /* resolve possible symlink to real path */ strlcpy(path, devpath, sizeof(path)); - sysfs_resolve_link(udev, path, sizeof(path)); + util_resolve_sys_link(udev, path, sizeof(path)); device_set_devpath(udev_device, path); info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device)); diff --git a/udev/lib/libudev-enumerate.c b/udev/lib/libudev-enumerate.c index 1ba4de8948..f36eafaff6 100644 --- a/udev/lib/libudev-enumerate.c +++ b/udev/lib/libudev-enumerate.c @@ -58,7 +58,7 @@ static int devices_scan_subsystem(struct udev *udev, strlcpy(devpath, &path[len], sizeof(devpath)); strlcat(devpath, "/", sizeof(devpath)); strlcat(devpath, dent->d_name, sizeof(devpath)); - sysfs_resolve_link(udev, devpath, sizeof(devpath)); + util_resolve_sys_link(udev, devpath, sizeof(devpath)); name_list_add(udev, device_list, devpath, 1); } closedir(dir); diff --git a/udev/lib/libudev-private.h b/udev/lib/libudev-private.h index daa869ba42..1579df6d6e 100644 --- a/udev/lib/libudev-private.h +++ b/udev/lib/libudev-private.h @@ -106,4 +106,5 @@ extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg); /* libudev-utils */ extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size); extern ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size); +extern int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size); #endif diff --git a/udev/lib/libudev-utils.c b/udev/lib/libudev-utils.c index 82acb1a481..e5f1ed7c38 100644 --- a/udev/lib/libudev-utils.c +++ b/udev/lib/libudev-utils.c @@ -63,3 +63,34 @@ ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver return get_sys_link(udev, "driver", devpath, driver, size); } +int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size) +{ + char link_path[PATH_SIZE]; + char link_target[PATH_SIZE]; + int len; + int i; + int back; + + strlcpy(link_path, udev_get_sys_path(udev), sizeof(link_path)); + strlcat(link_path, devpath, sizeof(link_path)); + len = readlink(link_path, link_target, sizeof(link_target)); + if (len <= 0) + return -1; + link_target[len] = '\0'; + dbg(udev, "path link '%s' points to '%s'\n", devpath, link_target); + + for (back = 0; strncmp(&link_target[back * 3], "../", 3) == 0; back++) + ; + dbg(udev, "base '%s', tail '%s', back %i\n", devpath, &link_target[back * 3], back); + for (i = 0; i <= back; i++) { + char *pos = strrchr(devpath, '/'); + + if (pos == NULL) + return -1; + pos[0] = '\0'; + } + dbg(udev, "after moving back '%s'\n", devpath); + strlcat(devpath, "/", size); + strlcat(devpath, &link_target[back * 3], size); + return 0; +} diff --git a/udev/lib/libudev.c b/udev/lib/libudev.c index 50fe0d1c89..3bcafcd9a6 100644 --- a/udev/lib/libudev.c +++ b/udev/lib/libudev.c @@ -295,10 +295,7 @@ struct udev *udev_new(void) if (udev->dev_path == NULL || udev->sys_path == NULL) goto err; - selinux_init(udev); - sysfs_init(); - info(udev, "context %p created\n", udev); info(udev, "log_priority=%d\n", udev->log_priority); info(udev, "config_file='%s'\n", config_file); @@ -306,7 +303,6 @@ struct udev *udev_new(void) info(udev, "sys_path='%s'\n", udev->sys_path); if (udev->rules_path != NULL) info(udev, "rules_path='%s'\n", udev->rules_path); - free(config_file); return udev; err: @@ -347,7 +343,6 @@ void udev_unref(struct udev *udev) udev->refcount--; if (udev->refcount > 0) return; - sysfs_cleanup(); selinux_exit(udev); free(udev->dev_path); free(udev->sys_path); |