summaryrefslogtreecommitdiffstats
path: root/discover/device-handler.c
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2016-09-05 14:21:23 +1000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2016-09-08 14:26:27 +1000
commit1def8f21aecc41ac22652e7b8bd1f5bf7a4dae98 (patch)
tree34ce7ff6feff3181c4312b80aad4af391ba94277 /discover/device-handler.c
parent4da0965a861bedd4332217c131abf399bc2b5a18 (diff)
downloadtalos-petitboot-1def8f21aecc41ac22652e7b8bd1f5bf7a4dae98.tar.gz
talos-petitboot-1def8f21aecc41ac22652e7b8bd1f5bf7a4dae98.zip
discover: Pass UUID to discover_device_create()
Currently discover_device_create() will search for existing discover devices by id to determine if a new device is required. However it is possible under some circumstances for distinct devices to have the same name. This is especially troublesome if the following network events are seen in network_handle_nlmsg(): - New interface, 'foo' with uuid x:x:x:x:x:x -> new discover device created with dev->device->id = 'foo' dev->uuid = x:x:x:x:x:x - New interface, 'foo' with uuid y:y:y:y:y:y -> existing device 'foo' found dev->uuid = y:y:y:y:y:y This can occur if an interface rename event arrives *after* an old name is reused, where temporarily Petitboot will see two distinct network interfaces with the same name. Now the two interfaces point to the same discover device, which can quickly result in a segfault if a 'remove' event occurs for one of the interfaces and the discover device is freed. To generally avoid this a 'uuid' parameter is added to discover_device_create(), which if present allows existing devices to be looked up by UUID rather than just their name. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/device-handler.c')
-rw-r--r--discover/device-handler.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index 54a1986..70e4506 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -221,17 +221,22 @@ static int destroy_device(void *arg)
}
struct discover_device *discover_device_create(struct device_handler *handler,
- const char *id)
+ const char *uuid, const char *id)
{
struct discover_device *dev;
- dev = device_lookup_by_id(handler, id);
+ if (uuid)
+ dev = device_lookup_by_uuid(handler, uuid);
+ else
+ dev = device_lookup_by_id(handler, id);
+
if (dev)
return dev;
dev = talloc_zero(handler, struct discover_device);
dev->device = talloc_zero(dev, struct device);
dev->device->id = talloc_strdup(dev->device, id);
+ dev->uuid = talloc_strdup(dev, uuid);
list_init(&dev->params);
list_init(&dev->boot_options);
@@ -1138,7 +1143,7 @@ void device_handler_process_url(struct device_handler *handler,
goto msg;
}
- dev = discover_device_create(handler, event->device);
+ dev = discover_device_create(handler, mac, event->device);
if (pb_url->scheme == pb_url_file)
dev->device->type = DEVICE_TYPE_ANY;
ctx = device_handler_discover_context_create(handler, dev);
@@ -1171,7 +1176,7 @@ void device_handler_discover_context_commit(struct device_handler *handler,
struct discover_device *dev = ctx->device;
struct discover_boot_option *opt, *tmp;
- if (!device_lookup_by_id(handler, dev->device->id))
+ if (!device_lookup_by_uuid(handler, dev->uuid))
device_handler_add_device(handler, dev);
/* move boot options from the context to the device */
OpenPOWER on IntegriCloud