diff options
author | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-08-20 16:09:58 +1000 |
---|---|---|
committer | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-08-28 13:46:03 +1000 |
commit | 7f5a99f015cb1f48f73acb921beced6daf9fa15d (patch) | |
tree | 89f78cd714b4b5692feb4999afa55db550d51602 /discover/device-handler.c | |
parent | 27c55969c0678e48893be5aa630b657a0eae7530 (diff) | |
download | talos-petitboot-7f5a99f015cb1f48f73acb921beced6daf9fa15d.tar.gz talos-petitboot-7f5a99f015cb1f48f73acb921beced6daf9fa15d.zip |
discover: Let 'boot' user-event boot by name
If a 'name' parameter is used for a boot user event, search existing
boot options for one that matches that name on the given device.
This allows a pb-event user to boot based on name rather than having to
specify the exact boot arguments.
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/device-handler.c')
-rw-r--r-- | discover/device-handler.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c index 9c05029..cf379e7 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -1404,6 +1404,28 @@ int device_handler_dhcp(struct device_handler *handler, return 0; } +struct discover_boot_option *device_handler_find_option_by_name( + struct device_handler *handler, const char *device, + const char *name) +{ + size_t len = strlen(name); + unsigned int i; + + for (i = 0; i < handler->n_devices; i++) { + struct discover_device *dev = handler->devices[i]; + struct discover_boot_option *opt; + + list_for_each_entry(&dev->boot_options, opt, list) + /* Match exactly, partial matches can be quite common */ + if (strlen(opt->option->name) == len && + !strcmp(opt->option->name, name)) + if (!dev || !strcmp(opt->option->device_id, device)) + return opt; + } + + return NULL; +} + static struct discover_boot_option *find_boot_option_by_id( struct device_handler *handler, const char *id) { |