[v11,12/12] config: Make configuration directories configurable
diff mbox series

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

Commit Message

Milan Zamazal June 24, 2025, 8:36 a.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/global_configuration.cpp  | 14 +++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

Comments

Barnabás Pőcze June 27, 2025, 2 p.m. UTC | #1
Hi

2025. 06. 24. 10:36 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/global_configuration.cpp  | 14 +++++++++-----
>   2 files changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst
> index 5648db7d7..3146cdba6 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/global_configuration.cpp b/src/libcamera/global_configuration.cpp
> index 2c3b6cf97..2b990cdea 100644
> --- a/src/libcamera/global_configuration.cpp
> +++ b/src/libcamera/global_configuration.cpp
> @@ -67,11 +67,6 @@ bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)
>   
>   bool GlobalConfiguration::load()
>   {
> -	const std::vector<std::filesystem::path> globalConfigurationDirectories = {
> -		std::filesystem::path(LIBCAMERA_SYSCONF_DIR),
> -		std::filesystem::path("/etc/libcamera"),
> -	};
> -
>   	const char *libcameraConfigName =
>   		utils::secure_getenv("LIBCAMERA_CONFIG_NAME");
>   	if (!libcameraConfigName)
> @@ -86,6 +81,15 @@ bool GlobalConfiguration::load()
>   	if (configName.empty())
>   		configName = std::filesystem::path("configuration.yaml");
>   
> +	const char *const configDir = utils::secure_getenv("LIBCAMERA_CONFIG_DIR");

I think you can drop the top-level `const`, other variables here don't have it.


> +	std::vector<std::filesystem::path> globalConfigurationDirectories;
> +	if (configDir)
> +		for (auto const &path : utils::split(configDir, ":"))
> +			if (!path.empty())
> +				globalConfigurationDirectories.push_back(path);

I would probably add `{}` around everything except the innermost `if`.


Regards,
Barnabás Pőcze


> +	globalConfigurationDirectories.push_back(LIBCAMERA_SYSCONF_DIR);
> +	globalConfigurationDirectories.push_back("/etc/libcamera");
> +
>   	std::filesystem::path userConfigurationDirectory;
>   	const char *xdgConfigHome = utils::secure_getenv("XDG_CONFIG_HOME");
>   	if (xdgConfigHome) {
Milan Zamazal June 27, 2025, 9:13 p.m. UTC | #2
Hi Barnabás,

Barnabás Pőcze <barnabas.pocze@ideasonboard.com> writes:

> Hi
>
> 2025. 06. 24. 10:36 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/global_configuration.cpp  | 14 +++++++++-----
>>   2 files changed, 14 insertions(+), 5 deletions(-)
>> diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst
>> index 5648db7d7..3146cdba6 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/global_configuration.cpp b/src/libcamera/global_configuration.cpp
>> index 2c3b6cf97..2b990cdea 100644
>> --- a/src/libcamera/global_configuration.cpp
>> +++ b/src/libcamera/global_configuration.cpp
>> @@ -67,11 +67,6 @@ bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)
>>     bool GlobalConfiguration::load()
>>   {
>> -	const std::vector<std::filesystem::path> globalConfigurationDirectories = {
>> -		std::filesystem::path(LIBCAMERA_SYSCONF_DIR),
>> -		std::filesystem::path("/etc/libcamera"),
>> -	};
>> -
>>   	const char *libcameraConfigName =
>>   		utils::secure_getenv("LIBCAMERA_CONFIG_NAME");
>>   	if (!libcameraConfigName)
>> @@ -86,6 +81,15 @@ bool GlobalConfiguration::load()
>>   	if (configName.empty())
>>   		configName = std::filesystem::path("configuration.yaml");
>>   +	const char *const configDir = utils::secure_getenv("LIBCAMERA_CONFIG_DIR");
>
> I think you can drop the top-level `const`, other variables here don't have it.

OK.

>> +	std::vector<std::filesystem::path> globalConfigurationDirectories;
>> +	if (configDir)
>> +		for (auto const &path : utils::split(configDir, ":"))
>> +			if (!path.empty())
>> +				globalConfigurationDirectories.push_back(path);
>
> I would probably add `{}` around everything except the innermost `if`.

OK.

> Regards,
> Barnabás Pőcze
>
>
>> +	globalConfigurationDirectories.push_back(LIBCAMERA_SYSCONF_DIR);
>> +	globalConfigurationDirectories.push_back("/etc/libcamera");
>> +
>>   	std::filesystem::path userConfigurationDirectory;
>>   	const char *xdgConfigHome = utils::secure_getenv("XDG_CONFIG_HOME");
>>   	if (xdgConfigHome) {

Patch
diff mbox series

diff --git a/Documentation/runtime_configuration.rst b/Documentation/runtime_configuration.rst
index 5648db7d7..3146cdba6 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/global_configuration.cpp b/src/libcamera/global_configuration.cpp
index 2c3b6cf97..2b990cdea 100644
--- a/src/libcamera/global_configuration.cpp
+++ b/src/libcamera/global_configuration.cpp
@@ -67,11 +67,6 @@  bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)
 
 bool GlobalConfiguration::load()
 {
-	const std::vector<std::filesystem::path> globalConfigurationDirectories = {
-		std::filesystem::path(LIBCAMERA_SYSCONF_DIR),
-		std::filesystem::path("/etc/libcamera"),
-	};
-
 	const char *libcameraConfigName =
 		utils::secure_getenv("LIBCAMERA_CONFIG_NAME");
 	if (!libcameraConfigName)
@@ -86,6 +81,15 @@  bool 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(LIBCAMERA_SYSCONF_DIR);
+	globalConfigurationDirectories.push_back("/etc/libcamera");
+
 	std::filesystem::path userConfigurationDirectory;
 	const char *xdgConfigHome = utils::secure_getenv("XDG_CONFIG_HOME");
 	if (xdgConfigHome) {