gui: Fix config file reloading.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 14 Feb 2015 19:45:29 +0000 (20:45 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 13 Mar 2015 07:58:02 +0000 (08:58 +0100)
Without this, all key-map arguments found in the config file are
appended to the existing ones, duplicating these options in the help
output. Fix this by invalidating the key-map entry prior to the call
to gui_cmdline_parser_config_file().

This bug was present since "day one".

gui.c

diff --git a/gui.c b/gui.c
index c82cd8c32300b27d2bd6c5a8d15bff60e52fb372..1a89681d196bce31b863e390bd60fc62f441a886 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -871,6 +871,23 @@ static void parse_config_file_or_die(bool override)
                }
                goto out;
        }
                }
                goto out;
        }
+       /*
+        * When the gengetopt config file parser is called more than once, any
+        * key map arguments found in the config file are _appended_ to the old
+        * values, even though we turn on ->override. We want the new arguments
+        * to replace the old ones, so we must empty the key_map_arg array
+        * first. Unfortunately, this also clears any key map arguments given
+        * at the command line.
+        */
+       if (override) {
+               int i;
+               for (i = 0; i < conf.key_map_given; i++) {
+                       free(conf.key_map_arg[i]);
+                       conf.key_map_arg[i] = NULL;
+               }
+               conf.key_map_given = 0;
+       }
+
        gui_cmdline_parser_config_file(config_file, &conf, &params);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
        check_key_map_args_or_die();
        gui_cmdline_parser_config_file(config_file, &conf, &params);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
        check_key_map_args_or_die();