X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=f1270c8ca660b7c771f0e08023e4559345f1e5bc;hb=675eb751ff84e80f286da808daa931a84baf9302;hp=0c0a9a78818bed53c0596390b927ebd571704e98;hpb=ff54a215f0ce4c25262b24038841b58274cc51d3;p=petitboot diff --git a/discover/device-handler.c b/discover/device-handler.c index 0c0a9a7..f1270c8 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 /** @@ -1507,6 +1563,10 @@ static void device_handler_update_lang(const char *lang) static int device_handler_init_sources(struct device_handler *handler) { /* init our device sources: udev, network and user events */ + handler->user_event = user_event_init(handler, handler->waitset); + if (!handler->user_event) + return -1; + handler->network = network_init(handler, handler->waitset, handler->dry_run); if (!handler->network) @@ -1516,10 +1576,6 @@ static int device_handler_init_sources(struct device_handler *handler) if (!handler->udev) return -1; - handler->user_event = user_event_init(handler, handler->waitset); - if (!handler->user_event) - return -1; - return 0; }