[{"id":35798,"web_url":"https://patchwork.libcamera.org/comment/35798/","msgid":"<175766968274.2127323.10509001125951944071@neptunite.rasen.tech>","date":"2025-09-12T09:34:42","subject":"Re: [PATCH v17 11/12] config: Make configuration file locations\n\tconfigurable","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Milan,\n\nThanks for the patch.\n\nQuoting Milan Zamazal (2025-09-11 18:29:41)\n> To support easy switching of configurations, let's introduce\n> LIBCAMERA_CONFIG_DIR and LIBCAMERA_CONFIG_NAME environment variables.\n> \n> LIBCAMERA_CONFIG_DIR environment variable specifies a directory or a\n> list of directories separated by colons where to look for the libcamera\n> configuration file before trying the standard locations.  This override\n> can be useful in a meson devenv.\n> \n> LIBCAMERA_CONFIG_NAME\n> - specifies the path of the configuration file to load if it is an\n>   absolute path (useful to quickly try some configuration); or\n> - prevents any configuration file from loading if it is defined and\n>   empty (useful to disable all configuration files); or\n> - specifies the path of the configuration file to load, relative to\n>   the configuration directories (useful to quickly select between\n>   different configurations).\n> \n> If a configuration file specified by those environment variables doesn't\n> exist, no custom configuration is loaded.\n\nI assume you mean that in this scenario no configuration file is loaded at all,\nso s/custom// is clearer.\n\nWith that, looks good to me.\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  Documentation/runtime_configuration.rst | 13 +++++++\n>  src/libcamera/global_configuration.cpp  | 50 +++++++++++++++++--------\n>  2 files changed, 47 insertions(+), 16 deletions(-)\n> \n> diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst\n> index 702139544..5307f3645 100644\n> --- a/Documentation/runtime_configuration.rst\n> +++ b/Documentation/runtime_configuration.rst\n> @@ -19,6 +19,19 @@ order:\n>  - LIBCAMERA_SYSCONF_DIR/configuration.yaml\n>  - LIBCAMERA_DATA_DIR/libcamera/configuration.yaml\n>  \n> +If LIBCAMERA_CONFIG_DIR environment variable is non-empty then it\n> +specifies additional directories where to look for the configuration\n> +file, before looking at the standard locations. It can be a single\n> +directory or multiple directories separated by colons.\n> +\n> +The default name of the configuration file, configuration.yaml, can be\n> +overridden in LIBCAMERA_CONFIG_NAME environment variable. The variable\n> +can specify just an alternative configuration file name to be looked up\n> +in the locations above, or a whole absolute path. If an absolute path is\n> +specified then it is the only location that is used; if the given file\n> +doesn't exist then no configuration file is read. If the variable is\n> +defined but empty, no configuration is loaded.\n> +\n>  The first configuration file found wins, configuration files in other\n>  locations are ignored.\n>  \n> diff --git a/src/libcamera/global_configuration.cpp b/src/libcamera/global_configuration.cpp\n> index 592edcf30..8c2670e03 100644\n> --- a/src/libcamera/global_configuration.cpp\n> +++ b/src/libcamera/global_configuration.cpp\n> @@ -23,13 +23,6 @@\n>  \n>  namespace libcamera {\n>  \n> -namespace {\n> -const std::vector<std::filesystem::path> globalConfigurationFiles = {\n> -       std::filesystem::path(LIBCAMERA_SYSCONF_DIR) / \"configuration.yaml\",\n> -       std::filesystem::path(LIBCAMERA_DATA_DIR) / \"configuration.yaml\",\n> -};\n> -}\n> -\n>  LOG_DEFINE_CATEGORY(Configuration)\n>  \n>  /**\n> @@ -80,6 +73,33 @@ bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)\n>  \n>  void GlobalConfiguration::load()\n>  {\n> +       const char *libcameraConfigName =\n> +               utils::secure_getenv(\"LIBCAMERA_CONFIG_NAME\");\n> +       if (libcameraConfigName && libcameraConfigName[0] == '\\0')\n> +               return;\n> +       if (!libcameraConfigName)\n> +               libcameraConfigName = \"\";\n> +\n> +       std::filesystem::path configName(libcameraConfigName);\n> +\n> +       if (configName.is_absolute()) {\n> +               loadFile(configName);\n> +               return;\n> +       }\n> +\n> +       if (configName.empty())\n> +               configName = std::filesystem::path(\"configuration.yaml\");\n> +\n> +       std::vector<std::filesystem::path> configurationDirectories;\n> +\n> +       const char *configDir = utils::secure_getenv(\"LIBCAMERA_CONFIG_DIR\");\n> +       if (configDir) {\n> +               for (auto const &path : utils::split(configDir, \":\")) {\n> +                       if (!path.empty())\n> +                               configurationDirectories.push_back(path);\n> +               }\n> +       }\n> +\n>         std::filesystem::path userConfigurationDirectory;\n>         const char *xdgConfigHome = utils::secure_getenv(\"XDG_CONFIG_HOME\");\n>         if (xdgConfigHome) {\n> @@ -90,18 +110,16 @@ void GlobalConfiguration::load()\n>                         userConfigurationDirectory =\n>                                 std::filesystem::path(home) / \".config\";\n>         }\n> +       if (!userConfigurationDirectory.empty())\n> +               configurationDirectories.push_back(\n> +                       userConfigurationDirectory / \"libcamera\");\n>  \n> -       if (!userConfigurationDirectory.empty()) {\n> -               std::filesystem::path user_configuration_file =\n> -                       userConfigurationDirectory / \"libcamera\" / \"configuration.yaml\";\n> -               if (loadFile(user_configuration_file))\n> -                       return;\n> -       }\n> +       configurationDirectories.push_back(LIBCAMERA_SYSCONF_DIR);\n> +       configurationDirectories.push_back(LIBCAMERA_DATA_DIR);\n>  \n> -       for (const auto &path : globalConfigurationFiles) {\n> -               if (loadFile(path))\n> +       for (const auto &path : configurationDirectories)\n> +               if (loadFile(path / configName))\n>                         return;\n> -       }\n>  }\n>  \n>  /**\n> -- \n> 2.51.0\n>","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 5F749BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 12 Sep 2025 09:34:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6309269367;\n\tFri, 12 Sep 2025 11:34:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 03165613A3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Sep 2025 11:34:48 +0200 (CEST)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:5c83:71e0:e0c7:1670])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id D0267446;\n\tFri, 12 Sep 2025 11:33:32 +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=\"CrlpQCZM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1757669613;\n\tbh=12Je5/w+1ldLY41IcON1G6Cw6sc0JG8lX1JFMP72oMs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=CrlpQCZMCHSRgZRYNY5DTImnRRxZwUjeq++uCfWPtdiue1nmc/NavXa70t1oRgMhM\n\taRp6FKhLlyeaFfhEkt4l6r+joKVUpcGmDdYrkZwL80RlHj4kyFa2dfRzkwzW+9Znbh\n\tb3sfyhtaBMZs+Y4Mq4ivdqD8tw2uxMYDSvrqVpxg=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250911092945.16517-12-mzamazal@redhat.com>","References":"<20250911092945.16517-1-mzamazal@redhat.com>\n\t<20250911092945.16517-12-mzamazal@redhat.com>","Subject":"Re: [PATCH v17 11/12] config: Make configuration file locations\n\tconfigurable","From":"Paul Elder <paul.elder@ideasonboard.com>","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<barnabas.pocze@ideasonboard.com>, Laurent Pinchart\n\t<laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Fri, 12 Sep 2025 18:34:42 +0900","Message-ID":"<175766968274.2127323.10509001125951944071@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]