summaryrefslogtreecommitdiff
path: root/libudev
diff options
context:
space:
mode:
Diffstat (limited to 'libudev')
-rw-r--r--libudev/libudev-device-private.c6
-rw-r--r--libudev/libudev-device.c26
-rw-r--r--libudev/libudev-enumerate.c13
-rw-r--r--libudev/libudev-private.h1
4 files changed, 33 insertions, 13 deletions
diff --git a/libudev/libudev-device-private.c b/libudev/libudev-device-private.c
index bf93834c10..430e3e64d4 100644
--- a/libudev/libudev-device-private.c
+++ b/libudev/libudev-device-private.c
@@ -34,8 +34,12 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add)
util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/tags/", tag, "/", id, NULL);
if (add) {
+ int fd;
+
util_create_path(udev, filename);
- symlink(udev_device_get_devpath(dev), filename);
+ fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444);
+ if (fd >= 0)
+ close(fd);
} else {
unlink(filename);
}
diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c
index ac206a0e16..8698d98e1c 100644
--- a/libudev/libudev-device.c
+++ b/libudev/libudev-device.c
@@ -475,6 +475,32 @@ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, de
return udev_device_new_from_syspath(udev, path);
}
+struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id)
+{
+ char type;
+ int maj, min;
+ char subsys[UTIL_PATH_SIZE];
+ char *sysname;
+
+ switch(id[0]) {
+ case 'b':
+ case 'c':
+ if (sscanf(id, "%c%i:%i", &type, &maj, &min) != 3)
+ return NULL;
+ return udev_device_new_from_devnum(udev, type, makedev(maj, min));
+ case '+':
+ util_strscpy(subsys, sizeof(subsys), &id[1]);
+ sysname = strchr(subsys, ':');
+ if (sysname == NULL)
+ return NULL;
+ sysname[0] = '\0';
+ sysname = &sysname[1];
+ return udev_device_new_from_subsystem_sysname(udev, subsys, sysname);
+ default:
+ return NULL;
+ }
+}
+
/**
* udev_device_new_from_subsystem_sysname:
* @udev: udev library context
diff --git a/libudev/libudev-enumerate.c b/libudev/libudev-enumerate.c
index f13e56f2f7..363d445f90 100644
--- a/libudev/libudev-enumerate.c
+++ b/libudev/libudev-enumerate.c
@@ -714,22 +714,11 @@ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
continue;
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
struct udev_device *dev;
- char syspath[UTIL_PATH_SIZE];
- char *s;
- size_t l;
- ssize_t len;
if (dent->d_name[0] == '.')
continue;
- s = syspath;
- l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev), NULL);
- len = readlinkat(dirfd(dir), dent->d_name, s, l);
- if (len <= 0 || (size_t)len == l)
- continue;
- s[len] = '\0';
-
- dev = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
+ dev = udev_device_new_from_id_filename(udev_enumerate->udev, dent->d_name);
if (dev == NULL)
continue;
syspath_add(udev_enumerate, udev_device_get_syspath(dev));
diff --git a/libudev/libudev-private.h b/libudev/libudev-private.h
index d09a9a52a8..2b638ce06e 100644
--- a/libudev/libudev-private.h
+++ b/libudev/libudev-private.h
@@ -66,6 +66,7 @@ struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev);
/* libudev-device.c */
struct udev_device *udev_device_new(struct udev *udev);
+struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id);
int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath);
int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem);
int udev_device_set_devtype(struct udev_device *udev_device, const char *devtype);