Commit fa70542c authored by Dan Williams's avatar Dan Williams

core: add networking enable/disable knob distinct from sleep/wake (rh #589108) (bgo #346615)

Since forever we've used sleep/wake as the way to implement
Networking Enabled.  When the state file was introduced to make the
networking and wifi states persistent, we ran into a bug where
a failed suspend (like if the machine ran out of power while
suspended) would result in networking being disabled on reboot
since suspend/resume used the same knob as enable/disable.

This patch adds a distinct call for enable/disable networking
which changes the state file, while sleep/wake no longer change
the state file.
parent c1b3b137
......@@ -39,6 +39,12 @@ object. dbus-glib generates the same bound function names for D-Bus the methods
<arg name="sleep" type="b" direction="in"/>
</method>
<method name="Enable">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_enable"/>
<arg name="enable" type="b" direction="in"/>
</method>
<property name="NetworkingEnabled" type="b" access="read"/>
<property name="WirelessEnabled" type="b" access="readwrite"/>
<property name="WirelessHardwareEnabled" type="b" access="read"/>
<property name="WwanEnabled" type="b" access="readwrite"/>
......
......@@ -87,7 +87,10 @@
<method name="Sleep">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_sleep"/>
<tp:docstring>
Control the NetworkManager daemon's sleep state. When asleep, all interfaces that it manages are deactivated. When awake, devices are available to be activated.
Control the NetworkManager daemon's sleep state. When asleep, all
interfaces that it manages are deactivated. When awake, devices are
available to be activated. This command should not be called directly
by users or clients; it is intended for system suspend/resume tracking.
</tp:docstring>
<arg name="sleep" type="b" direction="in">
<tp:docstring>
......@@ -96,6 +99,23 @@
</arg>
</method>
<method name="Enable">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_enable"/>
<tp:docstring>
Control whether overall networking is enabled or disabled. When
disabled, all interfaces that NM manages are deactivated. When enabled,
all managed interfaces are re-enabled and available to be activated.
This command should be used by clients that provide to users the ability
to enable/disable all networking.
</tp:docstring>
<arg name="enable" type="b" direction="in">
<tp:docstring>
If FALSE, indicates that all networking should be disabled. If TRUE,
indicates that NetworkManager should begin managing network devices.
</tp:docstring>
</arg>
</method>
<method name="SetLogging">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_set_logging"/>
<tp:docstring>
......@@ -118,6 +138,13 @@
</arg>
</method>
<property name="NetworkingEnabled" type="b" access="read">
<tp:docstring>
Indicates if overall networking is currently enabled or not. See the
Enable() method.
</tp:docstring>
</property>
<property name="WirelessEnabled" type="b" access="readwrite">
<tp:docstring>
Indicates if wireless is currently enabled or not.
......
......@@ -36,6 +36,8 @@ global:
nm_client_get_manager_running;
nm_client_get_state;
nm_client_get_type;
nm_client_networking_get_enabled;
nm_client_networking_set_enabled;
nm_client_new;
nm_client_sleep;
nm_client_wireless_get_enabled;
......
......@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2008 Red Hat, Inc.
* Copyright (C) 2007 - 2010 Red Hat, Inc.
*/
#include <dbus/dbus-glib.h>
......@@ -58,6 +58,7 @@ typedef struct {
GPtrArray *devices;
GPtrArray *active_connections;
gboolean networking_enabled;
gboolean wireless_enabled;
gboolean wireless_hw_enabled;
......@@ -69,6 +70,7 @@ enum {
PROP_0,
PROP_STATE,
PROP_MANAGER_RUNNING,
PROP_NETWORKING_ENABLED,
PROP_WIRELESS_ENABLED,
PROP_WIRELESS_HARDWARE_ENABLED,
PROP_WWAN_ENABLED,
......@@ -250,6 +252,7 @@ register_for_property_changed (NMClient *client)
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_CLIENT_STATE, _nm_object_demarshal_generic, &priv->state },
{ NM_CLIENT_NETWORKING_ENABLED, _nm_object_demarshal_generic, &priv->networking_enabled },
{ NM_CLIENT_WIRELESS_ENABLED, _nm_object_demarshal_generic, &priv->wireless_enabled },
{ NM_CLIENT_WIRELESS_HARDWARE_ENABLED, _nm_object_demarshal_generic, &priv->wireless_hw_enabled },
{ NM_CLIENT_WWAN_ENABLED, _nm_object_demarshal_generic, &priv->wwan_enabled },
......@@ -427,6 +430,9 @@ get_property (GObject *object,
case PROP_MANAGER_RUNNING:
g_value_set_boolean (value, priv->manager_running);
break;
case PROP_NETWORKING_ENABLED:
g_value_set_boolean (value, priv->networking_enabled);
break;
case PROP_WIRELESS_ENABLED:
g_value_set_boolean (value, priv->wireless_enabled);
break;
......@@ -489,6 +495,19 @@ nm_client_class_init (NMClientClass *client_class)
FALSE,
G_PARAM_READABLE));
/**
* NMClient::networking-enabled:
*
* Whether networking is enabled.
**/
g_object_class_install_property
(object_class, PROP_NETWORKING_ENABLED,
g_param_spec_boolean (NM_CLIENT_NETWORKING_ENABLED,
"NetworkingEnabled",
"Is networking enabled",
TRUE,
G_PARAM_READABLE));
/**
* NMClient::wireless-enabled:
*
......@@ -1042,26 +1061,40 @@ nm_client_get_state (NMClient *client)
}
/**
* nm_client_sleep:
* nm_client_networking_set_enabled:
* @client: a #NMClient
* @sleep: %TRUE to put the daemon to sleep
* @enabled: %TRUE to set networking enabled, %FALSE to set networking disabled
*
* Enables or disables networking. When the daemon is put to sleep, it'll deactivate and disable
* all the active devices.
* Enables or disables networking. When networking is disabled, all controlled
* interfaces are disconnected and deactivated. When networking is enabled,
* all controlled interfaces are available for activation.
**/
void
nm_client_sleep (NMClient *client, gboolean sleep)
nm_client_networking_set_enabled (NMClient *client, gboolean enable)
{
GError *err = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
if (!org_freedesktop_NetworkManager_sleep (NM_CLIENT_GET_PRIVATE (client)->client_proxy, sleep, &err)) {
g_warning ("Error in sleep: %s", err->message);
if (!org_freedesktop_NetworkManager_enable (NM_CLIENT_GET_PRIVATE (client)->client_proxy, enable, &err)) {
g_warning ("Error enabling/disabling networking: %s", err->message);
g_error_free (err);
}
}
/**
* nm_client_sleep:
* @client: a #NMClient
* @sleep: %TRUE to put the daemon to sleep
*
* Deprecated; use nm_client_networking_set_enabled() instead.
**/
void
nm_client_sleep (NMClient *client, gboolean sleep)
{
nm_client_networking_set_enabled (client, !sleep);
}
/**
* nm_client_get_manager_running:
* @client: a #NMClient
......
......@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2008 Red Hat, Inc.
* Copyright (C) 2007 - 2010 Red Hat, Inc.
*/
#ifndef NM_CLIENT_H
......@@ -43,6 +43,7 @@ G_BEGIN_DECLS
#define NM_CLIENT_STATE "state"
#define NM_CLIENT_MANAGER_RUNNING "manager-running"
#define NM_CLIENT_NETWORKING_ENABLED "networking-enabled"
#define NM_CLIENT_WIRELESS_ENABLED "wireless-enabled"
#define NM_CLIENT_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
#define NM_CLIENT_WWAN_ENABLED "wwan-enabled"
......@@ -88,6 +89,9 @@ void nm_client_activate_connection (NMClient *client,
void nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active);
gboolean nm_client_networking_get_enabled (NMClient *client);
void nm_client_networking_set_enabled (NMClient *client, gboolean enabled);
gboolean nm_client_wireless_get_enabled (NMClient *client);
void nm_client_wireless_set_enabled (NMClient *client, gboolean enabled);
gboolean nm_client_wireless_hardware_get_enabled (NMClient *client);
......
This diff is collapsed.
......@@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2008 Red Hat, Inc.
* Copyright (C) 2007 - 2010 Red Hat, Inc.
*/
#ifndef NM_MANAGER_H
......@@ -35,6 +35,14 @@
#define NM_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_MANAGER))
#define NM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MANAGER, NMManagerClass))
#define NM_MANAGER_STATE "state"
#define NM_MANAGER_NETWORKING_ENABLED "networking-enabled"
#define NM_MANAGER_WIRELESS_ENABLED "wireless-enabled"
#define NM_MANAGER_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
#define NM_MANAGER_WWAN_ENABLED "wwan-enabled"
#define NM_MANAGER_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled"
#define NM_MANAGER_ACTIVE_CONNECTIONS "active-connections"
/* Not exported */
#define NM_MANAGER_HOSTNAME "hostname"
#define NM_MANAGER_SLEEPING "sleeping"
......
......@@ -718,13 +718,14 @@ hostname_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data)
static void
sleeping_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data)
{
gboolean sleeping = FALSE;
gboolean sleeping = FALSE, enabled = FALSE;
GSList *connections, *iter;
g_object_get (G_OBJECT (manager), NM_MANAGER_SLEEPING, &sleeping, NULL);
g_object_get (G_OBJECT (manager), NM_MANAGER_NETWORKING_ENABLED, &enabled, NULL);
/* Clear the invalid flag on all connections so they'll get retried on wakeup */
if (sleeping) {
if (sleeping || !enabled) {
connections = nm_manager_get_connections (manager, NM_CONNECTION_SCOPE_SYSTEM);
connections = g_slist_concat (connections, nm_manager_get_connections (manager, NM_CONNECTION_SCOPE_USER));
for (iter = connections; iter; iter = g_slist_next (iter))
......@@ -1055,6 +1056,10 @@ nm_policy_new (NMManager *manager, NMVPNManager *vpn_manager)
G_CALLBACK (sleeping_changed), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
id = g_signal_connect (manager, "notify::" NM_MANAGER_NETWORKING_ENABLED,
G_CALLBACK (sleeping_changed), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
id = g_signal_connect (manager, "device-added",
G_CALLBACK (device_added), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
......
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