Handle invalid configuration file format

Print an error when an invalid key/value config is given to termite.

Closes: #486
This commit is contained in:
Jelle van der Waa 2017-06-19 22:22:28 +02:00
parent 18b653954d
commit 5dc2d638a0
1 changed files with 13 additions and 3 deletions

View File

@ -1371,25 +1371,35 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
char **geometry, char **icon) { char **geometry, char **icon) {
const std::string default_path = "/termite/config"; const std::string default_path = "/termite/config";
GKeyFile *config = g_key_file_new(); GKeyFile *config = g_key_file_new();
GError *error = nullptr;
gboolean loaded = FALSE; gboolean loaded = FALSE;
if (info->config_file) { if (info->config_file) {
loaded = g_key_file_load_from_file(config, loaded = g_key_file_load_from_file(config,
info->config_file, info->config_file,
G_KEY_FILE_NONE, nullptr); G_KEY_FILE_NONE, &error);
if (!loaded)
g_printerr("%s parsing failed: %s\n", info->config_file,
error->message);
} }
if (!loaded) { if (!loaded) {
loaded = g_key_file_load_from_file(config, loaded = g_key_file_load_from_file(config,
(g_get_user_config_dir() + default_path).c_str(), (g_get_user_config_dir() + default_path).c_str(),
G_KEY_FILE_NONE, nullptr); G_KEY_FILE_NONE, &error);
if (!loaded)
g_printerr("%s parsing failed: %s\n", (g_get_user_config_dir() + default_path).c_str(),
error->message);
} }
for (const char *const *dir = g_get_system_config_dirs(); for (const char *const *dir = g_get_system_config_dirs();
!loaded && *dir; dir++) { !loaded && *dir; dir++) {
loaded = g_key_file_load_from_file(config, (*dir + default_path).c_str(), loaded = g_key_file_load_from_file(config, (*dir + default_path).c_str(),
G_KEY_FILE_NONE, nullptr); G_KEY_FILE_NONE, &error);
if (!loaded)
g_printerr("%s parsing failed: %s\n", (*dir + default_path).c_str(),
error->message);
} }
if (loaded) { if (loaded) {