From ddf1942bfb640ddcfbcd663f21b90fd39eb2ac29 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 May 2021 14:18:31 +0200 Subject: [PATCH] libnm: avoid g_warning() in nm_vpn_service_plugin_read_vpn_details() g_warning() and printing to stdout/stderr are not suitable actions for a library. If there is something important, find a way to report the condition to the caller. If it's not important, stay quiet. --- src/libnm-client-impl/nm-vpn-service-plugin.c | 14 ++++---------- src/libnm-client-impl/tests/test-libnm.c | 3 +-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/libnm-client-impl/nm-vpn-service-plugin.c b/src/libnm-client-impl/nm-vpn-service-plugin.c index 5c7bc45b6d..7ed0c5fabe 100644 --- a/src/libnm-client-impl/nm-vpn-service-plugin.c +++ b/src/libnm-client-impl/nm-vpn-service-plugin.c @@ -807,29 +807,23 @@ nm_vpn_service_plugin_read_vpn_details(int fd, GHashTable **out_data, GHashTable /* finish marker */ break; } else if (NM_STR_HAS_PREFIX(line->str, DATA_KEY_TAG)) { - if (nm_clear_g_string(&key)) - g_warning("a value expected"); + nm_clear_g_string(&key); key = g_string_new(line->str + strlen(DATA_KEY_TAG)); str = key; hash = data; } else if (NM_STR_HAS_PREFIX(line->str, DATA_VAL_TAG)) { - if (val || !key || hash != data) { - g_warning("%s not preceded by %s", DATA_VAL_TAG, DATA_KEY_TAG); + if (val || !key || hash != data) break; - } val = g_string_new(line->str + strlen(DATA_VAL_TAG)); str = val; } else if (NM_STR_HAS_PREFIX(line->str, SECRET_KEY_TAG)) { - if (nm_clear_g_string(&key)) - g_warning("a value expected"); + nm_clear_g_string(&key); key = g_string_new(line->str + strlen(SECRET_KEY_TAG)); str = key; hash = secrets; } else if (NM_STR_HAS_PREFIX(line->str, SECRET_VAL_TAG)) { - if (val || !key || hash != secrets) { - g_warning("%s not preceded by %s", SECRET_VAL_TAG, SECRET_KEY_TAG); + if (val || !key || hash != secrets) break; - } val = g_string_new(line->str + strlen(SECRET_VAL_TAG)); str = val; } diff --git a/src/libnm-client-impl/tests/test-libnm.c b/src/libnm-client-impl/tests/test-libnm.c index 003b030432..d09feb5ce3 100644 --- a/src/libnm-client-impl/tests/test-libnm.c +++ b/src/libnm-client-impl/tests/test-libnm.c @@ -2462,8 +2462,7 @@ test_nm_vpn_service_plugin_read_vpn_details(void) "DONE\n" "", READ_VPN_DETAIL_DATA({"some-key", "string\ncontinued after a line break"}, ), - READ_VPN_DETAIL_DATA({"key names\ncan have\ncontinuations too", "value"}, ), - NMTST_EXPECT_LIBNM_WARNING("DATA_VAL= not preceded by DATA_KEY=")); + READ_VPN_DETAIL_DATA({"key names\ncan have\ncontinuations too", "value"}, ), ); _do_read_vpn_details( ""