summaryrefslogtreecommitdiffstats
path: root/discover/device-handler.c
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2017-06-16 15:09:55 +1000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2017-08-15 13:38:17 +1000
commit37feda62bd2835eabc779d275301a9b763521f7a (patch)
tree6a92baf2ea721f2bc55551f16c9f5651ed83949c /discover/device-handler.c
parentff54a215f0ce4c25262b24038841b58274cc51d3 (diff)
downloadtalos-petitboot-37feda62bd2835eabc779d275301a9b763521f7a.tar.gz
talos-petitboot-37feda62bd2835eabc779d275301a9b763521f7a.zip
discover: Handle plugin install request
Handle "_PLUGIN_INSTALL" requests from clients. Calling the pb-plugin script from pb-discover ensures different clients don't trip over each other. Successfully installed plugins are automatically communicated back to clients once pb-plugin sends a 'plugin' user event. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/device-handler.c')
-rw-r--r--discover/device-handler.c56
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
/**
OpenPOWER on IntegriCloud