{"id":24094,"url":"https://patchwork.libcamera.org/api/patches/24094/?format=json","web_url":"https://patchwork.libcamera.org/patch/24094/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250812143814.120975-1-stefan.klug@ideasonboard.com>","date":"2025-08-12T14:38:04","name":"libcamera: ipa_proxy: Log configuration file path","commit_ref":"452fbd2295dea2f1acb4f7e746aa17a0c7b11a73","pull_url":null,"state":"accepted","archived":false,"hash":"95f69f584d17be08d5d788c3dee6cb078521a0ba","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24094/mbox/","series":[{"id":5369,"url":"https://patchwork.libcamera.org/api/series/5369/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5369","date":"2025-08-12T14:38:04","name":"libcamera: ipa_proxy: Log configuration file path","version":1,"mbox":"https://patchwork.libcamera.org/series/5369/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24094/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24094/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 9712BBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 12 Aug 2025 14:38:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5582E69249;\n\tTue, 12 Aug 2025 16:38:21 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FA286921A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Aug 2025 16:38:19 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:7c24:e2bc:68da:c990])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 5273C3DA;\n\tTue, 12 Aug 2025 16:37:26 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"eQB/PARS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755009446;\n\tbh=lXOibL5+UYk2LGZhzCDKnQrSGRkVKO/MlBTDk+mqsfw=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=eQB/PARSXj6YCtqld6OEjQidPWKylxM16RC8F9cVvBAbHAnw+X5UrRo6jrj3fex8j\n\teiXk/x7zKXH1Cj3UVoBMnZhJwQwkaCo9ho38H8Rzpqhf5WnOCWjMJegwkC76vxcd15\n\t1le/jeVXVedxJ3hK0lWjA8o/WUJUAcXPlVB5FDZU=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH] libcamera: ipa_proxy: Log configuration file path","Date":"Tue, 12 Aug 2025 16:38:04 +0200","Message-ID":"<20250812143814.120975-1-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.48.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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":"It is often helpful to know which tuning file is used. Add a log\nstatement with INFO level for that.\n\nAs the core logic has multiple return paths, adding the log statement is\nnot straight forward. Extract finder logic into a ipaConfigurationFile()\nfunction and call that with the name and optionally the fallbackName\nfrom the configurationFile() function.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n\nHi all,\n\nI posted a similar patch a while ago here:\nhttps://lists.libcamera.org/pipermail/libcamera-devel/2025-January/048324.html\n\nWe didn't merge it back then because it should be central in ipa_proxy.\nAdding it there is a bit ugly because there are a few return paths. I\ntried to use a scope_exit but that doesn't work as the exit function is\ncalled after confPath is moved out to the caller. So I settled for\nrefactoring which imho makes the configurationFile() function also\neasier to read.\n\nBest regards,\nStefan\n\n---\n src/libcamera/ipa_proxy.cpp | 143 ++++++++++++++++++++----------------\n 1 file changed, 79 insertions(+), 64 deletions(-)","diff":"diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp\nindex 9907b9615ec7..b5c13a30f1d4 100644\n--- a/src/libcamera/ipa_proxy.cpp\n+++ b/src/libcamera/ipa_proxy.cpp\n@@ -25,6 +25,78 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPAProxy)\n \n+namespace {\n+\n+std::string ipaConfigurationFile(const std::string &ipaName, const std::string &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 */\n+\tstd::string ipaEnvName = ipaName.substr(0, ipaName.find('/'));\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+\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 */\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+\t}\n+\n+\tstd::string root = utils::libcameraSourcePath();\n+\tif (!root.empty()) {\n+\t\t/*\n+\t\t * When libcamera is used before it is installed, load\n+\t\t * configuration files from the source directory. The\n+\t\t * configuration files are then located in the 'data'\n+\t\t * subdirectory of the corresponding IPA module.\n+\t\t */\n+\t\tstd::string ipaConfDir = root + \"src/ipa/\" + ipaName + \"/data\";\n+\n+\t\tLOG(IPAProxy, Info)\n+\t\t\t<< \"libcamera is not installed. Loading IPA configuration from '\"\n+\t\t\t<< ipaConfDir << \"'\";\n+\n+\t\tstd::string confPath = ipaConfDir + \"/\" + 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+\n+\t} else {\n+\t\t/* Else look in the system locations. */\n+\t\tfor (const auto &dir : utils::split(IPA_CONFIG_DIR, \":\")) {\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}\n+\n+\treturn {};\n+}\n+\n+} /* namespace */\n+\n /**\n  * \\class IPAProxy\n  * \\brief IPA Proxy\n@@ -103,68 +175,10 @@ std::string IPAProxy::configurationFile(const std::string &name,\n \t * has been validated when loading the module.\n \t */\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 */\n-\tstd::string ipaEnvName = ipaName.substr(0, ipaName.find('/'));\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-\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 */\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-\t}\n-\n-\tstd::string root = utils::libcameraSourcePath();\n-\tif (!root.empty()) {\n-\t\t/*\n-\t\t * When libcamera is used before it is installed, load\n-\t\t * configuration files from the source directory. The\n-\t\t * configuration files are then located in the 'data'\n-\t\t * subdirectory of the corresponding IPA module.\n-\t\t */\n-\t\tstd::string ipaConfDir = root + \"src/ipa/\" + ipaName + \"/data\";\n-\n-\t\tLOG(IPAProxy, Info)\n-\t\t\t<< \"libcamera is not installed. Loading IPA configuration from '\"\n-\t\t\t<< ipaConfDir << \"'\";\n-\n-\t\tstd::string confPath = ipaConfDir + \"/\" + 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-\n-\t} else {\n-\t\t/* Else look in the system locations. */\n-\t\tfor (const auto &dir : utils::split(IPA_CONFIG_DIR, \":\")) {\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+\tstd::string confPath = ipaConfigurationFile(ipaName, name);\n+\tif (!confPath.empty()) {\n+\t\tLOG(IPAProxy, Info) << \"Using tuning file \" << confPath;\n+\t\treturn confPath;\n \t}\n \n \tif (fallbackName.empty()) {\n@@ -174,11 +188,12 @@ std::string IPAProxy::configurationFile(const std::string &name,\n \t\treturn std::string();\n \t}\n \n+\tconfPath = ipaConfigurationFile(ipaName, fallbackName);\n \tLOG(IPAProxy, Warning)\n \t\t<< \"Configuration file '\" << name\n \t\t<< \"' not found for IPA module '\" << ipaName\n-\t\t<< \"', falling back to '\" << fallbackName << \"'\";\n-\treturn configurationFile(fallbackName);\n+\t\t<< \"', falling back to '\" << confPath << \"'\";\n+\treturn confPath;\n }\n \n /**\n","prefixes":[]}