From patchwork Fri Jun 23 06:27:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 779810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wv7my440Vz9s7v for ; Fri, 23 Jun 2017 16:28:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="N/QBavk0"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wv7my23VBzDqnT for ; Fri, 23 Jun 2017 16:28:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="N/QBavk0"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from mendozajonas.com (mendozajonas.com [188.166.185.233]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wv7m76PTVzDqjL for ; Fri, 23 Jun 2017 16:27:35 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="N/QBavk0"; dkim-atps=neutral Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: sam@mendozajonas.com) by mendozajonas.com (Postfix) with ESMTPSA id 929591441AA; Fri, 23 Jun 2017 14:27:33 +0800 (SGT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mendozajonas.com; s=mail; t=1498199254; bh=iJ9FErZDESrqFHZa1t02Yw9cRG8DtfouKPewWT2VFaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N/QBavk0Jiq+112Y+NOTK1ON01RiTCy4dQjjayn+/gFATnaFwz0OmbLFnAijVriuT xo+HgEFYtb6Dwx0bNRRVSJ3KOrvAsZO9EHHPQOaBSEcSuJhD/TKHHHUXjG468TOOWK uu75G+q11oG5+HV9aOnRsKolPzx/A2XUKq5eBUTc= From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 08/10] discover: Handle plugin install request Date: Fri, 23 Jun 2017 16:27:07 +1000 Message-Id: <20170623062709.16035-9-sam@mendozajonas.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170623062709.16035-1-sam@mendozajonas.com> References: <20170623062709.16035-1-sam@mendozajonas.com> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" 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 --- discover/device-handler.c | 55 +++++++++++++++++++++++++++++++++++++++++++ discover/device-handler.h | 2 ++ discover/discover-server.c | 6 +++++ lib/pb-protocol/pb-protocol.h | 1 + 4 files changed, 64 insertions(+) diff --git a/discover/device-handler.c b/discover/device-handler.c index 02a95d8..b72508b 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); @@ -1345,6 +1346,60 @@ 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) + handler->plugin_installing = false; + else + pb_log("%s: Missing data!\n", __func__); + + 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; diff --git a/lib/pb-protocol/pb-protocol.h b/lib/pb-protocol/pb-protocol.h index ce876d0..250c2d1 100644 --- a/lib/pb-protocol/pb-protocol.h +++ b/lib/pb-protocol/pb-protocol.h @@ -25,6 +25,7 @@ enum pb_protocol_action { PB_PROTOCOL_ACTION_ADD_URL = 0xb, PB_PROTOCOL_ACTION_PLUGIN_OPTION_ADD = 0xc, PB_PROTOCOL_ACTION_PLUGINS_REMOVE = 0xd, + PB_PROTOCOL_ACTION_PLUGIN_INSTALL = 0xe, }; struct pb_protocol_message {