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`.
This commit is contained in:
Thomas Haller 2023-11-06 11:32:46 +01:00
parent 8ccd1f7bfe
commit a5f9f2fbfc
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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