Blame SOURCES/0009-rh1260584-nmcli-wol-fixes.patch

ab7d06
From 65f6bb0b7b5baf9b92906ca5b0259f901bb57bb7 Mon Sep 17 00:00:00 2001
ab7d06
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com>
ab7d06
Date: Mon, 14 Sep 2015 14:06:39 +0200
ab7d06
Subject: [PATCH 1/2] nmcli: allow "none" value for ethernet.wake-on-lan
ab7d06
 property (rh #1260584)
ab7d06
MIME-Version: 1.0
ab7d06
Content-Type: text/plain; charset=UTF-8
ab7d06
Content-Transfer-Encoding: 8bit
ab7d06
ab7d06
Aliases "disable" and "disabled" are accepted too.
ab7d06
ab7d06
nmcli> set 802-3-ethernet.wake-on-lan none
ab7d06
ab7d06
It was possible to remove flags by setting a string containing just white
ab7d06
spaces, but it was user unfriendly and non-intuitive.
ab7d06
ab7d06
https://bugzilla.redhat.com/show_bug.cgi?id=1260584
ab7d06
ab7d06
(cherry picked from commit f88ce92b2574b9f4388868d7f92a48ea71e93bb8)
ab7d06
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
ab7d06
---
ab7d06
 clients/cli/settings.c | 16 +++++++++++-----
ab7d06
 1 file changed, 11 insertions(+), 5 deletions(-)
ab7d06
ab7d06
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
ab7d06
index 952681d..5ca80b4 100644
ab7d06
--- a/clients/cli/settings.c
ab7d06
+++ b/clients/cli/settings.c
ab7d06
@@ -1541,11 +1541,17 @@ nmc_property_wired_set_wake_on_lan (NMSetting *setting, const char *prop,
ab7d06
 	                              (int *) &wol, &err_token);
ab7d06
 
ab7d06
 	if (!ret) {
ab7d06
-		g_set_error (error, 1, 0, _("invalid option '%s', use  a combination of %s or 'default'"),
ab7d06
-		             err_token,
ab7d06
-		             nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (),
ab7d06
-		                                   NM_SETTING_WIRED_WAKE_ON_LAN_ALL));
ab7d06
-		return FALSE;
ab7d06
+		if (   g_ascii_strcasecmp (err_token, "none") == 0
ab7d06
+		    || g_ascii_strcasecmp (err_token, "disable") == 0
ab7d06
+		    || g_ascii_strcasecmp (err_token, "disabled") == 0)
ab7d06
+			wol = NM_SETTING_WIRED_WAKE_ON_LAN_NONE;
ab7d06
+		else {
ab7d06
+			g_set_error (error, 1, 0, _("invalid option '%s', use  a combination of %s or 'default' or 'none'"),
ab7d06
+			             err_token,
ab7d06
+			             nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (),
ab7d06
+			                                   NM_SETTING_WIRED_WAKE_ON_LAN_ALL));
ab7d06
+			return FALSE;
ab7d06
+		}
ab7d06
 	}
ab7d06
 
ab7d06
 	if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) &&
ab7d06
-- 
ab7d06
2.1.0
ab7d06
ab7d06
ab7d06
From c0c1cb1dc8bff47385fd00043196ce323a6cb770 Mon Sep 17 00:00:00 2001
ab7d06
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com>
ab7d06
Date: Mon, 14 Sep 2015 14:23:50 +0200
ab7d06
Subject: [PATCH 2/2] nmcli: wake-on-lan property set/get fixes
ab7d06
MIME-Version: 1.0
ab7d06
Content-Type: text/plain; charset=UTF-8
ab7d06
Content-Transfer-Encoding: 8bit
ab7d06
ab7d06
- accept a numeric value (decimal or hex (0x prefix))
ab7d06
- display a numeric value of the property in addition to the strings
ab7d06
- add/accept spaces between string names
ab7d06
ab7d06
to behave similar to other flags' properties.
ab7d06
ab7d06
(cherry picked from commit 4485b4ec2fa22d588a75640573b06270031f5c77)
ab7d06
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
ab7d06
---
ab7d06
 clients/cli/settings.c          | 42 ++++++++++++++++++++++++++---------------
ab7d06
 libnm-core/nm-utils.c           |  4 ++--
ab7d06
 libnm-core/tests/test-general.c |  6 ++++--
ab7d06
 3 files changed, 33 insertions(+), 19 deletions(-)
ab7d06
ab7d06
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
ab7d06
index 5ca80b4..8d2d70b 100644
ab7d06
--- a/clients/cli/settings.c
ab7d06
+++ b/clients/cli/settings.c
ab7d06
@@ -1524,9 +1524,16 @@ nmc_property_wired_get_wake_on_lan (NMSetting *setting, NmcPropertyGetType get_t
ab7d06
 {
ab7d06
 	NMSettingWired *s_wired = NM_SETTING_WIRED (setting);
ab7d06
 	NMSettingWiredWakeOnLan wol;
ab7d06
+	char *tmp, *str;
ab7d06
 
ab7d06
 	wol = nm_setting_wired_get_wake_on_lan (s_wired);
ab7d06
-	return nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (), wol);
ab7d06
+	tmp = nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (), wol);
ab7d06
+	if (get_type == NMC_PROPERTY_GET_PARSABLE)
ab7d06
+		str = g_strdup_printf ("%s", tmp && *tmp ? tmp : "none");
ab7d06
+	else
ab7d06
+		str = g_strdup_printf ("%d (%s)", wol, tmp && *tmp ? tmp : "none");
ab7d06
+	g_free (tmp);
ab7d06
+	return str;
ab7d06
 }
ab7d06
 
ab7d06
 static gboolean
ab7d06
@@ -1536,21 +1543,26 @@ nmc_property_wired_set_wake_on_lan (NMSetting *setting, const char *prop,
ab7d06
 	NMSettingWiredWakeOnLan wol;
ab7d06
 	gs_free char *err_token = NULL;
ab7d06
 	gboolean ret;
ab7d06
+	long int t;
ab7d06
 
ab7d06
-	ret = nm_utils_enum_from_str (nm_setting_wired_wake_on_lan_get_type (), val,
ab7d06
-	                              (int *) &wol, &err_token);
ab7d06
-
ab7d06
-	if (!ret) {
ab7d06
-		if (   g_ascii_strcasecmp (err_token, "none") == 0
ab7d06
-		    || g_ascii_strcasecmp (err_token, "disable") == 0
ab7d06
-		    || g_ascii_strcasecmp (err_token, "disabled") == 0)
ab7d06
-			wol = NM_SETTING_WIRED_WAKE_ON_LAN_NONE;
ab7d06
-		else {
ab7d06
-			g_set_error (error, 1, 0, _("invalid option '%s', use  a combination of %s or 'default' or 'none'"),
ab7d06
-			             err_token,
ab7d06
-			             nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (),
ab7d06
-			                                   NM_SETTING_WIRED_WAKE_ON_LAN_ALL));
ab7d06
-			return FALSE;
ab7d06
+	if (nmc_string_to_int_base (val, 0, TRUE, 0, NM_SETTING_WIRED_WAKE_ON_LAN_ALL, &t))
ab7d06
+		wol = (NMSettingWiredWakeOnLan) t;
ab7d06
+	else {
ab7d06
+		ret = nm_utils_enum_from_str (nm_setting_wired_wake_on_lan_get_type (), val,
ab7d06
+		                              (int *) &wol, &err_token);
ab7d06
+
ab7d06
+		if (!ret) {
ab7d06
+			if (   g_ascii_strcasecmp (err_token, "none") == 0
ab7d06
+			    || g_ascii_strcasecmp (err_token, "disable") == 0
ab7d06
+			    || g_ascii_strcasecmp (err_token, "disabled") == 0)
ab7d06
+				wol = NM_SETTING_WIRED_WAKE_ON_LAN_NONE;
ab7d06
+			else {
ab7d06
+				g_set_error (error, 1, 0, _("invalid option '%s', use  a combination of [%s] or 'default' or 'none'"),
ab7d06
+				             err_token,
ab7d06
+				             nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (),
ab7d06
+				                                   NM_SETTING_WIRED_WAKE_ON_LAN_ALL));
ab7d06
+				return FALSE;
ab7d06
+			}
ab7d06
 		}
ab7d06
 	}
ab7d06
 
ab7d06
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
ab7d06
index 66dd1c8..987cf73 100644
ab7d06
--- a/libnm-core/nm-utils.c
ab7d06
+++ b/libnm-core/nm-utils.c
ab7d06
@@ -3676,7 +3676,7 @@ char *nm_utils_enum_to_str (GType type, int value)
ab7d06
 				break;
ab7d06
 
ab7d06
 			if (!first)
ab7d06
-				g_string_append_c (str, ',');
ab7d06
+				g_string_append (str, ", ");
ab7d06
 			g_string_append (str, flags_value->value_nick);
ab7d06
 
ab7d06
 			value &= ~flags_value->value;
ab7d06
@@ -3733,7 +3733,7 @@ gboolean nm_utils_enum_from_str (GType type, const char *str,
ab7d06
 		gs_strfreev char **strv = NULL;
ab7d06
 		int i;
ab7d06
 
ab7d06
-		strv = g_strsplit (stripped, ",", 0);
ab7d06
+		strv = g_strsplit_set (stripped, " \t,", 0);
ab7d06
 		for (i = 0; strv[i]; i++) {
ab7d06
 			if (!strv[i][0])
ab7d06
 				continue;
ab7d06
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
ab7d06
index a73604b..42b55c1 100644
ab7d06
--- a/libnm-core/tests/test-general.c
ab7d06
+++ b/libnm-core/tests/test-general.c
ab7d06
@@ -4582,12 +4582,12 @@ static void test_nm_utils_enum (void)
ab7d06
 	test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_BAZ, "baz");
ab7d06
 	test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_FOO |
ab7d06
 	                                          NM_TEST_GENERAL_META_FLAGS_BAR |
ab7d06
-	                                          NM_TEST_GENERAL_META_FLAGS_BAZ, "foo,bar,baz");
ab7d06
+	                                          NM_TEST_GENERAL_META_FLAGS_BAZ, "foo, bar, baz");
ab7d06
 
ab7d06
 	test_nm_utils_enum_to_str_do (color_flags, NM_TEST_GENERAL_COLOR_FLAGS_RED, "red");
ab7d06
 	test_nm_utils_enum_to_str_do (color_flags, NM_TEST_GENERAL_COLOR_FLAGS_WHITE, "");
ab7d06
 	test_nm_utils_enum_to_str_do (color_flags, NM_TEST_GENERAL_COLOR_FLAGS_RED |
ab7d06
-	                                           NM_TEST_GENERAL_COLOR_FLAGS_GREEN, "red,green");
ab7d06
+	                                           NM_TEST_GENERAL_COLOR_FLAGS_GREEN, "red, green");
ab7d06
 
ab7d06
 	test_nm_utils_enum_from_str_do (bool_enum, "", FALSE, 0, NULL);
ab7d06
 	test_nm_utils_enum_from_str_do (bool_enum, " ", FALSE, 0, NULL);
ab7d06
@@ -4601,6 +4601,8 @@ static void test_nm_utils_enum (void)
ab7d06
 	test_nm_utils_enum_from_str_do (meta_flags, "foo", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO, NULL);
ab7d06
 	test_nm_utils_enum_from_str_do (meta_flags, "foo,baz", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO |
ab7d06
 	                                                             NM_TEST_GENERAL_META_FLAGS_BAZ, NULL);
ab7d06
+	test_nm_utils_enum_from_str_do (meta_flags, "foo, baz", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO |
ab7d06
+	                                                              NM_TEST_GENERAL_META_FLAGS_BAZ, NULL);
ab7d06
 	test_nm_utils_enum_from_str_do (meta_flags, "foo,,bar", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO |
ab7d06
 	                                                              NM_TEST_GENERAL_META_FLAGS_BAR, NULL);
ab7d06
 	test_nm_utils_enum_from_str_do (meta_flags, "foo,baz,quux,bar", FALSE, 0, "quux");
ab7d06
-- 
ab7d06
2.1.0
ab7d06