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