summaryrefslogtreecommitdiff
path: root/src/nm-config.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-02-09 16:36:53 +0100
committerThomas Haller <thaller@redhat.com>2015-02-24 10:35:24 +0100
commitc6778ad1b76a995deee966af959ab8bf325524d2 (patch)
treec61819cb32f6a7ca9a4a53a46fc42e1d72ef4c94 /src/nm-config.c
parent3bcc5e4bd0bd88b15ab8f84515f0fca52db62823 (diff)
downloadNetworkManager-c6778ad1b76a995deee966af959ab8bf325524d2.tar.gz
core: unify parsing of device specs using nm_match_spec_split()
There are three configuration options that contain device specs: 'main.ignore-carrier', 'main.no-auto-default', and 'keyfile.unmanaged-devices'. Unify the parsing of them by splitting the device spec with nm_match_spec_split(). This changes behavior for parsing of these properties. Also get rid of logging warnings when parsing 'keyfile.unmanaged-devices'.
Diffstat (limited to 'src/nm-config.c')
-rw-r--r--src/nm-config.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/nm-config.c b/src/nm-config.c
index 6b9887ad1e..594d05f2e3 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -32,6 +32,7 @@
#include "NetworkManagerUtils.h"
#include "gsystem-local-alloc.h"
#include "nm-enum-types.h"
+#include "nm-core-internal.h"
#include <gio/gio.h>
#include <glib/gi18n.h>
@@ -76,7 +77,7 @@ typedef struct {
char *debug;
- char **ignore_carrier;
+ GSList *ignore_carrier;
gboolean configure_and_quit;
} NMConfigPrivate;
@@ -237,21 +238,10 @@ nm_config_get_configure_and_quit (NMConfig *config)
gboolean
nm_config_get_ignore_carrier (NMConfig *config, NMDevice *device)
{
- NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
- GSList *specs = NULL;
- int i;
- gboolean match;
-
- if (!priv->ignore_carrier)
- return FALSE;
-
- for (i = 0; priv->ignore_carrier[i]; i++)
- specs = g_slist_prepend (specs, priv->ignore_carrier[i]);
-
- match = nm_device_spec_match_list (device, specs);
+ g_return_val_if_fail (NM_IS_CONFIG (config), FALSE);
+ g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
- g_slist_free (specs);
- return match;
+ return nm_device_spec_match_list (device, NM_CONFIG_GET_PRIVATE (config)->ignore_carrier);
}
/************************************************************************/
@@ -689,6 +679,15 @@ read_entire_config (const NMConfigCmdLineOptions *cli,
return keyfile;
}
+GSList *
+nm_config_get_device_match_spec (const GKeyFile *keyfile, const char *group, const char *key)
+{
+ gs_free char *value = NULL;
+
+ value = g_key_file_get_string ((GKeyFile *) keyfile, group, key, NULL);
+ return nm_match_spec_split (value);
+}
+
/************************************************************************/
void
@@ -813,7 +812,8 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
char *config_main_file = NULL;
char *config_description = NULL;
char **no_auto_default;
- char **no_auto_default_orig;
+ GSList *no_auto_default_orig_list;
+ GPtrArray *no_auto_default_orig;
if (priv->config_dir) {
/* Object is already initialized. */
@@ -859,17 +859,22 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
priv->debug = g_key_file_get_value (keyfile, "main", "debug", NULL);
- priv->ignore_carrier = g_key_file_get_string_list (keyfile, "main", "ignore-carrier", NULL, NULL);
+ priv->ignore_carrier = nm_config_get_device_match_spec (keyfile, "main", "ignore-carrier");
priv->configure_and_quit = _get_bool_value (keyfile, "main", "configure-and-quit", FALSE);
- no_auto_default_orig = g_key_file_get_string_list (keyfile, "main", "no-auto-default", NULL, NULL);
- no_auto_default = no_auto_default_merge_from_file (priv->no_auto_default_file, (const char *const *) no_auto_default_orig);
+ no_auto_default_orig_list = nm_config_get_device_match_spec (keyfile, "main", "no-auto-default");
+
+ no_auto_default_orig = _nm_utils_copy_slist_to_array (no_auto_default_orig_list, NULL, NULL);
+ g_ptr_array_add (no_auto_default_orig, NULL);
+ no_auto_default = no_auto_default_merge_from_file (priv->no_auto_default_file, (const char *const *) no_auto_default_orig->pdata);
+ g_ptr_array_unref (no_auto_default_orig);
+
+ g_slist_free_full (no_auto_default_orig_list, g_free);
priv->config_data_orig = nm_config_data_new (config_main_file, config_description, (const char *const*) no_auto_default, keyfile);
g_strfreev (no_auto_default);
- g_strfreev (no_auto_default_orig);
priv->config_data = g_object_ref (priv->config_data_orig);
@@ -910,7 +915,7 @@ finalize (GObject *gobject)
g_free (priv->log_level);
g_free (priv->log_domains);
g_free (priv->debug);
- g_strfreev (priv->ignore_carrier);
+ g_slist_free_full (priv->ignore_carrier, g_free);
_nm_config_cmd_line_options_clear (&priv->cli);