X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=blobdiff_plain;f=config-ui%2Fbrowser-switchboard-config.c;h=685a0b048111a06263939bda9ec2a0b3eeeaeee0;hp=7d644c6ad44f8108b22c9c9ade897212b42712a6;hb=HEAD;hpb=1e3c4733ddcd3c38575a700906f368bb0ead6177 diff --git a/config-ui/browser-switchboard-config.c b/config-ui/browser-switchboard-config.c index 7d644c6..685a0b0 100644 --- a/config-ui/browser-switchboard-config.c +++ b/config-ui/browser-switchboard-config.c @@ -22,13 +22,13 @@ #include -#include #include #include #include #include #include "config.h" +#include "save-config.h" #include "browsers.h" extern struct swb_config_option swb_config_options[]; @@ -36,7 +36,7 @@ extern struct swb_config_option swb_config_options[]; static int get_config_value(char *name) { struct swb_config cfg; struct swb_config_option *optinfo; - ptrdiff_t i; + void *entry; int retval = 1; swb_config_init(&cfg); @@ -48,14 +48,14 @@ static int get_config_value(char *name) { if (strcmp(name, optinfo->name)) continue; - i = optinfo - swb_config_options; + entry = (char *)&cfg + optinfo->offset; switch (optinfo->type) { case SWB_CONFIG_OPT_STRING: - if (*(char **)cfg.entries[i]) - printf("%s\n", *(char **)cfg.entries[i]); + if (*(char **)entry) + printf("%s\n", *(char **)entry); break; case SWB_CONFIG_OPT_INT: - printf("%d\n", *(int *)cfg.entries[i]); + printf("%d\n", *(int *)entry); break; default: break; @@ -103,36 +103,34 @@ static int get_default_browser(void) { } static int set_config_value(char *name, char *value) { - struct swb_config cfg; + struct swb_config orig_cfg, cfg; struct swb_config_option *optinfo; - ptrdiff_t i; + void *entry; int retval = 1; - swb_config_init(&cfg); + swb_config_init(&orig_cfg); - if (!swb_config_load(&cfg)) + if (!swb_config_load(&orig_cfg)) return 1; + cfg = orig_cfg; + for (optinfo = swb_config_options; optinfo->name; ++optinfo) { if (strcmp(name, optinfo->name)) continue; - i = optinfo - swb_config_options; + entry = (char *)&cfg + optinfo->offset; switch (optinfo->type) { case SWB_CONFIG_OPT_STRING: - /* Free any existing string */ - if (cfg.flags & optinfo->set_mask) - free(*(char **)cfg.entries[i]); - if (strlen(value) == 0) { /* If the new value is empty, clear the config setting */ - *(char **)cfg.entries[i] = NULL; + *(char **)entry = NULL; cfg.flags &= ~optinfo->set_mask; } else { /* Make a copy of the string -- it's not safe to free value, which comes from argv */ - if (!(*(char **)cfg.entries[i] = + if (!(*(char **)entry = strdup(value))) exit(1); cfg.flags |= optinfo->set_mask; @@ -144,7 +142,7 @@ static int set_config_value(char *name, char *value) { setting */ cfg.flags &= ~optinfo->set_mask; } else { - *(int *)cfg.entries[i] = atoi(value); + *(int *)entry = atoi(value); cfg.flags |= optinfo->set_mask; } break; @@ -157,12 +155,15 @@ static int set_config_value(char *name, char *value) { if (!swb_config_save(&cfg)) retval = 1; - swb_config_free(&cfg); + /* Reconfigure a running browser-switchboard, if present */ + swb_reconfig(&orig_cfg, &cfg); - /* Try to send SIGHUP to any running browser-switchboard process - This causes it to reread config files if in continuous_mode, or - die so that the config will be reloaded on next start otherwise */ - system("kill -HUP `pidof browser-switchboard` > /dev/null 2>&1"); + swb_config_free(&orig_cfg); + /* XXX can't free all of cfg, it contains pointers to memory we just + freed above + swb_config_free(&cfg); */ + if (optinfo->name && optinfo->type == SWB_CONFIG_OPT_STRING) + free(*(char **)entry); return retval; }