summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-08-23 16:19:42 +0200
committerThomas Haller <thaller@redhat.com>2016-08-26 11:41:13 +0200
commit50d7ac4af3f6908a09a857d4127e196b2df37c27 (patch)
tree83958af21b5c1c0b0e8b3f062735d2782d0faca7
parentcf7b8866ced5ec67e76b8dde530e0350104194d4 (diff)
downloadNetworkManager-50d7ac4af3f6908a09a857d4127e196b2df37c27.tar.gz
ifcfg-rh: make out_unhandled argument non-optional
Depending on the connection we are about to read, we would assert that the user provided a @out_unhandled argument. That means, the user must always provide a valid @out_unhandled pointer, because he cannot know beforehand how the reading of the ifcfg file goes.
-rw-r--r--src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c4
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c9
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c10
3 files changed, 11 insertions, 12 deletions
diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c
index 82f2059854..184e95b2aa 100644
--- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c
+++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c
@@ -395,7 +395,9 @@ commit_changes (NMSettingsConnection *connection,
*/
filename = nm_settings_connection_get_filename (connection);
if (filename) {
- reread = connection_from_file (filename, NULL, NULL, NULL);
+ gs_free char *unhandled = NULL;
+
+ reread = connection_from_file (filename, &unhandled, NULL, NULL);
if (reread) {
same = nm_connection_compare (NM_CONNECTION (connection),
reread,
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index af5d291026..e3d8ee1bb8 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -4848,7 +4848,7 @@ create_unhandled_connection (const char *filename, shvarFile *ifcfg,
NMSetting *s_con;
char *value;
- g_assert (out_spec != NULL);
+ nm_assert (out_spec && !*out_spec);
connection = nm_simple_connection_new ();
@@ -4963,8 +4963,7 @@ connection_from_file_full (const char *filename,
const char *ifcfg_name = NULL;
g_return_val_if_fail (filename != NULL, NULL);
- if (out_unhandled)
- g_return_val_if_fail (*out_unhandled == NULL, NULL);
+ g_return_val_if_fail (out_unhandled && !*out_unhandled, NULL);
/* Non-NULL only for unit tests; normally use /etc/sysconfig/network */
if (!network_file)
@@ -4982,8 +4981,6 @@ connection_from_file_full (const char *filename,
return NULL;
if (!svGetValueBoolean (parsed, "NM_CONTROLLED", TRUE)) {
- g_assert (out_unhandled != NULL);
-
connection = create_unhandled_connection (filename, parsed, "unmanaged", out_unhandled);
if (!connection)
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
@@ -5136,8 +5133,6 @@ connection_from_file_full (const char *filename,
else if (!strcasecmp (type, TYPE_BRIDGE))
connection = bridge_connection_from_ifcfg (filename, parsed, error);
else {
- g_assert (out_unhandled != NULL);
-
connection = create_unhandled_connection (filename, parsed, "unrecognized", out_unhandled);
if (!connection)
PARSE_WARNING ("connection type was unrecognized but device was not uniquely identified; device may be managed");
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index b73f2f5f25..3a67a831db 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -67,11 +67,14 @@ _connection_from_file (const char *filename,
{
NMConnection *connection;
GError *error = NULL;
+ char *unhandled_fallback = NULL;
g_assert (!out_unhandled || !*out_unhandled);
- connection = connection_from_file_test (filename, network_file, test_type, out_unhandled, &error);
+ connection = connection_from_file_test (filename, network_file, test_type,
+ out_unhandled ?: &unhandled_fallback, &error);
g_assert_no_error (error);
+ g_assert (!unhandled_fallback);
if (out_unhandled && *out_unhandled)
nmtst_assert_connection_verifies (connection);
@@ -89,13 +92,12 @@ _connection_from_file_fail (const char *filename,
NMConnection *connection;
GError *local = NULL;
char *unhandled = NULL;
- char **p_unhandled = (nmtst_get_rand_int () % 2) ? &unhandled : NULL;
- connection = connection_from_file_test (filename, network_file, test_type, p_unhandled, &local);
+ connection = connection_from_file_test (filename, network_file, test_type, &unhandled, &local);
g_assert (!connection);
g_assert (local);
- g_assert (!p_unhandled || !*p_unhandled);
+ g_assert (!unhandled);
g_propagate_error (error, local);
}