From: Steven Luo Date: Sun, 21 Feb 2010 03:26:48 +0000 (-0800) Subject: Add a new config setting for logging X-Git-Tag: v3.2~11 X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=commitdiff_plain;h=bdea97be42be2df37d6e0d29bbaa8114f3f727de;ds=sidebyside Add a new config setting for logging Add a new config setting: logging = "stdout" -- log to stdout (default) logging = "syslog" -- log to syslog logging = "none" -- disable logging No configuration UI is exposed, but the UI needs to be taught that this is a legal config setting (so that it doesn't discard it). --- diff --git a/config-ui/browser-switchboard-cp.c b/config-ui/browser-switchboard-cp.c index 13b0b48..c34778b 100644 --- a/config-ui/browser-switchboard-cp.c +++ b/config-ui/browser-switchboard-cp.c @@ -72,6 +72,8 @@ struct browser_entry browsers[] = { { NULL, NULL }, }; +char *logger_name = NULL; + struct config_widgets { #if defined(HILDON) && defined(FREMANTLE) GtkWidget *continuous_mode_selector; @@ -169,20 +171,25 @@ static void load_config(void) { set_continuous_mode(atoi(line.value)); continuous_mode_seen = 1; } + free(line.value); } else if (!strcmp(line.key, "default_browser")) { if (!default_browser_seen) { set_default_browser(line.value); default_browser_seen = 1; } + free(line.value); } else if (!strcmp(line.key, "other_browser_cmd")) { if (!other_browser_cmd_seen) { set_other_browser_cmd(line.value); other_browser_cmd_seen = 1; } + free(line.value); + } else if (!strcmp(line.key, "logging")) { + if (!logger_name) + logger_name = line.value; } } free(line.key); - free(line.value); } parse_config_file_end(); @@ -261,6 +268,15 @@ static void save_config(void) { get_other_browser_cmd()); other_browser_cmd_seen = 1; } + } else if (!strcmp(line.key, + "logging")) { + if (logger_name) { + fprintf(tmpfp, "%s = \"%s\"\n", + line.key, + logger_name); + free(logger_name); + logger_name = NULL; + } } } else { /* Just copy the old line over */ @@ -282,6 +298,9 @@ static void save_config(void) { if (!other_browser_cmd_seen && strlen(get_other_browser_cmd()) > 0) fprintf(tmpfp, "%s = \"%s\"\n", "other_browser_cmd", get_other_browser_cmd()); + if (logger_name) + fprintf(tmpfp, "%s = \"%s\"\n", + "logging", logger_name); /* Replace the old config file with the new one */ fclose(tmpfp); diff --git a/main.c b/main.c index cd7fdb5..7f2f7db 100644 --- a/main.c +++ b/main.c @@ -53,7 +53,7 @@ static void read_config(int signalnum) { FILE *fp; int continuous_mode_seen = 0; struct swb_config_line line; - char *default_browser = NULL; + char *default_browser = NULL, *logger_name = NULL; set_config_defaults(&ctx); @@ -78,6 +78,9 @@ static void read_config(int signalnum) { } else if (!strcmp(line.key, "other_browser_cmd")) { if (!ctx.other_browser_cmd) ctx.other_browser_cmd = line.value; + } else if (!strcmp(line.key, "logging")) { + if (!logger_name) + logger_name = line.value; } else { /* Don't need this line's contents */ free(line.value); @@ -96,7 +99,9 @@ static void read_config(int signalnum) { out: fclose(fp); out_noopen: + log_config(logger_name); update_default_browser(&ctx, default_browser); + free(logger_name); free(default_browser); return; }