cli: simplify find_device_for_connection()
This commit is contained in:
@@ -1077,22 +1077,10 @@ find_device_for_connection (NmCli *nmc,
|
|||||||
/* VPN connections */
|
/* VPN connections */
|
||||||
NMActiveConnection *active = NULL;
|
NMActiveConnection *active = NULL;
|
||||||
if (iface) {
|
if (iface) {
|
||||||
const GPtrArray *connections = nm_client_get_active_connections (nmc->client);
|
*device = nm_client_get_device_by_iface (nmc->client, iface);
|
||||||
for (i = 0; connections && (i < connections->len) && !active; i++) {
|
if (*device)
|
||||||
NMActiveConnection *candidate = g_ptr_array_index (connections, i);
|
active = nm_device_get_active_connection (*device);
|
||||||
const GPtrArray *devices = nm_active_connection_get_devices (candidate);
|
|
||||||
if (!devices || !devices->len)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (j = 0; devices && (j < devices->len); j++) {
|
|
||||||
NMDevice *dev = g_ptr_array_index (devices, j);
|
|
||||||
if (!strcmp (iface, nm_device_get_iface (dev))) {
|
|
||||||
active = candidate;
|
|
||||||
*device = dev;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!active) {
|
if (!active) {
|
||||||
g_set_error (error, 0, 0, _("no active connection on device '%s'"), iface);
|
g_set_error (error, 0, 0, _("no active connection on device '%s'"), iface);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Reference in New Issue
Block a user