summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--udev/udev-node.c14
-rw-r--r--udev/udev-watch.c14
6 files changed, 39 insertions, 35 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);
diff --git a/udev/udev-node.c b/udev/udev-node.c
index a9ffa988b1..0ceb1d5110 100644
--- a/udev/udev-node.c
+++ b/udev/udev-node.c
@@ -243,26 +243,20 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons
for (;;) {
struct udev_device *dev_db;
struct dirent *dent;
- int maj, min;
- char type, type2;
- dev_t devnum;
dent = readdir(dir);
if (dent == NULL || dent->d_name[0] == '\0')
break;
if (dent->d_name[0] == '.')
continue;
- if (sscanf(dent->d_name, "%c%i:%i", &type, &maj, &min) != 3)
- continue;
- info(udev, "found '%c%i:%i' claiming '%s'\n", type, maj, min, stackdir);
- devnum = makedev(maj, min);
+
+ info(udev, "found '%s' claiming '%s'\n", dent->d_name, stackdir);
/* did we find ourself? */
- type2 = strcmp(udev_device_get_subsystem(dev), "block") == 0 ? 'b' : 'c';
- if (udev_device_get_devnum(dev) == devnum && type == type2)
+ if (strcmp(dent->d_name, udev_device_get_id_filename(dev)) == 0)
continue;
- dev_db = udev_device_new_from_devnum(udev, type, devnum);
+ dev_db = udev_device_new_from_id_filename(udev, dent->d_name);
if (dev_db != NULL) {
const char *devnode;
diff --git a/udev/udev-watch.c b/udev/udev-watch.c
index 9e1b8d8553..f51a10dcab 100644
--- a/udev/udev-watch.c
+++ b/udev/udev-watch.c
@@ -72,8 +72,6 @@ void udev_watch_restore(struct udev *udev)
size_t l;
ssize_t len;
struct udev_device *dev;
- int maj, min;
- char type;
if (ent->d_name[0] == '.')
continue;
@@ -85,9 +83,7 @@ void udev_watch_restore(struct udev *udev)
goto unlink;
s[len] = '\0';
- if (sscanf(s, "%c%i:%i", &type, &maj, &min) != 3)
- goto unlink;
- dev = udev_device_new_from_devnum(udev, type, makedev(maj, min));
+ dev = udev_device_new_from_id_filename(udev, s);
if (dev == NULL)
goto unlink;
@@ -158,9 +154,6 @@ struct udev_device *udev_watch_lookup(struct udev *udev, int wd)
char *s;
size_t l;
ssize_t len;
- int maj, min;
- char type;
- dev_t devnum;
if (inotify_fd < 0 || wd < 0)
return NULL;
@@ -173,8 +166,5 @@ struct udev_device *udev_watch_lookup(struct udev *udev, int wd)
return NULL;
s[len] = '\0';
- if (sscanf(s, "%c%i:%i", &type, &maj, &min) != 3)
- return NULL;
- devnum = makedev(maj, min);
- return udev_device_new_from_devnum(udev, type, devnum);
+ return udev_device_new_from_id_filename(udev, s);
}