From 5cf9395b94f68c701101207a1eb964eb565be55d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 3 Oct 2022 13:46:02 +0200 Subject: [PATCH 1/2] nmcli: fix return code on "nmcli device connect" error Before: $ nmcli device connect veth0; echo $? Error: Connection activation failed: (5) IP configuration could not be reserved (no available address, timeout, etc.). 0 After $ nmcli device connect veth0; echo $? Error: Connection activation failed: (5) IP configuration could not be reserved (no available address, timeout, etc.). 4 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/902 --- src/nmcli/devices.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index dbba6bb61c..7b70fa1645 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -2132,9 +2132,11 @@ connected_state_cb(AddAndActivateInfo *info) _("Hint: \"nmcli dev wifi show-password\" shows the Wi-Fi name and password.\n")); } else if (state <= NM_DEVICE_STATE_DISCONNECTED || state >= NM_DEVICE_STATE_DEACTIVATING) { reason = nm_device_get_state_reason(info->device); - g_print(_("Error: Connection activation failed: (%d) %s.\n"), - reason, - gettext(nmc_device_reason_to_string(reason))); + g_string_printf(info->nmc->return_text, + _("Error: Connection activation failed: (%d) %s."), + reason, + gettext(nmc_device_reason_to_string(reason))); + info->nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; } else { return; } From 1a77108dcb68b156682ad776156b4e12f3c37bb7 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 3 Oct 2022 13:51:49 +0200 Subject: [PATCH 2/2] nmcli: don't show state-reason for "nmcli device connect" errors It's confusing to show a state-reason number different from nmcli return values. --- src/nmcli/devices.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index 7b70fa1645..b449383034 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -2133,8 +2133,7 @@ connected_state_cb(AddAndActivateInfo *info) } else if (state <= NM_DEVICE_STATE_DISCONNECTED || state >= NM_DEVICE_STATE_DEACTIVATING) { reason = nm_device_get_state_reason(info->device); g_string_printf(info->nmc->return_text, - _("Error: Connection activation failed: (%d) %s."), - reason, + _("Error: Connection activation failed: %s."), gettext(nmc_device_reason_to_string(reason))); info->nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; } else {