diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml index 950085c8b..c23b596c4 100644 --- a/introspection/nm-device.xml +++ b/introspection/nm-device.xml @@ -60,7 +60,7 @@ - Manually disconnect a device + Disconnects a device and prevents the device from automatically activating further connections without user intervention. diff --git a/src/nm-device-interface.c b/src/nm-device-interface.c index 60db27f2c..c8475df4c 100644 --- a/src/nm-device-interface.c +++ b/src/nm-device-interface.c @@ -53,6 +53,8 @@ nm_device_interface_error_get_type (void) ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_CONNECTION_ACTIVATING, "ConnectionActivating"), /* Connection is invalid for this device. */ ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_CONNECTION_INVALID, "ConnectionInvalid"), + /* Operation could not be performed because the device is not active. */ + ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_NOT_ACTIVE, "NotActive"), { 0, 0, 0 } }; etype = g_enum_register_static ("NMDeviceInterfaceError", values); @@ -277,12 +279,28 @@ gboolean nm_device_interface_disconnect (NMDeviceInterface *device, GError **error) { - g_return_val_if_fail (device, FALSE); + gboolean success = FALSE; - return NM_DEVICE_INTERFACE_GET_INTERFACE (device)->disconnect (device, error); + g_return_val_if_fail (NM_IS_DEVICE_INTERFACE (device), FALSE); + + switch (nm_device_interface_get_state (device)) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_UNMANAGED: + case NM_DEVICE_STATE_UNAVAILABLE: + case NM_DEVICE_STATE_DISCONNECTED: + g_set_error_literal (error, + NM_DEVICE_INTERFACE_ERROR, + NM_DEVICE_INTERFACE_ERROR_NOT_ACTIVE, + "Cannot disconnect an inactive device."); + break; + default: + success = NM_DEVICE_INTERFACE_GET_INTERFACE (device)->disconnect (device, error); + break; + } + + return success; } - static gboolean impl_device_disconnect (NMDeviceInterface *device, GError **error) diff --git a/src/nm-device-interface.h b/src/nm-device-interface.h index ffa7e1c0e..0867bc292 100644 --- a/src/nm-device-interface.h +++ b/src/nm-device-interface.h @@ -36,6 +36,7 @@ typedef enum { NM_DEVICE_INTERFACE_ERROR_CONNECTION_ACTIVATING = 0, NM_DEVICE_INTERFACE_ERROR_CONNECTION_INVALID, + NM_DEVICE_INTERFACE_ERROR_NOT_ACTIVE, } NMDeviceInterfaceError; #define NM_DEVICE_INTERFACE_ERROR (nm_device_interface_error_quark ()) diff --git a/src/nm-device.c b/src/nm-device.c index 155f689a1..d7e6e256c 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -2080,8 +2080,8 @@ device_disconnect (NMDeviceInterface *device, GError **error) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (NM_DEVICE (device)); + priv->autoconnect_inhibit = TRUE; - nm_device_deactivate (device, NM_DEVICE_STATE_REASON_USER_REQUESTED); nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_USER_REQUESTED); return TRUE; }