summaryrefslogtreecommitdiffstats
path: root/discover
diff options
context:
space:
mode:
Diffstat (limited to 'discover')
-rw-r--r--discover/device-handler.c56
-rw-r--r--discover/device-handler.h2
-rw-r--r--discover/discover-server.c6
3 files changed, 64 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
/**
diff --git a/discover/device-handler.h b/discover/device-handler.h
index c1bbe7d..a95cc9d 100644
--- a/discover/device-handler.h
+++ b/discover/device-handler.h
@@ -159,6 +159,8 @@ void device_handler_update_config(struct device_handler *handler,
struct config *config);
void device_handler_process_url(struct device_handler *handler,
const char *url, const char *mac, const char *ip);
+void device_handler_install_plugin(struct device_handler *handler,
+ const char *plugin_file);
void device_handler_reinit(struct device_handler *handler);
int device_request_write(struct discover_device *dev, bool *release);
diff --git a/discover/discover-server.c b/discover/discover-server.c
index e2e87ca..57cf3b7 100644
--- a/discover/discover-server.c
+++ b/discover/discover-server.c
@@ -304,6 +304,12 @@ static int discover_server_process_message(void *arg)
url, NULL, NULL);
break;
+ case PB_PROTOCOL_ACTION_PLUGIN_INSTALL:
+ url = pb_protocol_deserialise_string((void *) client, message);
+
+ device_handler_install_plugin(client->server->device_handler,
+ url);
+ break;
default:
pb_log("%s: invalid action %d\n", __func__, message->action);
return 0;
OpenPOWER on IntegriCloud