Hi,

On Tue, 2012-07-17 at 12:00 -0700, Grant Erickson wrote:
> This patch adds support for specifying a main configuration file
> different from the default value of /etc/connman/main.conf. This
> is valuable during debug to specify alternate debug-only
> configurations.
> ---
>   v1: Initial submission.
>   v2: Incorporated feedback from Marcel about not propagating the
>       fully-qualified default configuration file path on the compiler
>       command line.
> 
>  src/main.c |   25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/src/main.c b/src/main.c
> index 5c206e7..214b736 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -42,6 +42,8 @@
>  #define DEFAULT_INPUT_REQUEST_TIMEOUT 120 * 1000
>  #define DEFAULT_BROWSER_LAUNCH_TIMEOUT 300 * 1000
>  
> +#define CONFIGMAINFILE CONFIGDIR "/main.conf"
> +
>  static char *default_auto_connect[] = {
>       "wifi",
>       "ethernet",
> @@ -324,6 +326,7 @@ static void disconnect_callback(DBusConnection *conn, 
> void *user_data)
>  
>  static gchar *option_debug = NULL;
>  static gchar *option_device = NULL;
> +static gchar *option_file = NULL;
>  static gchar *option_plugin = NULL;
>  static gchar *option_nodevice = NULL;
>  static gchar *option_noplugin = NULL;
> @@ -333,6 +336,18 @@ static gboolean option_dnsproxy = TRUE;
>  static gboolean option_compat = FALSE;
>  static gboolean option_version = FALSE;
>  
> +static int conf_init(const char *file)
> +{
> +     GKeyFile *config;
> +
> +     config = load_config(file);
> +     parse_config(config);
> +     if (config != NULL)
> +             g_key_file_free(config);
> +
> +     return 0;
> +}
> +
>  static gboolean parse_debug(const char *key, const char *value,
>                                       gpointer user_data, GError **error)
>  {
> @@ -350,6 +365,9 @@ static GOptionEntry options[] = {
>                               "Specify debug options to enable", "DEBUG" },
>       { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
>                       "Specify networking device or interface", "DEV" },
> +     { "file", 'f', 0, G_OPTION_ARG_STRING, &option_file,
> +                             "Load the specified configuration file "
> +                             "instead of " CONFIGMAINFILE, "FILE" },
>       { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
>                       "Specify networking interface to ignore", "DEV" },
>       { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
> @@ -430,7 +448,6 @@ int main(int argc, char *argv[])
>       GError *error = NULL;
>       DBusConnection *conn;
>       DBusError err;
> -     GKeyFile *config;
>       guint signal;
>  
>  #ifdef NEED_THREADS
> @@ -507,10 +524,7 @@ int main(int argc, char *argv[])
>  
>       __connman_dbus_init(conn);
>  
> -     config = load_config(CONFIGDIR "/main.conf");
> -     parse_config(config);
> -     if (config != NULL)
> -             g_key_file_free(config);
> +     conf_init(option_file ? option_file : CONFIGMAINFILE);

I'd like to have if (option_file == NULL)... before this line and not
use ? : here. And as a nitpick I'd rename it config_init() and add it
close to load/parse_config() so it's easier to find.

>  
>       __connman_storage_migrate();
>       __connman_technology_init();
> @@ -551,6 +565,7 @@ int main(int argc, char *argv[])
>       __connman_rfkill_init();
>  
>       g_free(option_device);
> +     g_free(option_file);
>       g_free(option_plugin);
>       g_free(option_nodevice);
>       g_free(option_noplugin);

Cheers,

        Patrik

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to