Patch Detail
Show a patch.
GET /api/1.1/patches/22245/?format=api
{ "id": 22245, "url": "https://patchwork.libcamera.org/api/1.1/patches/22245/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22245/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20241206171148.1189292-9-mzamazal@redhat.com>", "date": "2024-12-06T17:11:39", "name": "[v6,08/16] config: Look up IPA configurables in configuration file", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4ec951bebe7843c3486c12d3cfcf4ff22930b52f", "submitter": { "id": 177, "url": "https://patchwork.libcamera.org/api/1.1/people/177/?format=api", "name": "Milan Zamazal", "email": "mzamazal@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22245/mbox/", "series": [ { "id": 4861, "url": "https://patchwork.libcamera.org/api/1.1/series/4861/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4861", "date": "2024-12-06T17:11:31", "name": "Add global configuration file", "version": 6, "mbox": "https://patchwork.libcamera.org/series/4861/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22245/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22245/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 22C53BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 6 Dec 2024 17:12:36 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D375667E36;\n\tFri, 6 Dec 2024 18:12:35 +0100 (CET)", "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 65AF267E2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 6 Dec 2024 18:12:33 +0100 (CET)", "from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-630-CjVfnyKKPSWJwpMzHihFpQ-1;\n\tFri, 06 Dec 2024 12:12:27 -0500", "from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 012421954AE2; Fri, 6 Dec 2024 17:12:26 +0000 (UTC)", "from nuthatch.redhat.com (unknown [10.45.224.27])\n\tby mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 7F585300019E; Fri, 6 Dec 2024 17:12:23 +0000 (UTC)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"Q5ckdKuA\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1733505152;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=C+uOJoL9MPLuoNXCwucTE/uRvPF32C657uZ9VDm1Sts=;\n\tb=Q5ckdKuA1A+bzubodGoElXiYOX3BY8+pc92bunMXQypWFZYZ2hgEar9nvygblmGZs91YgE\n\tWQWh1L/H7s8SJieaBdIrqP/Mq2dSKX1iSoBBxVVDNL/2PeDi2aDYIpacvf7AXvrZpA5QHP\n\tVeYIVVDv2zWt1XhkiBpS7tQ4QjohFQU=", "X-MC-Unique": "CjVfnyKKPSWJwpMzHihFpQ-1", "X-Mimecast-MFC-AGG-ID": "CjVfnyKKPSWJwpMzHihFpQ", "From": "Milan Zamazal <mzamazal@redhat.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Milan Zamazal <mzamazal@redhat.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, Naushir Patuck\n\t<naush@raspberrypi.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<pobrn@protonmail.com>, Laurent Pinchart\n\t<laurent.pinchart@ideasonboard.com>", "Subject": "[PATCH v6 08/16] config: Look up IPA configurables in configuration\n\tfile", "Date": "Fri, 6 Dec 2024 18:11:39 +0100", "Message-ID": "<20241206171148.1189292-9-mzamazal@redhat.com>", "In-Reply-To": "<20241206171148.1189292-1-mzamazal@redhat.com>", "References": "<20241206171148.1189292-1-mzamazal@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.4", "X-Mimecast-Spam-Score": "0", "X-Mimecast-MFC-PROC-ID": "gFhFNDPvfWb-FzFhTDumew1bHKAkQ4Ou_zDeie7NQNE_1733505146", "X-Mimecast-Originator": "redhat.com", "Content-Transfer-Encoding": "8bit", "content-type": "text/plain; charset=\"US-ASCII\"; x-default=true", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The configuration snippet:\n\n configuration:\n ipa:\n config_paths:\n - config path 1\n - config path 2\n - ...\n module_paths:\n - module path 1\n - module path 2\n - ...\n force_isolation: BOOL\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n .../libcamera/internal/global_configuration.h | 4 ++\n src/libcamera/base/global_configuration.cpp | 51 +++++++++++++++++++\n src/libcamera/ipa_manager.cpp | 32 ++++++++----\n src/libcamera/ipa_proxy.cpp | 47 ++++++++---------\n 4 files changed, 100 insertions(+), 34 deletions(-)", "diff": "diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h\nindex a6e21a2d..ffa6454c 100644\n--- a/include/libcamera/internal/global_configuration.h\n+++ b/include/libcamera/internal/global_configuration.h\n@@ -48,8 +48,12 @@ std::optional<T> option(const std::string &confPath)\n \treturn c->get<T>();\n }\n \n+std::vector<std::string> listOption(const std::string &confPath);\n std::optional<std::string> envOption(const char *const envVariable,\n \t\t\t\t const std::string &confPath);\n+std::vector<std::string> envListOption(\n+\tconst char *const envVariable,\n+\tconst std::string &confPath);\n \n } /* namespace GlobalConfiguration */\n \ndiff --git a/src/libcamera/base/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp\nindex 3dc31c48..e69951b4 100644\n--- a/src/libcamera/base/global_configuration.cpp\n+++ b/src/libcamera/base/global_configuration.cpp\n@@ -9,11 +9,14 @@\n \n #include <filesystem>\n #include <memory>\n+#include <optional>\n #include <string>\n #include <sys/types.h>\n+#include <vector>\n \n #include <libcamera/base/file.h>\n #include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n \n #include \"libcamera/internal/yaml_parser.h\"\n \n@@ -152,6 +155,24 @@ void initialize()\n * in the configuration file and matches type \\a T, no value otherwise\n */\n \n+/**\n+ * \\brief Return values of the configuration option identified by \\a confPath\n+ * \\tparam T The type of the retrieved configuration value\n+ * \\param[in] confPath Sequence of the YAML section names (excluding\n+ * `configuration') leading to the requested list option, separated by dots\n+ * \\return A vector of strings (empty one if the option is not found)\n+ */\n+std::vector<std::string> listOption(const std::string &confPath)\n+{\n+\tconst YamlObject *c = &configuration();\n+\tfor (auto part : utils::split(confPath, \".\")) {\n+\t\tc = &(*c)[part];\n+\t\tif (!*c)\n+\t\t\treturn {};\n+\t}\n+\treturn c->getList<std::string>().value_or(std::vector<std::string>());\n+}\n+\n /**\n * \\brief Return value of the configuration option from a file or environment\n * \\param[in] envVariable Environment variable to get the value from\n@@ -179,6 +200,36 @@ std::optional<std::string> envOption(\n \treturn option<std::string>(confPath);\n }\n \n+/**\n+ * \\brief Return values of the configuration option from a file or environment\n+ * \\param[in] envVariable Environment variable to get the value from\n+ * \\param[in] confPath The same as in GlobalConfiguration::option\n+ *\n+ * This helper looks first at the given environment variable and if it is\n+ * defined (even if it is empty) then it splits its value by semicolons and\n+ * returns the resulting list of strings. Otherwise it looks for \\a confPath the\n+ * same way as in GlobalConfiguration::option, value of which must be a list of\n+ * strings.\n+ *\n+ * \\note Support for using environment variables to configure libcamera behavior\n+ * is provided here mostly for backward compatibility reasons. Introducing new\n+ * configuration environment variables is discouraged.\n+ *\n+ * \\return A vector of strings retrieved from the given environment option or\n+ * configuration file (an empty vector is returned if nothing is found)\n+ */\n+std::vector<std::string> envListOption(\n+\tconst char *const envVariable,\n+\tconst std::string &confPath)\n+{\n+\tconst char *envValue = utils::secure_getenv(envVariable);\n+\tif (envValue) {\n+\t\tauto items = utils::split(envValue, \":\");\n+\t\treturn std::vector<std::string>(items.begin(), items.end());\n+\t}\n+\treturn listOption(confPath);\n+}\n+\n /**\n * \\brief Return configuration version\n *\ndiff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\nindex 33ae74e8..21753eb6 100644\n--- a/src/libcamera/ipa_manager.cpp\n+++ b/src/libcamera/ipa_manager.cpp\n@@ -9,6 +9,7 @@\n \n #include <algorithm>\n #include <dirent.h>\n+#include <numeric>\n #include <string.h>\n #include <sys/types.h>\n \n@@ -114,18 +115,25 @@ IPAManager::IPAManager()\n \tunsigned int ipaCount = 0;\n \n \t/* User-specified paths take precedence. */\n-\tconst char *modulePaths = utils::secure_getenv(\"LIBCAMERA_IPA_MODULE_PATH\");\n-\tif (modulePaths) {\n-\t\tfor (const auto &dir : utils::split(modulePaths, \":\")) {\n-\t\t\tif (dir.empty())\n-\t\t\t\tcontinue;\n+\tconst auto modulePaths =\n+\t\tGlobalConfiguration::envListOption(\n+\t\t\t\"LIBCAMERA_IPA_MODULE_PATH\", \"ipa.module_paths\");\n+\tfor (const auto &dir : modulePaths) {\n+\t\tif (dir.empty())\n+\t\t\tcontinue;\n \n-\t\t\tipaCount += addDir(dir.c_str());\n-\t\t}\n+\t\tipaCount += addDir(dir.c_str());\n+\t}\n \n-\t\tif (!ipaCount)\n-\t\t\tLOG(IPAManager, Warning)\n-\t\t\t\t<< \"No IPA found in '\" << modulePaths << \"'\";\n+\tif (!ipaCount) {\n+\t\tstd::string paths;\n+\t\tif (!modulePaths.empty()) {\n+\t\t\tpaths = std::accumulate(std::next(modulePaths.begin()),\n+\t\t\t\t\t\tmodulePaths.end(),\n+\t\t\t\t\t\tmodulePaths[0],\n+\t\t\t\t\t\t[](std::string s1, std::string s2) { return s1 + \":\" + s2; });\n+\t\t}\n+\t\tLOG(IPAManager, Warning) << \"No IPA found in '\" << paths << \"'\";\n \t}\n \n \t/*\n@@ -289,7 +297,9 @@ bool IPAManager::isSignatureValid([[maybe_unused]] IPAModule *ipa) const\n {\n #if HAVE_IPA_PUBKEY\n \tchar *force = utils::secure_getenv(\"LIBCAMERA_IPA_FORCE_ISOLATION\");\n-\tif (force && force[0] != '\\0') {\n+\tif ((force && force[0] != '\\0') ||\n+\t (!force && GlobalConfiguration::option<bool>(\"ipa.force_isolation\")\n+\t\t\t .value_or(false))) {\n \t\tLOG(IPAManager, Debug)\n \t\t\t<< \"Isolation of IPA module \" << ipa->path()\n \t\t\t<< \" forced through environment variable\";\ndiff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp\nindex 85004737..c3630de0 100644\n--- a/src/libcamera/ipa_proxy.cpp\n+++ b/src/libcamera/ipa_proxy.cpp\n@@ -14,6 +14,7 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n \n+#include \"libcamera/internal/global_configuration.h\"\n #include \"libcamera/internal/ipa_module.h\"\n \n /**\n@@ -107,18 +108,18 @@ std::string IPAProxy::configurationFile(const std::string &name,\n \t */\n \tstd::string ipaName = ipam_->info().name;\n \n-\t/* Check the environment variable first. */\n-\tconst char *confPaths = utils::secure_getenv(\"LIBCAMERA_IPA_CONFIG_PATH\");\n-\tif (confPaths) {\n-\t\tfor (const auto &dir : utils::split(confPaths, \":\")) {\n-\t\t\tif (dir.empty())\n-\t\t\t\tcontinue;\n+\t/* Check the configuration first. */\n+\tauto confPaths =\n+\t\tGlobalConfiguration::envListOption(\n+\t\t\t\"LIBCAMERA_IPA_CONFIG_PATH\", \"ipa.config_paths\");\n+\tfor (const auto &dir : confPaths) {\n+\t\tif (dir.empty())\n+\t\t\tcontinue;\n \n-\t\t\tstd::string confPath = dir + \"/\" + ipaName + \"/\" + name;\n-\t\t\tret = stat(confPath.c_str(), &statbuf);\n-\t\t\tif (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)\n-\t\t\t\treturn confPath;\n-\t\t}\n+\t\tstd::string confPath = dir + \"/\" + ipaName + \"/\" + name;\n+\t\tret = stat(confPath.c_str(), &statbuf);\n+\t\tif (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)\n+\t\t\treturn confPath;\n \t}\n \n \tstd::string root = utils::libcameraSourcePath();\n@@ -182,18 +183,18 @@ std::string IPAProxy::resolvePath(const std::string &file) const\n {\n \tstd::string proxyFile = \"/\" + file;\n \n-\t/* Check env variable first. */\n-\tconst char *execPaths = utils::secure_getenv(\"LIBCAMERA_IPA_PROXY_PATH\");\n-\tif (execPaths) {\n-\t\tfor (const auto &dir : utils::split(execPaths, \":\")) {\n-\t\t\tif (dir.empty())\n-\t\t\t\tcontinue;\n-\n-\t\t\tstd::string proxyPath = dir;\n-\t\t\tproxyPath += proxyFile;\n-\t\t\tif (!access(proxyPath.c_str(), X_OK))\n-\t\t\t\treturn proxyPath;\n-\t\t}\n+\t/* Check the configuration first. */\n+\tconst auto execPaths =\n+\t\tGlobalConfiguration::envListOption(\n+\t\t\t\"LIBCAMERA_IPA_PROXY_PATH\", \"ipa.proxy_paths\");\n+\tfor (const auto &dir : execPaths) {\n+\t\tif (dir.empty())\n+\t\t\tcontinue;\n+\n+\t\tstd::string proxyPath = dir;\n+\t\tproxyPath += proxyFile;\n+\t\tif (!access(proxyPath.c_str(), X_OK))\n+\t\t\treturn proxyPath;\n \t}\n \n \t/*\n", "prefixes": [ "v6", "08/16" ] }