[v9,13/13] config: Make configuration directories configurable
diff mbox series

Message ID 20250611142431.33306-14-mzamazal@redhat.com
State New
Headers show
Series
  • Add global configuration file
Related show

Commit Message

Milan Zamazal June 11, 2025, 2:24 p.m. UTC
A newly introduced LIBCAMERA_CONFIG_DIR environment variable specifies a
directory or a list of directories separated by colons where to look for
the libcamera configuration file before trying the standard locations.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 Documentation/runtime_configuration.rst     |  5 +++++
 src/libcamera/base/global_configuration.cpp | 17 +++++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

Comments

Barnabás Pőcze June 13, 2025, 1:05 p.m. UTC | #1
Hi

2025. 06. 11. 16:24 keltezéssel, Milan Zamazal írta:
> A newly introduced LIBCAMERA_CONFIG_DIR environment variable specifies a
> directory or a list of directories separated by colons where to look for
> the libcamera configuration file before trying the standard locations.
> 
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
> ---
>   Documentation/runtime_configuration.rst     |  5 +++++
>   src/libcamera/base/global_configuration.cpp | 17 +++++++++++------
>   2 files changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst
> index 9e2650799..8f9e6fd75 100644
> --- a/Documentation/runtime_configuration.rst
> +++ b/Documentation/runtime_configuration.rst
> @@ -19,6 +19,11 @@ order:
>   - LIBCAMERA_SYSCONF_DIR/configuration.yaml
>   - /etc/libcamera/configuration.yaml
> 
> +If LIBCAMERA_CONFIG_DIR environment variable is non-empty then it
> +specifies additional directories where to look for the configuration
> +file, before looking at the standard locations. It can be a single
> +directory or multiple directories separated by colons.
> +
>   The default name of the configuration file, configuration.yaml, can be
>   overridden in LIBCAMERA_CONFIG_NAME environment variable. The variable
>   can specify just an alternative configuration file name to be looked up
> diff --git a/src/libcamera/base/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp
> index 9c9d1d74e..bcafadda2 100644
> --- a/src/libcamera/base/global_configuration.cpp
> +++ b/src/libcamera/base/global_configuration.cpp
> @@ -75,12 +75,6 @@ bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)
>   	return true;
>   }
> 
> -const std::vector<std::filesystem::path>
> -	globalConfigurationDirectories = {
> -		std::filesystem::path(LIBCAMERA_SYSCONF_DIR),
> -		std::filesystem::path("/etc/libcamera"),
> -	};
> -
>   void GlobalConfiguration::load()
>   {
>   	const char *libcameraConfigName =
> @@ -97,6 +91,17 @@ void GlobalConfiguration::load()
>   	if (configName.empty())
>   		configName = std::filesystem::path("configuration.yaml");
> 
> +	const char *const configDir = utils::secure_getenv("LIBCAMERA_CONFIG_DIR");
> +	std::vector<std::filesystem::path> globalConfigurationDirectories;
> +	if (configDir)
> +		for (auto const &path : utils::split(configDir, ":"))
> +			if (!path.empty())
> +				globalConfigurationDirectories.push_back(path);
> +	globalConfigurationDirectories.push_back(
> +		std::filesystem::path(LIBCAMERA_SYSCONF_DIR));
> +	globalConfigurationDirectories.push_back(
> +		std::filesystem::path("/etc/libcamera"));

I think you can get rid of the explicit `std::filesystem::path(...)`.


Regards,
Barnabás Pőcze


> +
>   	std::filesystem::path userConfigurationDirectory;
>   	char *xdgConfigHome = utils::secure_getenv("XDG_CONFIG_HOME");
>   	if (xdgConfigHome) {
> --
> 2.49.0
>

Patch
diff mbox series

diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst
index 9e2650799..8f9e6fd75 100644
--- a/Documentation/runtime_configuration.rst
+++ b/Documentation/runtime_configuration.rst
@@ -19,6 +19,11 @@  order:
 - LIBCAMERA_SYSCONF_DIR/configuration.yaml
 - /etc/libcamera/configuration.yaml
 
+If LIBCAMERA_CONFIG_DIR environment variable is non-empty then it
+specifies additional directories where to look for the configuration
+file, before looking at the standard locations. It can be a single
+directory or multiple directories separated by colons.
+
 The default name of the configuration file, configuration.yaml, can be
 overridden in LIBCAMERA_CONFIG_NAME environment variable. The variable
 can specify just an alternative configuration file name to be looked up
diff --git a/src/libcamera/base/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp
index 9c9d1d74e..bcafadda2 100644
--- a/src/libcamera/base/global_configuration.cpp
+++ b/src/libcamera/base/global_configuration.cpp
@@ -75,12 +75,6 @@  bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)
 	return true;
 }
 
-const std::vector<std::filesystem::path>
-	globalConfigurationDirectories = {
-		std::filesystem::path(LIBCAMERA_SYSCONF_DIR),
-		std::filesystem::path("/etc/libcamera"),
-	};
-
 void GlobalConfiguration::load()
 {
 	const char *libcameraConfigName =
@@ -97,6 +91,17 @@  void GlobalConfiguration::load()
 	if (configName.empty())
 		configName = std::filesystem::path("configuration.yaml");
 
+	const char *const configDir = utils::secure_getenv("LIBCAMERA_CONFIG_DIR");
+	std::vector<std::filesystem::path> globalConfigurationDirectories;
+	if (configDir)
+		for (auto const &path : utils::split(configDir, ":"))
+			if (!path.empty())
+				globalConfigurationDirectories.push_back(path);
+	globalConfigurationDirectories.push_back(
+		std::filesystem::path(LIBCAMERA_SYSCONF_DIR));
+	globalConfigurationDirectories.push_back(
+		std::filesystem::path("/etc/libcamera"));
+
 	std::filesystem::path userConfigurationDirectory;
 	char *xdgConfigHome = utils::secure_getenv("XDG_CONFIG_HOME");
 	if (xdgConfigHome) {