]> err.no Git - systemd/commitdiff
libudev: device - export properties when values are set
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 16 Oct 2008 09:37:22 +0000 (11:37 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 16 Oct 2008 09:37:22 +0000 (11:37 +0200)
udev/lib/libudev-device.c
udev/lib/libudev-monitor.c

index 8afd68cc7666ddef1e12e2346ebe3db2e3ad5f58..acab263785a95fe4892989a765818e17b869936b 100644 (file)
@@ -35,6 +35,7 @@ struct udev_device {
        int refcount;
        struct udev *udev;
        struct udev_device *parent_device;
+       int parent_set;
        char *syspath;
        const char *devpath;
        char *sysname;
@@ -518,12 +519,12 @@ struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
 {
        if (udev_device == NULL)
                return NULL;
-
-       if (udev_device->parent_device != NULL) {
-               info(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
-               return udev_device->parent_device;
+       if (!udev_device->parent_set) {
+               udev_device->parent_set = 1;
+               udev_device->parent_device = device_new_from_parent(udev_device);
        }
-       udev_device->parent_device = device_new_from_parent(udev_device);
+       if (udev_device->parent_device != NULL)
+               info(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
        return udev_device->parent_device;
 }
 
@@ -1016,7 +1017,7 @@ int udev_device_set_action(struct udev_device *udev_device, const char *action)
        udev_device->action = strdup(action);
        if (udev_device->action == NULL)
                return -ENOMEM;
-       udev_device_add_property(udev_device, "ACTION", action);
+       udev_device_add_property(udev_device, "ACTION", udev_device->action);
        return 0;
 }
 
@@ -1027,6 +1028,7 @@ int udev_device_set_driver(struct udev_device *udev_device, const char *driver)
        if (udev_device->driver == NULL)
                return -ENOMEM;
        udev_device->driver_set = 1;
+       udev_device_add_property(udev_device, "DRIVER", udev_device->driver);
        return 0;
 }
 
@@ -1040,6 +1042,7 @@ int udev_device_set_devpath_old(struct udev_device *udev_device, const char *dev
        udev_device->devpath_old = strdup(devpath_old);
        if (udev_device->devpath_old == NULL)
                return -ENOMEM;
+       udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old);
        return 0;
 }
 
@@ -1081,13 +1084,24 @@ int udev_device_set_event_timeout(struct udev_device *udev_device, int event_tim
 
 int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
 {
+       char num[32];
+
        udev_device->seqnum = seqnum;
+       snprintf(num, sizeof(num), "%llu", seqnum);
+       udev_device_add_property(udev_device, "SEQNUM", num);
        return 0;
 }
 
 int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
 {
+       char num[32];
+
        udev_device->devnum = devnum;
+
+       snprintf(num, sizeof(num), "%u", major(devnum));
+       udev_device_add_property(udev_device, "MAJOR", num);
+       snprintf(num, sizeof(num), "%u", minor(devnum));
+       udev_device_add_property(udev_device, "MINOR", num);
        return 0;
 }
 
index dd8dfac3233778743eb460183c2bc9255a138678..382fbfac5ffbca49e1f704278672a7d81b21701c 100644 (file)
@@ -245,6 +245,8 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
        char buf[4096];
        size_t bufpos;
        int devpath_set = 0;
+       int subsystem_set = 0;
+       int action_set = 0;
        int maj = 0;
        int min = 0;
 
@@ -317,6 +319,7 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
                        devpath_set = 1;
                } else if (strncmp(key, "SUBSYSTEM=", 10) == 0) {
                        udev_device_set_subsystem(udev_device, &key[10]);
+                       subsystem_set = 1;
                } else if (strncmp(key, "DEVNAME=", 8) == 0) {
                        udev_device_set_devnode(udev_device, &key[8]);
                } else if (strncmp(key, "DEVLINKS=", 9) == 0) {
@@ -339,6 +342,7 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
                        udev_device_set_driver(udev_device, &key[7]);
                } else if (strncmp(key, "ACTION=", 7) == 0) {
                        udev_device_set_action(udev_device, &key[7]);
+                       action_set = 1;
                } else if (strncmp(key, "MAJOR=", 6) == 0) {
                        maj = strtoull(&key[6], NULL, 10);
                } else if (strncmp(key, "MINOR=", 6) == 0) {
@@ -351,12 +355,15 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
                        udev_device_set_seqnum(udev_device, strtoull(&key[7], NULL, 10));
                } else if (strncmp(key, "TIMEOUT=", 8) == 0) {
                        udev_device_set_timeout(udev_device, strtoull(&key[8], NULL, 10));
-               }
-               if (strncmp(key, "PHYSDEV", 7) == 0)
+               } else if (strncmp(key, "PHYSDEV", 7) == 0) {
+                       /* skip deprecated values */
                        continue;
-               udev_device_add_property_from_string(udev_device, key);
+               } else {
+                       udev_device_add_property_from_string(udev_device, key);
+               }
        }
-       if (!devpath_set) {
+       if (!devpath_set || !subsystem_set || !action_set) {
+               info(udev_monitor->udev, "missing values, skip\n");
                udev_device_unref(udev_device);
                return NULL;
        }