From patchwork Fri Jun 23 06:27:06 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: 779808 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 3wv7mp07jRz9s7v for ; Fri, 23 Jun 2017 16:28:10 +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="TY3Cx9uh"; 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 3wv7mn65bYzDqkM for ; Fri, 23 Jun 2017 16:28:09 +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="TY3Cx9uh"; 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 3wv7m73b2KzDqjM 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="TY3Cx9uh"; 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 CAA22143F85; Fri, 23 Jun 2017 14:27:32 +0800 (SGT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mendozajonas.com; s=mail; t=1498199253; bh=m4SKm7SVjZcoJ+qSonUYMpj+l02m7Bxwmybk/gIJelM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TY3Cx9uhPjorvlHjuHTXgjlGL8Q9Rvc8FMr0hpLzf72gB4VV6s0f/B+EALDbff7jp q8A5eS+jyQSAN2ad7kcI78FC144J/IDcO5zMNMRYntO7QgE/mILfWS1DNjgGdbLZ9V XhQCkkj/9AZWo/1amHeA5Y/X0NYSRJgD7LjSmrmI= From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 07/10] discover: Add 'plugin' user-event Date: Fri, 23 Jun 2017 16:27:06 +1000 Message-Id: <20170623062709.16035-8-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" Add a new user event to advertise installed pb-plugins and add them to the device_handler. The intended use case for this is to enable pb-plugin to inform pb-discover of new plugins as it installs them. Signed-off-by: Samuel Mendoza-Jonas --- discover/event.c | 2 ++ discover/event.h | 1 + discover/user-event.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ utils/pb-plugin | 6 ++++++ 4 files changed, 66 insertions(+) diff --git a/discover/event.c b/discover/event.c index 1be19eb..047e928 100644 --- a/discover/event.c +++ b/discover/event.c @@ -55,6 +55,8 @@ static int event_parse_ad_header(char *buf, int len, enum event_action *action, *action = EVENT_ACTION_BOOT; else if (streq(buf, "sync")) *action = EVENT_ACTION_SYNC; + else if (streq(buf, "plugin")) + *action = EVENT_ACTION_PLUGIN; else { pb_log("%s: unknown action: %s\n", __func__, buf); return -1; diff --git a/discover/event.h b/discover/event.h index a639d9c..1f6966c 100644 --- a/discover/event.h +++ b/discover/event.h @@ -14,6 +14,7 @@ enum event_action { EVENT_ACTION_DHCP, EVENT_ACTION_BOOT, EVENT_ACTION_SYNC, + EVENT_ACTION_PLUGIN, EVENT_ACTION_MAX, }; diff --git a/discover/user-event.c b/discover/user-event.c index fb3fddb..98d5948 100644 --- a/discover/user-event.c +++ b/discover/user-event.c @@ -63,6 +63,8 @@ static const char *event_action_name(enum event_action action) return "boot"; case EVENT_ACTION_SYNC: return "sync"; + case EVENT_ACTION_PLUGIN: + return "plugin"; default: break; } @@ -486,6 +488,58 @@ static int user_event_sync(struct user_event *uev, struct event *event) return 0; } +/* Notification that a plugin has been installed. These are represented by a + * plugin_option struct which is added to the device_handler and then sent to + * clients. + */ +static int user_event_plugin(struct user_event *uev, struct event *event) +{ + struct device_handler *handler = uev->handler; + struct plugin_option *opt; + char *executable, *executables, *saveptr; + + opt = talloc_zero(handler, struct plugin_option); + if (!opt) + return -1; + opt->name = talloc_strdup(opt, event_get_param(event, "name")); + opt->id = talloc_strdup(opt, event_get_param(event, "id")); + opt->version = talloc_strdup(opt, event_get_param(event, "version")); + opt->vendor = talloc_strdup(opt, event_get_param(event, "vendor")); + opt->vendor_id = talloc_strdup(opt, event_get_param(event, "vendor_id")); + opt->date = talloc_strdup(opt, event_get_param(event, "date")); + opt->plugin_file = talloc_strdup(opt, + event_get_param(event, "source_file")); + + executables = talloc_strdup(opt, event_get_param(event, "executables")); + if (!executables) { + talloc_free(opt); + return -1; + } + + /* + * The 'executables' parameter is a space-delimited list of installed + * executables + */ + executable = strtok_r(executables, " ", &saveptr); + while (executable) { + opt->executables = talloc_realloc(opt, opt->executables, + char *, opt->n_executables + 1); + if (!opt->executables) { + talloc_free(opt); + return -1; + } + opt->executables[opt->n_executables++] = talloc_strdup(opt, + executable); + executable = strtok_r(NULL, " ", &saveptr); + } + + device_handler_add_plugin_option(handler, opt); + + talloc_free(executables); + + return 0; +} + static void user_event_handle_message(struct user_event *uev, char *buf, int len) { @@ -521,6 +575,9 @@ static void user_event_handle_message(struct user_event *uev, char *buf, case EVENT_ACTION_SYNC: result = user_event_sync(uev, event); break; + case EVENT_ACTION_PLUGIN: + result = user_event_plugin(uev, event); + break; default: break; } diff --git a/utils/pb-plugin b/utils/pb-plugin index 1a03f23..2021e9d 100755 --- a/utils/pb-plugin +++ b/utils/pb-plugin @@ -231,6 +231,12 @@ do_install() __create_wrapper "$__dest" "$binary" done + pb-event plugin@local \ + name=$PLUGIN_NAME id=$PLUGIN_ID version=$PLUGIN_VERSION \ + vendor=$PLUGIN_VENDOR vendor_id=$PLUGIN_VENDOR_ID \ + date=$PLUGIN_DATE executables="$PLUGIN_EXECUTABLES" \ + source_file=$url + echo "Plugin installed" plugin_info }