]> err.no Git - systemd/commitdiff
udevd: switch to common id_filename functions
authorKay Sievers <kay.sievers@vrfy.org>
Sun, 12 Dec 2010 19:07:15 +0000 (20:07 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Sun, 12 Dec 2010 19:07:15 +0000 (20:07 +0100)
libudev/libudev-device-private.c
libudev/libudev-device.c
libudev/libudev-enumerate.c
libudev/libudev-private.h
udev/udev-node.c
udev/udev-watch.c

index bf93834c10a7353eb03980caa04aad46bd4b581b..430e3e64d4dbe74049515bad6e3c19324cccb3c8 100644 (file)
@@ -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);
        }
index ac206a0e16700b14c156483516957490149c69bf..8698d98e1c6871ee7ea3c2ddf88f95c75fe2fa95 100644 (file)
@@ -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
index f13e56f2f7f72a57bba96ee0ebe4501c924c1b9d..363d445f90a5f63a569cf4d1d15378456b119180 100644 (file)
@@ -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));
index d09a9a52a89436d4b601f4175ce93018d4045a69..2b638ce06eb3d4baeca17932ea6a0193268cf201 100644 (file)
@@ -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);
index a9ffa988b14f0f3d66645b12d949c8e1d42979ee..0ceb1d5110b0642102a6b49e10eb8a807c8908d4 100644 (file)
@@ -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;
 
index 9e1b8d8553e3650f39519df602153072281a04ce..f51a10dcabdd410589f3cdcdf1fd4386044d6214 100644 (file)
@@ -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);
 }