Commit b990cee0 authored by Thomas Haller's avatar Thomas Haller

cli: sort active-connection for `nmcli connection show $PROFILE` output

There might be multiple active connections. Output them in a defined order.
parent a1b25a47
......@@ -865,36 +865,42 @@ construct_header_name (const char *base, const char *spec)
return g_strdup_printf ("%s (%s)", base, spec);
}
static int
get_ac_for_connection_cmp (gconstpointer pa, gconstpointer pb, gpointer user_data)
{
NMActiveConnection *ac_a = *((NMActiveConnection *const*) pa);
NMActiveConnection *ac_b = *((NMActiveConnection *const*) pb);
return active_connection_cmp (ac_a, ac_b);
}
static NMActiveConnection *
get_ac_for_connection (const GPtrArray *active_cons, NMConnection *connection, GPtrArray **out_result)
{
const char *con_path, *ac_con_path;
guint i;
NMActiveConnection *best_candidate = NULL;
GPtrArray *result = out_result ? *out_result : NULL;
con_path = nm_connection_get_path (connection);
for (i = 0; i < active_cons->len; i++) {
NMActiveConnection *candidate = g_ptr_array_index (active_cons, i);
NMRemoteConnection *con;
con = nm_active_connection_get_connection (candidate);
if (NM_CONNECTION (con) != connection) {
/* also compare the D-Bus paths. Why? I don't know. */
ac_con_path = con ? nm_connection_get_path (NM_CONNECTION (con)) : NULL;
if (!nm_streq0 (ac_con_path, con_path))
continue;
}
if (NM_CONNECTION (con) != connection)
continue;
if (!out_result)
return candidate;
if (!best_candidate)
best_candidate = candidate;
if (!result)
result = g_ptr_array_new_with_free_func (g_object_unref);
g_ptr_array_add (result, g_object_ref (candidate));
}
if (result) {
g_ptr_array_sort_with_data (result, get_ac_for_connection_cmp, NULL);
best_candidate = result->pdata[0];
}
NM_SET_OUT (out_result, result);
return best_candidate;
}
......
......@@ -84,26 +84,26 @@ proxy.pac-url: --
proxy.pac-script: --
GENERAL.NAME: ethernet
GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL
GENERAL.DEVICES: eth0
GENERAL.STATE: deactivating
GENERAL.DEVICES: eth1
GENERAL.STATE: activated
GENERAL.DEFAULT: no
GENERAL.DEFAULT6: no
GENERAL.SPEC-OBJECT: --
GENERAL.VPN: no
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3
GENERAL.ZONE: --
GENERAL.MASTER-PATH: --
GENERAL.NAME: ethernet
GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL
GENERAL.DEVICES: eth1
GENERAL.STATE: activated
GENERAL.DEVICES: eth0
GENERAL.STATE: deactivating
GENERAL.DEFAULT: no
GENERAL.DEFAULT6: no
GENERAL.SPEC-OBJECT: --
GENERAL.VPN: no
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3
GENERAL.ZONE: --
GENERAL.MASTER-PATH: --
......
......@@ -84,26 +84,26 @@ proxy.pac-url: --
proxy.pac-script: --
GENERAL.NAME: ethernet
GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL
GENERAL.DEVICES: eth0
GENERAL.STATE: deactivating
GENERAL.DEVICES: eth1
GENERAL.STATE: activated
GENERAL.DEFAULT: nie
GENERAL.DEFAULT6: nie
GENERAL.SPEC-OBJECT: --
GENERAL.VPN: nie
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3
GENERAL.ZONE: --
GENERAL.MASTER-PATH: --
GENERAL.NAME: ethernet
GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL
GENERAL.DEVICES: eth1
GENERAL.STATE: activated
GENERAL.DEVICES: eth0
GENERAL.STATE: deactivating
GENERAL.DEFAULT: nie
GENERAL.DEFAULT6: nie
GENERAL.SPEC-OBJECT: --
GENERAL.VPN: nie
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3
GENERAL.ZONE: --
GENERAL.MASTER-PATH: --
......
......@@ -9,6 +9,6 @@ stdout: 0 bytes
stderr: 103 bytes
>>>
**
nmcli:ERROR:clients/cli/connections.c:1062:fill_output_active_connection: assertion failed: (s_con)
nmcli:ERROR:clients/cli/connections.c:1068:fill_output_active_connection: assertion failed: (s_con)
<<<
......@@ -9,6 +9,6 @@ stdout: 0 bytes
stderr: 103 bytes
>>>
**
nmcli:ERROR:clients/cli/connections.c:1062:fill_output_active_connection: assertion failed: (s_con)
nmcli:ERROR:clients/cli/connections.c:1068:fill_output_active_connection: assertion failed: (s_con)
<<<
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment