mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 15:22:20 +02:00
src: don't crash on incomplete user-edited config file
If a user created a custom config file and we added new fields in a newer version, `eg25-manager` will crash by assuming all config files are complete and up-to-date. Moreover, creating a custom config, even to change only one option, required copying a complete default config file and then editing the relevant field(s). This could lead to issues when upgrading, as default values of fields unrelated to the user change could be modified and not applied to the user config. This patch addresses both these issues by: * making sure at least one config file exists * requiring only the "default" config file (the one under `/usr/share`) to include all the required fields * trying to use user config for each field, falling back to the default config file if the field isn't present in the user config * exiting with a meaningful error message in case the default config file is missing a required field or section That way, it will be possible to have a minimal user config file containing only the field(s) needing a different value than the default one, falling back to the values in the default config file. Fixes #23
This commit is contained in:
committed by
Arnaud Ferraris
parent
55ed2dc39c
commit
4c6625a38d
32
src/gnss.c
32
src/gnss.c
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "gnss.h"
|
||||
#include "manager.h"
|
||||
#include "at.h"
|
||||
@@ -58,38 +59,34 @@ gboolean gnss_upload_assistance_data(struct EG25Manager *manager)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void gnss_init(struct EG25Manager *manager, toml_table_t *config)
|
||||
void gnss_init(struct EG25Manager *manager, toml_table_t *config[])
|
||||
{
|
||||
toml_datum_t enabled;
|
||||
toml_datum_t url;
|
||||
toml_datum_t file;
|
||||
toml_table_t *gnss_config[EG25_CONFIG_COUNT];
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
for (int i = 0; i < EG25_CONFIG_COUNT; i++)
|
||||
gnss_config[i] = config[i] ? toml_table_in(config[i], "gnss") : NULL;
|
||||
|
||||
if (!gnss_config[EG25_CONFIG_SYS])
|
||||
g_error("Default config file lacks the 'gnss' section!");
|
||||
|
||||
/*
|
||||
* GNSS assistance is an optional feature, you can disable it
|
||||
* if you want in the configuration file.
|
||||
* In case the configuration is missing, we assume GNSS assistance
|
||||
* to be disabled.
|
||||
*/
|
||||
enabled = toml_bool_in(config, "enabled");
|
||||
manager->gnss_assistance_enabled = FALSE;
|
||||
if (enabled.ok)
|
||||
manager->gnss_assistance_enabled = enabled.u.b;
|
||||
config_get_bool(gnss_config, "enabled", &manager->gnss_assistance_enabled);
|
||||
|
||||
if (!manager->gnss_assistance_enabled) {
|
||||
g_message("GNSS assistance is disabled!");
|
||||
return;
|
||||
}
|
||||
|
||||
url = toml_string_in(config, "url");
|
||||
if (url.ok)
|
||||
manager->gnss_assistance_url = url.u.s;
|
||||
else
|
||||
if (!config_get_string(gnss_config, "url", &manager->gnss_assistance_url))
|
||||
g_error("GNSS assistance server URL is missing from config file");
|
||||
file = toml_string_in(config, "file");
|
||||
if (file.ok)
|
||||
manager->gnss_assistance_file = file.u.s;
|
||||
else
|
||||
|
||||
if (!config_get_string(gnss_config, "file", &manager->gnss_assistance_file))
|
||||
g_error("GNSS assistance file name is missing from config file");
|
||||
|
||||
/* Create temporary file to store assistance data */
|
||||
@@ -105,6 +102,8 @@ void gnss_init(struct EG25Manager *manager, toml_table_t *config)
|
||||
|
||||
void gnss_destroy(struct EG25Manager *manager)
|
||||
{
|
||||
g_free(manager->gnss_assistance_url);
|
||||
g_free(manager->gnss_assistance_file);
|
||||
close(manager->gnss_assistance_fd);
|
||||
}
|
||||
|
||||
@@ -512,4 +511,3 @@ void gnss_step(struct EG25Manager *manager)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user