Annotation of /trunk/gnome-volume-manager/patches/gnome-volume-manager-1.3.3-reconnect_dbus.patch
Parent Directory | Revision Log
Revision 144 -
(hide annotations)
(download)
Tue May 8 20:06:05 2007 UTC (17 years, 4 months ago) by niro
File size: 3984 byte(s)
Tue May 8 20:06:05 2007 UTC (17 years, 4 months ago) by niro
File size: 3984 byte(s)
-import
1 | niro | 144 | diff -urN gnome-volume-manager-1.3.3.orig/src/manager.c gnome-volume-manager-1.3.3/src/manager.c |
2 | --- gnome-volume-manager-1.3.3.orig/src/manager.c 2005-07-25 13:32:13.000000000 -0500 | ||
3 | +++ gnome-volume-manager-1.3.3/src/manager.c 2005-07-25 13:36:01.000000000 -0500 | ||
4 | @@ -48,7 +48,8 @@ | ||
5 | #define NAUTILUS_COMMAND BIN_NAUTILUS" -n --no-desktop %m" | ||
6 | |||
7 | static struct gvm_configuration config; | ||
8 | -static LibHalContext *hal_ctx; | ||
9 | +static LibHalContext *hal_ctx = NULL; | ||
10 | +static DBusConnection *dbus_connection = NULL; | ||
11 | |||
12 | #ifndef ASSUME_SUBMOUNT | ||
13 | /** Table of UDI's for volumes being mounted by g-v-m that we need to apply policy to */ | ||
14 | @@ -1379,6 +1380,73 @@ | ||
15 | { | ||
16 | } | ||
17 | |||
18 | +static LibHalContext * gvm_do_hal_init (); | ||
19 | + | ||
20 | +/** Invoked by gvm_do_filter_dbus_msg in response to a D-BUS disconnect event. | ||
21 | + * | ||
22 | + * @param data Context pointer | ||
23 | + * @return true if it should be tried again, false if success or failure. | ||
24 | + */ | ||
25 | +static gboolean | ||
26 | +gvm_reconnect_to_hal (gpointer data __attribute__((__unused__))) | ||
27 | +{ | ||
28 | + static unsigned int retries = 0; | ||
29 | + DBusError error; | ||
30 | + | ||
31 | + dbg ("Trying a reconnect ...\n"); | ||
32 | + hal_ctx = gvm_do_hal_init (); | ||
33 | + if (hal_ctx != NULL) { | ||
34 | + dbg ("Reconnected OK.\n"); | ||
35 | + retries = 0; | ||
36 | + return FALSE; | ||
37 | + } else if (dbus_connection){ | ||
38 | + /* shut down dbus connection to try it again */ | ||
39 | + dbus_connection_unref (dbus_connection); | ||
40 | + dbus_connection = NULL; | ||
41 | + } | ||
42 | + | ||
43 | + /* Retry later if it failed. */ | ||
44 | + if (retries++ < 100) | ||
45 | + return TRUE; | ||
46 | + | ||
47 | + /* Too many retries; clean up and bail. */ | ||
48 | + warn("gvm_reconnect_to_hal: no reconnection after 100 retries, exiting\n"); | ||
49 | + libhal_ctx_shutdown (hal_ctx, &error); | ||
50 | + libhal_ctx_free (hal_ctx); | ||
51 | + hal_ctx = NULL; | ||
52 | + gtk_main_quit (); | ||
53 | + return FALSE; | ||
54 | +} | ||
55 | + | ||
56 | +/** Invoked by D-BUS to filter messages. | ||
57 | + * | ||
58 | + * @param connection D-BUS connection | ||
59 | + * @param message D-BUS message | ||
60 | + * @param user_data Context pointer | ||
61 | + */ | ||
62 | +static DBusHandlerResult | ||
63 | +gvm_do_filter_dbus_msg (DBusConnection *connection __attribute__((__unused__)), | ||
64 | + DBusMessage *message, | ||
65 | + void *user_data __attribute__((__unused__))) | ||
66 | +{ | ||
67 | + DBusError error; | ||
68 | + | ||
69 | + if (dbus_message_is_signal (message, | ||
70 | + DBUS_INTERFACE_LOCAL, | ||
71 | + "Disconnected")) { | ||
72 | + dbg("gvm_do_filter_dbus_msg: received Disconnected message\n"); | ||
73 | + g_timeout_add(500, gvm_reconnect_to_hal, NULL); | ||
74 | + libhal_ctx_shutdown (hal_ctx, &error); | ||
75 | + libhal_ctx_free (hal_ctx); | ||
76 | + hal_ctx = NULL; | ||
77 | + dbus_connection_unref (dbus_connection); | ||
78 | + dbus_connection = NULL; | ||
79 | + return DBUS_HANDLER_RESULT_HANDLED; | ||
80 | + } | ||
81 | + else | ||
82 | + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | ||
83 | +} | ||
84 | + | ||
85 | /** Integrate a dbus mainloop. | ||
86 | * | ||
87 | * @param ctx LibHal context | ||
88 | @@ -1389,14 +1457,15 @@ | ||
89 | static dbus_bool_t | ||
90 | hal_mainloop_integration (LibHalContext *ctx, DBusError *error) | ||
91 | { | ||
92 | - DBusConnection *dbus_connection; | ||
93 | - | ||
94 | dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, error); | ||
95 | |||
96 | if (dbus_error_is_set (error)) | ||
97 | return FALSE; | ||
98 | + | ||
99 | + dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE); | ||
100 | |||
101 | dbus_connection_setup_with_g_main (dbus_connection, NULL); | ||
102 | + dbus_connection_add_filter (dbus_connection, gvm_do_filter_dbus_msg, NULL, NULL); | ||
103 | |||
104 | libhal_ctx_set_dbus_connection (ctx, dbus_connection); | ||
105 | |||
106 | @@ -1556,6 +1625,10 @@ | ||
107 | DBusError error; | ||
108 | GSList *l; | ||
109 | |||
110 | + if (ctx == NULL) { | ||
111 | + warn("unmount_all: No hal connection! can't unmount volumes\n"); | ||
112 | + return; | ||
113 | + } | ||
114 | dbg ("unmounting all volumes that we saw mounted in our life\n"); | ||
115 | dbus_error_init (&error); | ||
116 | for (l = mounted_volumes; l != NULL; l = g_slist_next (l)) { |