From a5f9f2fbfceb39b63aa3f652062bc130d46a2fed Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Nov 2023 11:32:46 +0100 Subject: [PATCH] cli: sort external connections later in `nmcli connection|device` EXTERNAL connections are special. Sort them later. This affects output of `nmcli connection` and `nmcli device`. --- src/nmcli/connections.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index b1db014069..3b97da76a4 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -300,21 +300,27 @@ active_connection_get_state_ord(NMActiveConnection *active) }; NMActiveConnectionState state; int i; + gboolean is_external; /* returns an integer related to @active's state, that can be used for sorting * active connections based on their activation state. */ if (!active) - return -2; + return -10; - state = nm_active_connection_get_state(active); + state = nm_active_connection_get_state(active); + is_external = NM_FLAGS_HAS(nm_active_connection_get_state_flags(active), + NM_ACTIVATION_STATE_FLAG_EXTERNAL); for (i = 0; i < (int) G_N_ELEMENTS(ordered_states); i++) { - if (state == ordered_states[i]) + if (state == ordered_states[i]) { + if (!is_external) + i += G_N_ELEMENTS(ordered_states); return i; + } } - return -1; + return is_external ? -2 : -1; } int