Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1443798rdb; Wed, 24 Jan 2024 16:07:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYFLFuQa1rny/vwc8rRx86aQWUZxapFR5LLxrAdKktIDPBRs5dSHQ73x/4cKnFtIa/AAOU X-Received: by 2002:a05:6a00:22d6:b0:6da:ca92:3e2e with SMTP id f22-20020a056a0022d600b006daca923e2emr412615pfj.7.1706141278835; Wed, 24 Jan 2024 16:07:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706141278; cv=pass; d=google.com; s=arc-20160816; b=WQPo+JjFXO+6rM+ICgdbrwnlDLTOskUfGt74mi5ggXrypv0uFmHKAvh00PY3wsuOFF 73EON7DRtTYg9qbBafNVQFCnNsYFcUm1RzOs6p+hplgut4fnRfhaeSrdEaLh9h4eOMZR NtqQCOMsCyfDJdgRP2MYCGR3g5SGWV2gtNwUDFc/k1wl5M3723gdJ0RAHxrn6DGaM7xZ xg53EYWfEaF4/Q2M89k1sG8Omg+buBLq4qcQQkATUZZuyKP3IFKv/d9W7bMEDIKSXBCV 2mPpVAUa1IhHb5AMn2EVz1u7Pf7zYiwxtV0+OHDSpeXKADUK6hwz0k8TqfF2hOtNTE/F ZOgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=dN8+szbJwrsVZicVFdvA9b5NzWstDNV9GTNp87jFcKE=; fh=wm3knQjNzlzhSYO3l6/R1dJNTO7aXLaAzT309a/t7Bw=; b=pj04gi03TTrq4ylZuh2u5I8hdct2YtZQoy1RfLyfzvwa1LHATAWUxteWuifrln/fpS pmDhirCu+dZLuqDC5j4bQsUJ4kO0aA+vQI16Ov5XrnSy0L01YCJIUYeDPTFz07dIhFjn 1so2qXW4EbjXYJWrvGxkQzbWuUWcK+VaucAMPFKvoVh9RPiPlJBxI5EtF0+VMefaiTE3 J+Ym4RUqoDRomXKyVXd6VeIT6aeDIgBE9TCqLypJb5Ehhklqy3wZZq1fcB55BtY0o+0g oTxcFJAsQmdcgOVhycsXsslGIeCMM1aNIKFjzfe8Lyiuscx2B5oOndw0vQ/VcNq3CePq +ISQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="io/b2CsC"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-bluetooth+bounces-1338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q19-20020aa79833000000b006dd839fed5fsi2728355pfl.232.2024.01.24.16.07.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 16:07:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-1338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="io/b2CsC"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-bluetooth+bounces-1338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A9A49B22CB6 for ; Thu, 25 Jan 2024 00:07:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D026363D1; Thu, 25 Jan 2024 00:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="io/b2CsC" X-Original-To: linux-bluetooth@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE64F399 for ; Thu, 25 Jan 2024 00:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706141249; cv=none; b=UHPDcsgyFWk8Ic1aLX/7JrpL9OfPGpCwSHZI7KEVMKP31IxMEcY329oyZG4xCco9VeIuDtPY3lxe5/DGlDC9K/HuyH/bVbuyY9kOHOKf3NA1LwNAJdRiT3MOwUtCl6NwpQdBngdF8QD+9qwPtax/gXA+oIYKvU8hUjoZKfMX+Dg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706141249; c=relaxed/simple; bh=G9genvZ+XzEEPgL5CU4jnpFYI5JsJj4sQ/6exI14zAQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oxZUItQDIOw7E+QEF/ojyqGPdP8LYwjyGKfRwZOfNUwXOLs3tvPwrXYLSFyN5Zu33/W2i/vG72anS2B7YJLHhUifxF/ITAgRCQalTGsJ2saSQwHekcUw5DYilOIKmflIVn9Z2sSa6tGSJpQqcpgeCjwCAoouQdbBtfZ99kV7oCY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=io/b2CsC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 819D7C43330; Thu, 25 Jan 2024 00:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706141249; bh=G9genvZ+XzEEPgL5CU4jnpFYI5JsJj4sQ/6exI14zAQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=io/b2CsC/KZ8uTVFakQaMkU/Dwj/JMPeFaHsYX5ootxTkqqhfM0p/jQ0W6kBC132D HM7AGSdnYTnaxh/eoHtqoJrzrgEq/x9QuE9uxEkhAcuYpgsu7uVGzfJEdSrfyp9o4x ekyhfWPSw42IU2YI62h2OvQq/9ouV20sk0S07U9Txbu2/DlgAA/tpPS9jN6xMxDEFI TmqjPCdcO1/LrUBN767CGjZR7PQhgt7efcPOorNXcoAtY4KVBW/Z6XuQ0hf3zjXYrc SwpVAQvvX5Ye/MjwjbAP3QJLYrYCSbDe03ULkbdaE4rs2QJX8UkMHb05kUQy5ju4sz UrketYFwc/m5Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71AFEC47422; Thu, 25 Jan 2024 00:07:29 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Thu, 25 Jan 2024 00:07:32 +0000 Subject: [PATCH BlueZ v3 7/8] bluetoothd: change plugin loading alike obexd Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240125-rm-ext-plugins-v3-7-d141f7870bb6@gmail.com> References: <20240125-rm-ext-plugins-v3-0-d141f7870bb6@gmail.com> In-Reply-To: <20240125-rm-ext-plugins-v3-0-d141f7870bb6@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706141247; l=3470; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=6yElFux7++NnGhXn3yTR7PlLXi4XViEHuKoqMgyFigw=; b=lXobeEKJxrFM52Kbj5OKm+XlDLerbaNjVpH6BHJ+gVI6v9prO3Dq3yf8MN1lpY74DOfrslXio 9dmelYX4Up5DokHJDjLYU6/lUlWsrR7KgtmfxLmtqeRLBWvN5yx4WFB X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov Currently, we print "Loading foobar" for every plugin, before we try the respective init() callback. Instead we handle the latter in a bunch, at the end of the process. Do the init() call early, print "Loaded" once it's actually successful and drop the no-longer "active" tracking. --- src/plugin.c | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index ae9406375..3895792bc 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -32,7 +32,6 @@ struct bluetooth_plugin { #if EXTERNAL_PLUGINS void *handle; #endif - gboolean active; const struct bluetooth_plugin_desc *desc; }; @@ -44,6 +43,22 @@ static int compare_priority(gconstpointer a, gconstpointer b) return plugin2->desc->priority - plugin1->desc->priority; } +static int init_plugin(const struct bluetooth_plugin_desc *desc) +{ + int err; + + err = desc->init(); + if (err < 0) { + if (err == -ENOSYS || err == -ENOTSUP) + warn("System does not support %s plugin", + desc->name); + else + error("Failed to init %s plugin", + desc->name); + } + return err; +} + #if EXTERNAL_PLUGINS static gboolean add_external_plugin(void *handle, const struct bluetooth_plugin_desc *desc) @@ -58,19 +73,22 @@ static gboolean add_external_plugin(void *handle, return FALSE; } - DBG("Loading %s plugin", desc->name); - plugin = g_try_new0(struct bluetooth_plugin, 1); if (plugin == NULL) return FALSE; plugin->handle = handle; - plugin->active = FALSE; plugin->desc = desc; + if (init_plugin(desc) < 0) { + g_free(plugin); + return FALSE; + } + __btd_enable_debug(desc->debug_start, desc->debug_stop); plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); + DBG("Plugin %s loaded", desc->name); return TRUE; } @@ -88,7 +106,13 @@ static void add_plugin(const struct bluetooth_plugin_desc *desc) plugin->desc = desc; + if (init_plugin(desc) < 0) { + g_free(plugin); + return; + } + plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); + DBG("Plugin %s loaded", desc->name); } static gboolean enable_plugin(const char *name, char **cli_enable, @@ -181,7 +205,6 @@ static void external_plugin_init(char **cli_disabled, char **cli_enabled) void plugin_init(const char *enable, const char *disable) { - GSList *list; char **cli_disabled = NULL; char **cli_enabled = NULL; unsigned int i; @@ -208,24 +231,6 @@ void plugin_init(const char *enable, const char *disable) external_plugin_init(cli_enabled, cli_disabled); - for (list = plugins; list; list = list->next) { - struct bluetooth_plugin *plugin = list->data; - int err; - - err = plugin->desc->init(); - if (err < 0) { - if (err == -ENOSYS || err == -ENOTSUP) - warn("System does not support %s plugin", - plugin->desc->name); - else - error("Failed to init %s plugin", - plugin->desc->name); - continue; - } - - plugin->active = TRUE; - } - g_strfreev(cli_enabled); g_strfreev(cli_disabled); } @@ -239,7 +244,7 @@ void plugin_cleanup(void) for (list = plugins; list; list = list->next) { struct bluetooth_plugin *plugin = list->data; - if (plugin->active == TRUE && plugin->desc->exit) + if (plugin->desc->exit) plugin->desc->exit(); #if EXTERNAL_PLUGINS -- 2.43.0