]> git.ozlabs.org Git - petitboot/blobdiff - discover/udev.c
utils/pb-udhcpc: Fix incorrect reference to $interface
[petitboot] / discover / udev.c
index 80029d6820d225f001940d696ec3c67c63ced878..3127ec25edc68dbc1cf484b973f76905c3ae0ebc 100644 (file)
@@ -1,5 +1,7 @@
 
-#define _GNU_SOURCE
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
 
 #include <assert.h>
 #include <errno.h>
@@ -62,7 +64,7 @@ static int udev_handle_dev_add(struct pb_udev *udev, struct udev_device *dev)
 {
        struct discover_device *ddev;
        const char *typestr;
-       const char *serial;
+       const char *uuid;
        const char *path;
        const char *name;
        const char *node;
@@ -112,23 +114,28 @@ static int udev_handle_dev_add(struct pb_udev *udev, struct udev_device *dev)
                return -1;
        }
 
-       /* we may also see multipath devices; same dev nodes (hence id), but
-        * different serial numbers */
-       serial = udev_device_get_property_value(dev, "ID_SERIAL");
-       if (serial && device_lookup_by_serial(udev->handler, serial))
-               return -1;
+       /* We may see multipath devices; they'll have the same uuid as an
+        * existing device, so only parse the first. */
+       uuid = udev_device_get_property_value(dev, "ID_FS_UUID");
+       if (uuid) {
+               ddev = device_lookup_by_uuid(udev->handler, uuid);
+               if (ddev) {
+                       pb_log("SKIP: %s UUID [%s] already present (as %s)\n",
+                                       name, uuid, ddev->device->id);
+                       return -1;
+               }
+       }
 
        ddev = discover_device_create(udev->handler, name);
 
        ddev->device_path = talloc_strdup(ddev, node);
 
-       prop = udev_device_get_property_value(dev, "ID_FS_UUID");
-       if (prop)
-               ddev->uuid = talloc_strdup(ddev, prop);
+       if (uuid)
+               ddev->uuid = talloc_strdup(ddev, uuid);
        prop = udev_device_get_property_value(dev, "ID_FS_LABEL");
        if (prop)
                ddev->label = talloc_strdup(ddev, prop);
-       ddev->device->type = DEVICE_TYPE_DISK;
+       ddev->device->type = cdrom ? DEVICE_TYPE_OPTICAL : DEVICE_TYPE_DISK;
 
        udev_setup_device_params(dev, ddev);