]> err.no Git - systemd/commitdiff
libudev: udev_device - read "driver" value
authorKay Sievers <kay.sievers@vrfy.org>
Tue, 9 Sep 2008 16:14:54 +0000 (18:14 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Tue, 9 Sep 2008 16:14:54 +0000 (18:14 +0200)
udev/lib/libudev-device.c
udev/lib/libudev-private.h
udev/lib/libudev-utils.c
udev/lib/test-libudev.c

index 00b9440386171542f294bbbcb2f6f6393ec01108..578afe7ec2d4e77bf707faed29da7063121a7417 100644 (file)
@@ -346,8 +346,15 @@ int udev_device_get_properties(struct udev_device *udev_device,
 
 const char *udev_device_get_driver(struct udev_device *udev_device)
 {
+       char driver[NAME_SIZE];
+
        if (udev_device == NULL)
                return NULL;
+       if (udev_device->driver != NULL)
+               return udev_device->driver;
+       if (util_get_sys_driver(udev_device->udev, udev_device->devpath, driver, sizeof(driver)) < 2)
+               return NULL;
+       udev_device->driver = strdup(driver);
        return udev_device->driver;
 }
 
index 53a58cc6198db859c3311091fd33738c662e14b8..bc91927bed61de9dd63af1d3d60edbc03053a037 100644 (file)
@@ -99,4 +99,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);
 #endif
index 8251b64da98b492dc63f2f7ec8cc5d52294bdad8..82acb1a4815705d5a36ee01cb1470d89e20a5e9c 100644 (file)
@@ -32,7 +32,7 @@
 #include "libudev-private.h"
 #include "../udev.h"
 
-ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
+static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *devpath, char *subsystem, size_t size)
 {
        char path[PATH_SIZE];
        ssize_t len;
@@ -40,7 +40,8 @@ ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *sub
 
        strlcpy(path, udev_get_sys_path(udev), sizeof(path));
        strlcat(path, devpath, sizeof(path));
-       strlcat(path, "/subsystem", sizeof(path));
+       strlcat(path, "/", sizeof(path));
+       strlcat(path, slink, sizeof(path));
        len = readlink(path, path, sizeof(path));
        if (len < 0 || len >= (ssize_t) sizeof(path))
                return -1;
@@ -51,3 +52,14 @@ ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *sub
        pos = &pos[1];
        return strlcpy(subsystem, pos, size);
 }
+
+ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
+{
+       return get_sys_link(udev, "subsystem", devpath, subsystem, size);
+}
+
+ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size)
+{
+       return get_sys_link(udev, "driver", devpath, driver, size);
+}
+
index 835536af84645d75b3d312d85f6cc7517d10793b..4fdef68881211f609259b16e1b2dec51fc17c75e 100644 (file)
@@ -58,6 +58,8 @@ static void print_device(struct udev_device *device)
        printf("devpath:   '%s'\n", str);
        str = udev_device_get_subsystem(device);
        printf("subsystem: '%s'\n", str);
+       str = udev_device_get_driver(device);
+       printf("driver:    '%s'\n", str);
        str = udev_device_get_syspath(device);
        printf("syspath:   '%s'\n", str);
        str = udev_device_get_devname(device);