summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-11-01 15:50:31 +0100
committerThomas Haller <thaller@redhat.com>2016-11-09 12:07:35 +0100
commiteb307bbbb6f2c6427b55502f5ed4881154d46569 (patch)
tree80ee95c86e9e878a5f08a497389e2f55adbca00e
parent82ccec22ca00dce8f094bc417f9f3cb386b475d3 (diff)
downloadNetworkManager-eb307bbbb6f2c6427b55502f5ed4881154d46569.tar.gz
ifcfg-rh: let reader preserve the last line even without newline at end of file
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c2
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk2
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c18
3 files changed, 21 insertions, 1 deletions
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index d92eaecee1..413ff309b5 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -630,6 +630,8 @@ svOpenFileInternal (const char *name, gboolean create, GError **error)
/* we'd use g_strsplit() here, but we want a list, not an array */
for (p = arena; (q = strchr (p, '\n')) != NULL; p = q + 1)
s->lineList = g_list_append (s->lineList, g_strndup (p, q - p));
+ if (p[0])
+ s->lineList = g_list_append (s->lineList, g_strdup (p));
g_free (arena);
/* closefd is set if we opened the file read-only, so go ahead and
diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk
index 2119ba8e6b..a78051aad4 100644
--- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk
+++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk
@@ -16,4 +16,4 @@ CIPHER_GROUP="TKIP CCMP WEP40 WEP104"
KEY_MGMT=WPA-PSK
WPA_ALLOW_WPA=yes
WPA_ALLOW_WPA2=yes
-
+LAST_ENTRY=no-newline \ No newline at end of file
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 ac50ed9b64..4cd7c4d270 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -2401,6 +2401,22 @@ test_read_wifi_leap_secret_flags (gconstpointer test_data)
}
static void
+test_ifcfg_no_trailing_newline (void)
+{
+ gs_free_error GError *error = NULL;
+ shvarFile *sv;
+ gs_free char *value = NULL;
+
+ sv = svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk", &error);
+ nmtst_assert_success (sv, error);
+
+ value = svGetValueString (sv, "LAST_ENTRY");
+ g_assert_cmpstr (value, ==, "no-newline");
+
+ svCloseFile (sv);
+}
+
+static void
test_read_wifi_wpa_psk (void)
{
NMConnection *connection;
@@ -9446,6 +9462,8 @@ int main (int argc, char **argv)
g_test_add_data_func (TPATH "wwan/write-gsm", GUINT_TO_POINTER (TRUE), test_write_mobile_broadband);
g_test_add_data_func (TPATH "wwan/write-cdma", GUINT_TO_POINTER (FALSE), test_write_mobile_broadband);
+ g_test_add_func (TPATH "no-trailing-newline", test_ifcfg_no_trailing_newline);
+
g_test_add_func (TPATH "utils/name", test_utils_name);
g_test_add_func (TPATH "utils/path", test_utils_path);
g_test_add_func (TPATH "utils/ignore", test_utils_ignore);