diff options
Diffstat (limited to 'discover/device-handler.c')
-rw-r--r-- | discover/device-handler.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c index 0c0a9a7..94a3f1c 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -87,6 +87,7 @@ struct device_handler { struct plugin_option **plugins; unsigned int n_plugins; + bool plugin_installing; }; static int mount_device(struct discover_device *dev); @@ -1406,6 +1407,61 @@ void device_handler_process_url(struct device_handler *handler, talloc_unlink(handler, ctx); } +static void plugin_install_cb(struct process *process) +{ + struct device_handler *handler = process->data; + + if (!handler) { + pb_log("%s: Missing data!\n", __func__); + return; + } + + handler->plugin_installing = false; + if (process->exit_status) { + device_handler_status_err(handler, "Plugin failed to install!"); + pb_log("Failed to install plugin:\n%s\n", process->stdout_buf); + } +} + +void device_handler_install_plugin(struct device_handler *handler, + const char *plugin_file) +{ + struct process *p; + int result; + + if (handler->plugin_installing) { + pb_log("Plugin install cancelled - install already running"); + return; + } + + p = process_create(handler); + if (!p) { + pb_log("install_plugin: Failed to create process\n"); + return; + } + + const char *argv[] = { + pb_system_apps.pb_plugin, + "install", + "auto", + plugin_file, + NULL + }; + + p->path = pb_system_apps.pb_plugin; + p->argv = argv; + p->exit_cb = plugin_install_cb; + p->data = handler; + p->keep_stdout = true; + + result = process_run_async(p); + + if (result) + device_handler_status_err(handler, "Could not install plugin"); + else + handler->plugin_installing = true; +} + #ifndef PETITBOOT_TEST /** |