/[gentoo-x86]/net-misc/networkmanager/files/networkmanager-0.9.2.0-pre-sleep.patch
Gentoo

Contents of /net-misc/networkmanager/files/networkmanager-0.9.2.0-pre-sleep.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Mon Feb 20 09:24:59 2012 UTC (2 years, 5 months ago) by tetromino
Branch: MAIN
CVS Tags: HEAD
Error occurred while calculating annotation data.
Fix openrc service going inactive while active connections are present (bug #402613, thanks to Thomas Witt). Try to be more user-friendly by waiting a few seconds before marking the service as inactive. Dispatch a pre-sleep event to unmount network filesystems before suspending (bug #402085, thanks to Marien Zwart). Do not truncate WPA passwords at '#' character (bug #402133, thanks to John Hardin).

(Portage version: 2.2.0_alpha87/cvs/Linux x86_64)

1 From 00b5c3785f7f5ce8da6db5da3fab814680ff82bc Mon Sep 17 00:00:00 2001
2 From: Alexandre Rostovtsev <tetromino@gentoo.org>
3 Date: Mon, 20 Feb 2012 02:14:26 -0500
4 Subject: [PATCH] Implement "pre-sleep" action dispatch
5
6 Based on work by Christian Becke <christianbecke@gmail.com> in
7 https://bugzilla.gnome.org/show_bug.cgi?id=387832
8
9 Adds a nm_utils_call_dispatcher_with_notify variant of the dispatcher
10 call, and uses it to dispatch a "pre-sleep" action before sleeping.
11 ---
12 callouts/nm-dispatcher-utils.c | 3 +-
13 src/NetworkManagerUtils.c | 70 ++++++++++++++++++++++++++++++++++------
14 src/NetworkManagerUtils.h | 12 +++++++
15 src/nm-manager.c | 28 ++++++++++++----
16 4 files changed, 95 insertions(+), 18 deletions(-)
17
18 diff --git a/callouts/nm-dispatcher-utils.c b/callouts/nm-dispatcher-utils.c
19 index 887e80d..db66b61 100644
20 --- a/callouts/nm-dispatcher-utils.c
21 +++ b/callouts/nm-dispatcher-utils.c
22 @@ -407,7 +407,8 @@ nm_dispatcher_utils_construct_envp (const char *action,
23 g_return_val_if_fail (*out_iface == NULL, NULL);
24
25 /* Hostname changes don't require a device nor contain a connection */
26 - if (!strcmp (action, "hostname"))
27 + if (!strcmp (action, "hostname") ||
28 + !strcmp (action, "pre-sleep"))
29 return g_new0 (char *, 1);
30
31 /* Canonicalize the VPN interface name; "" is used when passing it through
32 diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
33 index 451de6d..008b94e 100644
34 --- a/src/NetworkManagerUtils.c
35 +++ b/src/NetworkManagerUtils.c
36 @@ -44,6 +44,13 @@
37 #include "nm-setting-wireless-security.h"
38 #include "nm-manager-auth.h"
39
40 +typedef struct
41 +{
42 + NMDBusManager *dbus_mgr;
43 + NMUtilsDispatcherDoneCallback notify;
44 + gpointer user_data;
45 +} NMUtilsCallDispatcherNotifyData;
46 +
47 /*
48 * nm_ethernet_address_is_valid
49 *
50 @@ -475,18 +482,36 @@ fill_vpn_props (NMIP4Config *ip4_config,
51 static void
52 dispatcher_done_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
53 {
54 + NMUtilsCallDispatcherNotifyData *notify_data = (NMUtilsCallDispatcherNotifyData *) user_data;
55 +
56 dbus_g_proxy_end_call (proxy, call, NULL, G_TYPE_INVALID);
57 g_object_unref (proxy);
58 + if (notify_data->notify != NULL)
59 + notify_data->notify (notify_data->user_data);
60 +}
61 +
62 +static void
63 +nm_utils_call_dispatcher_notify_data_free (NMUtilsCallDispatcherNotifyData *data)
64 +{
65 + if (data == NULL)
66 + return;
67 +
68 + if (data->dbus_mgr != NULL)
69 + g_object_unref (data->dbus_mgr);
70 + g_free (data);
71 }
72
73 void
74 -nm_utils_call_dispatcher (const char *action,
75 - NMConnection *connection,
76 - NMDevice *device,
77 - const char *vpn_iface,
78 - NMIP4Config *vpn_ip4_config,
79 - NMIP6Config *vpn_ip6_config)
80 +nm_utils_call_dispatcher_with_notify (const char *action,
81 + NMConnection *connection,
82 + NMDevice *device,
83 + const char *vpn_iface,
84 + NMIP4Config *vpn_ip4_config,
85 + NMIP6Config *vpn_ip6_config,
86 + NMUtilsDispatcherDoneCallback notify,
87 + gpointer user_data)
88 {
89 + NMUtilsCallDispatcherNotifyData *notify_data;
90 NMDBusManager *dbus_mgr;
91 DBusGProxy *proxy;
92 DBusGConnection *g_connection;
93 @@ -503,7 +528,8 @@ nm_utils_call_dispatcher (const char *action,
94 g_return_if_fail (action != NULL);
95
96 /* All actions except 'hostname' require a device */
97 - if (strcmp (action, "hostname") != 0)
98 + if (strcmp (action, "hostname") != 0 &&
99 + strcmp (action, "pre-sleep") != 0)
100 g_return_if_fail (NM_IS_DEVICE (device));
101 /* VPN actions require at least an IPv4 config (for now) */
102 if (strcmp (action, "vpn-up") == 0)
103 @@ -544,7 +570,8 @@ nm_utils_call_dispatcher (const char *action,
104 vpn_ip6_props = value_hash_create ();
105
106 /* hostname actions only send the hostname */
107 - if (strcmp (action, "hostname") != 0) {
108 + if (strcmp (action, "hostname") != 0 &&
109 + strcmp (action, "pre-sleep") != 0) {
110 fill_device_props (device,
111 device_props,
112 device_ip4_props,
113 @@ -555,6 +582,11 @@ nm_utils_call_dispatcher (const char *action,
114 fill_vpn_props (vpn_ip4_config, NULL, vpn_ip4_props, vpn_ip6_props);
115 }
116
117 + notify_data = g_new0 (NMUtilsCallDispatcherNotifyData, 1);
118 + notify_data->dbus_mgr = dbus_mgr;
119 + notify_data->notify = notify;
120 + notify_data->user_data = user_data;
121 +
122 /* Do a non-blocking call, but wait for the reply, because dbus-glib
123 * sometimes needs time to complete internal housekeeping. If we use
124 * dbus_g_proxy_call_no_reply(), that housekeeping (specifically the
125 @@ -563,8 +595,8 @@ nm_utils_call_dispatcher (const char *action,
126 */
127 dbus_g_proxy_begin_call_with_timeout (proxy, "Action",
128 dispatcher_done_cb,
129 - dbus_mgr, /* automatically unref the dbus mgr when call is done */
130 - g_object_unref,
131 + notify_data, /* automatically unref the dbus mgr when call is done */
132 + (GDestroyNotify) nm_utils_call_dispatcher_notify_data_free,
133 5000,
134 G_TYPE_STRING, action,
135 DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, connection_hash,
136 @@ -589,6 +621,24 @@ nm_utils_call_dispatcher (const char *action,
137 g_hash_table_destroy (vpn_ip6_props);
138 }
139
140 +void
141 +nm_utils_call_dispatcher (const char *action,
142 + NMConnection *connection,
143 + NMDevice *device,
144 + const char *vpn_iface,
145 + NMIP4Config *vpn_ip4_config,
146 + NMIP6Config *vpn_ip6_config)
147 +{
148 + nm_utils_call_dispatcher_with_notify (action,
149 + connection,
150 + device,
151 + vpn_iface,
152 + vpn_ip4_config,
153 + vpn_ip6_config,
154 + NULL,
155 + NULL);
156 +}
157 +
158 gboolean
159 nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr)
160 {
161 diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
162 index 1bf741e..bdc0fef 100644
163 --- a/src/NetworkManagerUtils.h
164 +++ b/src/NetworkManagerUtils.h
165 @@ -49,6 +49,18 @@ void nm_utils_call_dispatcher (const char *action,
166 NMIP4Config *vpn_ip4_config,
167 NMIP6Config *vpn_ip6_config);
168
169 +typedef void (*NMUtilsDispatcherDoneCallback) (gpointer user_data);
170 +
171 +void
172 +nm_utils_call_dispatcher_with_notify (const char *action,
173 + NMConnection *connection,
174 + NMDevice *device,
175 + const char *vpn_iface,
176 + NMIP4Config *vpn_ip4_config,
177 + NMIP6Config *vpn_ip6_config,
178 + NMUtilsDispatcherDoneCallback notify,
179 + gpointer user_data);
180 +
181 gboolean nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr);
182 gboolean nm_match_spec_s390_subchannels (const GSList *specs, const char *subchannels);
183
184 diff --git a/src/nm-manager.c b/src/nm-manager.c
185 index 7205c7a..9e70071 100644
186 --- a/src/nm-manager.c
187 +++ b/src/nm-manager.c
188 @@ -2433,6 +2433,23 @@ impl_manager_deactivate_connection (NMManager *self,
189 }
190
191 static void
192 +pre_sleep_dispatcher_done (gpointer user_data)
193 +{
194 + NMManager *self = (NMManager *) user_data;
195 + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
196 + GSList *iter;
197 +
198 + /* Just deactivate and down all devices from the device list,
199 + * to keep things fast the device list will get resynced when
200 + * the manager wakes up.
201 + */
202 + for (iter = priv->devices; iter; iter = iter->next)
203 + nm_device_set_managed (NM_DEVICE (iter->data), FALSE, NM_DEVICE_STATE_REASON_SLEEPING);
204 +
205 + nm_manager_update_state (self);
206 +}
207 +
208 +static void
209 do_sleep_wake (NMManager *self)
210 {
211 NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
212 @@ -2442,13 +2459,10 @@ do_sleep_wake (NMManager *self)
213 if (manager_sleeping (self)) {
214 nm_log_info (LOGD_SUSPEND, "sleeping or disabling...");
215
216 - /* Just deactivate and down all devices from the device list,
217 - * to keep things fast the device list will get resynced when
218 - * the manager wakes up.
219 - */
220 - for (iter = priv->devices; iter; iter = iter->next)
221 - nm_device_set_managed (NM_DEVICE (iter->data), FALSE, NM_DEVICE_STATE_REASON_SLEEPING);
222 -
223 + nm_utils_call_dispatcher_with_notify ("pre-sleep",
224 + NULL, NULL, NULL, NULL, NULL,
225 + pre_sleep_dispatcher_done, self);
226 + return;
227 } else {
228 nm_log_info (LOGD_SUSPEND, "waking up and re-enabling...");
229
230 --
231 1.7.8.4

  ViewVC Help
Powered by ViewVC 1.1.20