From patchwork Tue Jul 25 06:49:02 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: 793226 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xGplL5D3zz9s0g for ; Tue, 25 Jul 2017 16:50:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="BqU4zqMB"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="hbJnMe2+"; 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 3xGplL43WrzDqnj for ; Tue, 25 Jul 2017 16:50:06 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="BqU4zqMB"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="hbJnMe2+"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from new2-smtp.messagingengine.com (new2-smtp.messagingengine.com [66.111.4.224]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xGpkp52K2zDqlC for ; Tue, 25 Jul 2017 16:49:38 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="BqU4zqMB"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="hbJnMe2+"; dkim-atps=neutral Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 906ED13E2; Tue, 25 Jul 2017 02:49:36 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute2.internal (MEProxy); Tue, 25 Jul 2017 02:49:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= mendozajonas.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=rvFEmVaBGsN7IPJdk4VC1UmF5hDaxHrkKqDtyCl5y 2M=; b=BqU4zqMBlexCo13LDOqCe4RIwKyCZejzAqvzYAPGmvWcMZDGXg65SN8c1 FJVm4qO2mBqO6MPFSGlDiAWP8BKxVaW/Y/2F4vnVdjXVguKnqfQIrwIQt+JhRL5R tBYBHmNcWdEx4COcwYvhHH5EMCIRHfjikx+e+F6ioOwhaaxsEmWFd9u+kJD0420c dKRZu64YwF5Rz4Xvmm5u9ZojIE1oXueH9VGHg1lcY0vrDkcH1rK6gMiYDbmk5/dF 3+qQo813ELHJUZxHlo1j1jKQ2q1DA9GrNXFDrfdrCr/3TdkoqSMvnnsmXCBeZ//L 49jw9dIpLnszgjF3PxDxpa+CaLDgw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=rvFEmVaBGsN7IPJdk4VC1UmF5hDaxHrkKqDtyCl5y 2M=; b=hbJnMe2+qHr9Xebx9ifKacRqCzG7Yt4qfMhT/xUnPg/qwKS5xJAxGUNrX eeSSatYOW7cSwlPtGnWcpHvD3JCrhYCn54oh+qSMgsC74misBm2JNs3G+SJXUnq9 agiRznZ9Jryu++3/s2zrLxdZcQXQHfNEmts0k7ovA30GYSlufMduitzA4go5N4Oc DlMGpyAynW9pch+xD1Pu9SdSQ6nNUM5CZrjsaoRBF9OMegA8biYIDbYGivzPkoWd OkkqRA9mDofWi5mKzlfOJGTzL3G0SATrfSibgRiY4iVHPctePV28aCJKTco16w7L DVNeOlZIjp1UGIUuU0u1hjRAAsvGA== X-ME-Sender: X-Sasl-enc: v6qGorB5grkgTd5PaOjnAdBIQZhWA8rvF7hFQeuD97i2 1500965375 Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id D836E245AD; Tue, 25 Jul 2017 02:49:34 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 04/12] discover: Add 'plugin' user-event Date: Tue, 25 Jul 2017 16:49:02 +1000 Message-Id: <20170725064910.31478-5-sam@mendozajonas.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170725064910.31478-1-sam@mendozajonas.com> References: <20170725064910.31478-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 pb-plugins and add them to the device_handler. Plugins described by this event can either be uninstalled pb-plugin files or successfully installed pb-plugins depending on the associated parameters. The is primarily intended for use by the pb-plugin utility itself to notify Petitboot as it operates on pb-plugin files. Signed-off-by: Samuel Mendoza-Jonas --- discover/event.c | 2 + discover/event.h | 1 + discover/user-event.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 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..77d28c1 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,111 @@ static int user_event_sync(struct user_event *uev, struct event *event) return 0; } +static int process_uninstalled_plugin(struct user_event *uev, + struct event *event) +{ + struct device_handler *handler = uev->handler; + struct discover_boot_option *file_opt; + struct discover_device *device; + struct discover_context *ctx; + const char *path; + struct resource *res; + + if (!event_get_param(event, "path")) { + pb_log("Uninstalled pb-plugin event missing path param\n"); + return -1; + } + + device = device_lookup_by_name(handler, event->device); + if (!device) { + pb_log("Couldn't find device matching %s for plugin\n", + event->device); + return -1; + } + + ctx = device_handler_discover_context_create(handler, device); + file_opt = discover_boot_option_create(ctx, device); + file_opt->option->name = talloc_strdup(file_opt, + event_get_param(event, "name")); + file_opt->option->id = talloc_asprintf(file_opt, "%s@%p", + device->device->id, file_opt); + file_opt->option->type = DISCOVER_PLUGIN_OPTION; + + + path = event_get_param(event, "path"); + /* path may be relative to root */ + if (strncmp(device->mount_path, path, strlen(device->mount_path)) == 0) { + path += strlen(device->mount_path) + 1; + } + + res = talloc(file_opt, struct resource); + resolve_resource_against_device(res, device, path); + file_opt->boot_image = res; + + discover_context_add_boot_option(ctx, file_opt); + device_handler_discover_context_commit(handler, ctx); + + return 0; +} + +/* + * Notification of a plugin event. This can either be for an uninstalled plugin + * that pb-plugin has scanned, or the result of a plugin that pb-plugin has + * installed. + */ +static int user_event_plugin(struct user_event *uev, struct event *event) +{ + struct device_handler *handler = uev->handler; + char *executable, *executables, *saveptr; + struct plugin_option *opt; + const char *installed; + + installed = event_get_param(event, "installed"); + if (!installed || strncmp(installed, "no", strlen("no")) == 0) + return process_uninstalled_plugin(uev, event); + + 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 +628,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; }