Show a patch.

GET /api/1.1/patches/23315/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 23315,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/23315/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23315/",
    "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": "<20250430121449.39910-9-mzamazal@redhat.com>",
    "date": "2025-04-30T12:14:41",
    "name": "[v8,08/15] config: Look up IPA configurables in configuration file",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "53d4f02d62aeec0b9e77e4d44f43a61055639a47",
    "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/23315/mbox/",
    "series": [
        {
            "id": 5156,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5156/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5156",
            "date": "2025-04-30T12:14:33",
            "name": "Add global configuration file",
            "version": 8,
            "mbox": "https://patchwork.libcamera.org/series/5156/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23315/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23315/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 24A5BBE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 30 Apr 2025 12:15:25 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B830B68B37;\n\tWed, 30 Apr 2025 14:15:24 +0200 (CEST)",
            "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 947BF68B27\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 30 Apr 2025 14:15:21 +0200 (CEST)",
            "from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-610-fbV0eImiOzWi7yVNWlBFGg-1;\n\tWed, 30 Apr 2025 08:15:17 -0400",
            "from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.111])\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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 529141801A18; Wed, 30 Apr 2025 12:15:16 +0000 (UTC)",
            "from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.120])\n\tby mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 596F7180047F; Wed, 30 Apr 2025 12:15:14 +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=\"Shy3Czd9\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1746015320;\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=MR6QI2o8el3O9A+3Hd1wZiU8/e1IUDsFxyQF8sv/CEk=;\n\tb=Shy3Czd9OCPQ58zBuCtmq6Xt+T3y6o26MJPv/B9447ZdT8QBBSsfuO7ank/O94iAwgQ8V/\n\tC+vd+hZV0XCbpIWvDuOTub7fIhaoS6AYi64IgdV/6SJXTgZHS2MffQd1VB4Fu5hNMZuYod\n\tuORXCr0+XmB6S8bXHkSFROh/W5DzgPM=",
        "X-MC-Unique": "fbV0eImiOzWi7yVNWlBFGg-1",
        "X-Mimecast-MFC-AGG-ID": "fbV0eImiOzWi7yVNWlBFGg_1746015316",
        "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>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<pobrn@protonmail.com>, Laurent Pinchart\n\t<laurent.pinchart@ideasonboard.com>",
        "Subject": "[PATCH v8 08/15] config: Look up IPA configurables in configuration\n\tfile",
        "Date": "Wed, 30 Apr 2025 14:14:41 +0200",
        "Message-ID": "<20250430121449.39910-9-mzamazal@redhat.com>",
        "In-Reply-To": "<20250430121449.39910-1-mzamazal@redhat.com>",
        "References": "<20250430121449.39910-1-mzamazal@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.111",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-MFC-PROC-ID": "1TlGyEKaMqd6m6ahZP7awFwVj4mj_4NXL62CrEDoyRQ_1746015316",
        "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": "This patch adds configuration options for environment variables used in\nthe IPA proxy.  Two utility functions configuration retrieval functions\nare added, to retrieve lists of values.\n\nThe 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      proxy_paths:\n      - proxy path 1\n      - proxy path 2\n      - ...\n      force_isolation: BOOL\n      ipas:\n        IPA_NAME:\n          tuning_file: TUNING FILE\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                   | 65 ++++++++++---------\n 4 files changed, 109 insertions(+), 43 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 7b4b2946..7b082a3b 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@@ -283,7 +291,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 9907b961..10c6ff8e 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@@ -105,37 +106,37 @@ std::string IPAProxy::configurationFile(const std::string &name,\n \tconst std::string ipaName = ipam_->info().name;\n \n \t/*\n-\t * Start with any user override through the module-specific environment\n-\t * variable. Use the name of the IPA module up to the first '/' to\n-\t * construct the variable name.\n+\t * Start with any user override through the module-specific configuration or\n+\t * environment variable. Use the name of the IPA module up to the first '/'\n+\t * to construct the configuration and variable names.\n \t */\n-\tstd::string ipaEnvName = ipaName.substr(0, ipaName.find('/'));\n+\tstd::string ipaBaseName = ipaName.substr(0, ipaName.find('/'));\n+\tstd::string ipaConfigName = \"ipa.ipas.\" + ipaBaseName + \".tuning_file\";\n+\tstd::string ipaEnvName = ipaBaseName;\n \tstd::transform(ipaEnvName.begin(), ipaEnvName.end(), ipaEnvName.begin(),\n \t\t       [](unsigned char c) { return std::toupper(c); });\n \tipaEnvName = \"LIBCAMERA_\" + ipaEnvName + \"_TUNING_FILE\";\n \n-\tchar const *configFromEnv = utils::secure_getenv(ipaEnvName.c_str());\n-\tif (configFromEnv && *configFromEnv != '\\0')\n-\t\treturn { configFromEnv };\n+\tauto config = GlobalConfiguration::envOption(ipaEnvName.c_str(), ipaConfigName);\n+\tif (config)\n+\t\treturn { config.value() };\n \n \tstruct stat statbuf;\n \tint ret;\n \n \t/*\n-\t * Check the directory pointed to by the IPA config path environment\n-\t * variable next.\n+\t * Check the directory pointed to by the IPA config path next.\n \t */\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-\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+\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+\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@@ -199,18 +200,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": [
        "v8",
        "08/15"
    ]
}