]>
Commit | Line | Data |
---|---|---|
fd8903d4 | 1 | Index: backends/xml-backend.c |
2 | =================================================================== | |
3 | RCS file: /cvs/gnome/gconf/backends/xml-backend.c,v | |
4 | retrieving revision 1.81 | |
5 | diff -u -p -u -r1.81 xml-backend.c | |
6 | --- GConf-1.2.1/backends/xml-backend.c 21 Mar 2002 23:55:06 -0000 1.81 | |
7 | +++ GConf-1.2.1/backends/xml-backend.c 21 Aug 2002 12:47:17 -0000 | |
8 | @@ -206,6 +206,8 @@ static void destroy_source (GC | |
9 | ||
10 | static void clear_cache (GConfSource* source); | |
11 | ||
12 | +static void blow_away_locks (const char *address); | |
13 | + | |
14 | static GConfBackendVTable xml_vtable = { | |
15 | x_shutdown, | |
16 | resolve_address, | |
17 | @@ -224,7 +226,8 @@ static GConfBackendVTable xml_vtable = { | |
18 | set_schema, | |
19 | sync_all, | |
20 | destroy_source, | |
21 | - clear_cache | |
22 | + clear_cache, | |
23 | + blow_away_locks | |
24 | }; | |
25 | ||
26 | static void | |
27 | @@ -267,13 +270,48 @@ writable (GConfSource* source, | |
28 | return TRUE; | |
29 | } | |
30 | ||
31 | +static char* | |
32 | +get_dir_from_address (const char *address, | |
33 | + GError **err) | |
34 | +{ | |
35 | + char *root_dir; | |
36 | + int len; | |
37 | + | |
38 | + root_dir = gconf_address_resource (address); | |
39 | + | |
40 | + if (root_dir == NULL) | |
41 | + { | |
42 | + gconf_set_error (err, GCONF_ERROR_BAD_ADDRESS, | |
43 | + _("Couldn't find the XML root directory in the address `%s'"), | |
44 | + address); | |
45 | + return NULL; | |
46 | + } | |
47 | + | |
48 | + /* Chop trailing '/' to canonicalize */ | |
49 | + len = strlen (root_dir); | |
50 | + | |
51 | + if (root_dir[len-1] == '/') | |
52 | + root_dir[len-1] = '\0'; | |
53 | + | |
54 | + return root_dir; | |
55 | +} | |
56 | + | |
57 | +static char* | |
58 | +get_lock_dir_from_root_dir (const char *root_dir) | |
59 | +{ | |
60 | + gchar* lockdir; | |
61 | + | |
62 | + lockdir = gconf_concat_dir_and_key (root_dir, "%gconf-xml-backend.lock"); | |
63 | + | |
64 | + return lockdir; | |
65 | +} | |
66 | + | |
67 | static GConfSource* | |
68 | resolve_address (const gchar* address, GError** err) | |
69 | { | |
70 | gchar* root_dir; | |
71 | XMLSource* xsource; | |
72 | GConfSource* source; | |
73 | - guint len; | |
74 | gint flags = 0; | |
75 | GConfLock* lock = NULL; | |
76 | guint dir_mode = 0700; | |
77 | @@ -281,20 +319,10 @@ resolve_address (const gchar* address, G | |
78 | gchar** address_flags; | |
79 | gchar** iter; | |
80 | gboolean force_readonly; | |
81 | - | |
82 | - root_dir = gconf_address_resource(address); | |
83 | ||
84 | + root_dir = get_dir_from_address (address, err); | |
85 | if (root_dir == NULL) | |
86 | - { | |
87 | - gconf_set_error(err, GCONF_ERROR_BAD_ADDRESS, _("Couldn't find the XML root directory in the address `%s'"), address); | |
88 | - return NULL; | |
89 | - } | |
90 | - | |
91 | - /* Chop trailing '/' to canonicalize */ | |
92 | - len = strlen(root_dir); | |
93 | - | |
94 | - if (root_dir[len-1] == '/') | |
95 | - root_dir[len-1] = '\0'; | |
96 | + return NULL; | |
97 | ||
98 | if (mkdir(root_dir, dir_mode) < 0) | |
99 | { | |
100 | @@ -374,7 +402,7 @@ resolve_address (const gchar* address, G | |
101 | { | |
102 | gchar* lockdir; | |
103 | ||
104 | - lockdir = gconf_concat_dir_and_key(root_dir, "%gconf-xml-backend.lock"); | |
105 | + lockdir = get_lock_dir_from_root_dir (root_dir); | |
106 | ||
107 | lock = gconf_get_lock(lockdir, err); | |
108 | ||
109 | @@ -712,6 +740,58 @@ clear_cache (GConfSource* source) | |
110 | ||
111 | /* clean all entries older than 0 seconds */ | |
112 | cache_clean(xs->cache, 0); | |
113 | +} | |
114 | + | |
115 | +static void | |
116 | +blow_away_locks (const char *address) | |
117 | +{ | |
118 | + char *root_dir; | |
119 | + char *lock_dir; | |
120 | + DIR *dp; | |
121 | + struct dirent *dent; | |
122 | + | |
123 | + root_dir = get_dir_from_address (address, NULL); | |
124 | + if (root_dir == NULL) | |
125 | + return; | |
126 | + | |
127 | + lock_dir = get_lock_dir_from_root_dir (root_dir); | |
128 | + | |
129 | + dp = opendir (lock_dir); | |
130 | + | |
131 | + if (dp == NULL) | |
132 | + { | |
133 | + g_printerr (_("Could not open lock directory for %s to remove locks: %s\n"), | |
134 | + address, g_strerror (errno)); | |
135 | + goto out; | |
136 | + } | |
137 | + | |
138 | + while ((dent = readdir (dp)) != NULL) | |
139 | + { | |
140 | + char *path; | |
141 | + | |
142 | + /* ignore ., .. (and any ..foo as an intentional who-cares bug) */ | |
143 | + if (dent->d_name[0] == '.' && | |
144 | + (dent->d_name[1] == '\0' || dent->d_name[1] == '.')) | |
145 | + continue; | |
146 | + | |
147 | + path = g_build_filename (lock_dir, dent->d_name, NULL); | |
148 | + | |
149 | + if (unlink (path) < 0) | |
150 | + { | |
151 | + g_printerr (_("Could not remove file %s: %s\n"), | |
152 | + path, g_strerror (errno)); | |
153 | + } | |
154 | + | |
155 | + g_free (path); | |
156 | + } | |
157 | + | |
158 | + out: | |
159 | + | |
160 | + if (dp) | |
161 | + closedir (dp); | |
162 | + | |
163 | + g_free (root_dir); | |
164 | + g_free (lock_dir); | |
165 | } | |
166 | ||
167 | /* Initializer */ | |
168 | Index: gconf/gconf-backend.c | |
169 | =================================================================== | |
170 | RCS file: /cvs/gnome/gconf/gconf/gconf-backend.c,v | |
171 | retrieving revision 1.21 | |
172 | diff -u -p -u -r1.21 gconf-backend.c | |
173 | --- GConf-1.2.1/gconf/gconf-backend.c 4 Dec 2001 22:17:09 -0000 1.21 | |
174 | +++ GConf-1.2.1/gconf/gconf-backend.c 21 Aug 2002 12:47:17 -0000 | |
175 | @@ -353,5 +353,15 @@ gconf_backend_resolve_address (GConfBack | |
176 | return retval; | |
177 | } | |
178 | ||
179 | +void | |
180 | +gconf_blow_away_locks (const gchar* address) | |
181 | +{ | |
182 | + GConfBackend* backend; | |
183 | ||
184 | + backend = gconf_get_backend (address, NULL); | |
185 | ||
186 | + if (backend != NULL) | |
187 | + { | |
188 | + (*backend->vtable->blow_away_locks) (address); | |
189 | + } | |
190 | +} | |
191 | Index: gconf/gconf-backend.h | |
192 | =================================================================== | |
193 | RCS file: /cvs/gnome/gconf/gconf/gconf-backend.h,v | |
194 | retrieving revision 1.29 | |
195 | diff -u -p -u -r1.29 gconf-backend.h | |
196 | --- GConf-1.2.1/gconf/gconf-backend.h 13 Jul 2001 22:07:37 -0000 1.29 | |
197 | +++ GConf-1.2.1/gconf/gconf-backend.h 21 Aug 2002 12:47:17 -0000 | |
198 | @@ -127,6 +127,9 @@ struct _GConfBackendVTable { | |
199 | ||
200 | /* This is basically used by the test suite */ | |
201 | void (* clear_cache) (GConfSource* source); | |
202 | + | |
203 | + /* used by gconf-sanity-check */ | |
204 | + void (* blow_away_locks) (const char *address); | |
205 | }; | |
206 | ||
207 | struct _GConfBackend { | |
208 | @@ -161,6 +164,8 @@ void gconf_backend_unref(GConfB | |
209 | GConfSource* gconf_backend_resolve_address (GConfBackend* backend, | |
210 | const gchar* address, | |
211 | GError** err); | |
212 | + | |
213 | +void gconf_blow_away_locks (const gchar* address); | |
214 | ||
215 | #endif | |
216 | ||
217 | Index: gconf/gconf-internals.c | |
218 | =================================================================== | |
219 | RCS file: /cvs/gnome/gconf/gconf/gconf-internals.c,v | |
220 | retrieving revision 1.114 | |
221 | diff -u -p -u -r1.114 gconf-internals.c | |
222 | --- GConf-1.2.1/gconf/gconf-internals.c 4 Aug 2002 17:44:16 -0000 1.114 | |
223 | +++ GConf-1.2.1/gconf/gconf-internals.c 21 Aug 2002 12:47:18 -0000 | |
224 | @@ -2701,6 +2701,24 @@ gconf_get_current_lock_holder (const gc | |
225 | return server; | |
226 | } | |
227 | ||
228 | +void | |
229 | +gconf_daemon_blow_away_locks (void) | |
230 | +{ | |
231 | + char *lock_directory; | |
232 | + char *iorfile; | |
233 | + | |
234 | + lock_directory = gconf_get_lock_dir (); | |
235 | + | |
236 | + iorfile = g_strconcat (lock_directory, "/ior", NULL); | |
237 | + | |
238 | + if (unlink (iorfile) < 0) | |
239 | + g_printerr (_("Failed to unlink lock file %s: %s\n"), | |
240 | + iorfile, g_strerror (errno)); | |
241 | + | |
242 | + g_free (iorfile); | |
243 | + g_free (lock_directory); | |
244 | +} | |
245 | + | |
246 | static CORBA_ORB gconf_orb = CORBA_OBJECT_NIL; | |
247 | ||
248 | CORBA_ORB | |
249 | Index: gconf/gconf-internals.h | |
250 | =================================================================== | |
251 | RCS file: /cvs/gnome/gconf/gconf/gconf-internals.h,v | |
252 | retrieving revision 1.74 | |
253 | diff -u -p -u -r1.74 gconf-internals.h | |
254 | --- GConf-1.2.1/gconf/gconf-internals.h 3 Jun 2002 02:36:26 -0000 1.74 | |
255 | +++ GConf-1.2.1/gconf/gconf-internals.h 21 Aug 2002 12:47:18 -0000 | |
256 | @@ -190,6 +190,8 @@ GConfLock* gconf_get_lock_or_current_hol | |
257 | ConfigServer gconf_get_current_lock_holder (const gchar *lock_directory, | |
258 | GString *failure_log); | |
259 | ||
260 | +void gconf_daemon_blow_away_locks (void); | |
261 | + | |
262 | GError* gconf_error_new (GConfError en, | |
263 | const gchar* format, ...) G_GNUC_PRINTF (2, 3); | |
264 | ||
265 | Index: gconf/gconf-sanity-check.c | |
266 | =================================================================== | |
267 | RCS file: /cvs/gnome/gconf/gconf/gconf-sanity-check.c,v | |
268 | retrieving revision 1.4 | |
269 | diff -u -p -u -r1.4 gconf-sanity-check.c | |
270 | --- GConf-1.2.1/gconf/gconf-sanity-check.c 21 Mar 2002 23:55:09 -0000 1.4 | |
271 | +++ GConf-1.2.1/gconf/gconf-sanity-check.c 21 Aug 2002 12:47:18 -0000 | |
272 | @@ -53,8 +53,9 @@ struct poptOption options[] = { | |
273 | static gboolean ensure_gtk (void); | |
274 | static void show_fatal_error_dialog (const char *format, | |
275 | ...) G_GNUC_PRINTF (1, 2); | |
276 | +static gboolean offer_delete_locks (void); | |
277 | static gboolean check_file_locking (void); | |
278 | -static gboolean check_gconf (void); | |
279 | +static gboolean check_gconf (gboolean display_errors); | |
280 | ||
281 | int | |
282 | main (int argc, char** argv) | |
283 | @@ -83,8 +84,14 @@ main (int argc, char** argv) | |
284 | if (!check_file_locking ()) | |
285 | return 1; | |
286 | ||
287 | - if (!check_gconf ()) | |
288 | - return 1; | |
289 | + if (!check_gconf (FALSE)) | |
290 | + { | |
291 | + if (!offer_delete_locks ()) | |
292 | + return 1; | |
293 | + | |
294 | + if (!check_gconf (TRUE)) | |
295 | + return 1; | |
296 | + } | |
297 | ||
298 | return 0; | |
299 | } | |
300 | @@ -164,7 +171,7 @@ check_file_locking (void) | |
301 | } | |
302 | ||
303 | static gboolean | |
304 | -check_gconf (void) | |
305 | +check_gconf (gboolean display_errors) | |
306 | { | |
307 | GSList* addresses; | |
308 | GSList* tmp; | |
309 | @@ -192,11 +199,12 @@ check_gconf (void) | |
310 | ||
311 | if (addresses == NULL) | |
312 | { | |
313 | - show_fatal_error_dialog (_("Please contact your system administrator to resolve the following problem:\n" | |
314 | - "No configuration sources in the configuration file \"%s\"; this means that preferences and other settings can't be saved. %s%s"), | |
315 | - conffile, | |
316 | - error ? _("Error reading the file: ") : "", | |
317 | - error ? error->message : ""); | |
318 | + if (display_errors) | |
319 | + show_fatal_error_dialog (_("Please contact your system administrator to resolve the following problem:\n" | |
320 | + "No configuration sources in the configuration file \"%s\"; this means that preferences and other settings can't be saved. %s%s"), | |
321 | + conffile, | |
322 | + error ? _("Error reading the file: ") : "", | |
323 | + error ? error->message : ""); | |
324 | ||
325 | if (error) | |
326 | g_error_free (error); | |
327 | @@ -217,9 +225,10 @@ check_gconf (void) | |
328 | ||
329 | if (error) | |
330 | { | |
331 | - show_fatal_error_dialog (_("Please contact your system administrator to resolve the following problem:\n" | |
332 | - "Could not resolve the address \"%s\" in the configuration file \"%s\": %s"), | |
333 | - address, conffile, error->message); | |
334 | + if (display_errors) | |
335 | + show_fatal_error_dialog (_("Please contact your system administrator to resolve the following problem:\n" | |
336 | + "Could not resolve the address \"%s\" in the configuration file \"%s\": %s"), | |
337 | + address, conffile, error->message); | |
338 | g_error_free (error); | |
339 | goto out; | |
340 | } | |
341 | @@ -269,6 +278,97 @@ show_fatal_error_dialog (const char *for | |
342 | gtk_dialog_run (GTK_DIALOG (d)); | |
343 | ||
344 | gtk_widget_destroy (d); | |
345 | +} | |
346 | + | |
347 | +static gboolean | |
348 | +offer_delete_locks (void) | |
349 | +{ | |
350 | + gboolean delete_locks; | |
351 | + const char *question; | |
352 | + | |
353 | + delete_locks = FALSE; | |
354 | + question = _("Your preferences files are currently in use. " | |
355 | + "(If you are logged in to this same account from " | |
356 | + "another computer, the other login session is probably using " | |
357 | + "your preferences files.) " | |
358 | + "You can choose to continue, but be aware that other login " | |
359 | + "sessions may become temporarily confused. " | |
360 | + "If you are not logged in elsewhere, it should be harmless to " | |
361 | + "continue."); | |
362 | + | |
363 | + if (ensure_gtk ()) | |
364 | + { | |
365 | + GtkDialog *d; | |
366 | + int response; | |
367 | + | |
368 | + d = gtk_message_dialog_new (NULL, 0, | |
369 | + GTK_MESSAGE_ERROR, | |
370 | + GTK_BUTTONS_NONE, | |
371 | + "%s", question); | |
372 | + | |
373 | + gtk_dialog_add_buttons (GTK_DIALOG (d), | |
374 | + GTK_STOCK_CANCEL, | |
375 | + GTK_RESPONSE_REJECT, | |
376 | + _("Continue"), | |
377 | + GTK_RESPONSE_ACCEPT, | |
378 | + NULL); | |
379 | + | |
380 | + response = gtk_dialog_run (GTK_DIALOG (d)); | |
381 | + | |
382 | + gtk_widget_destroy (d); | |
383 | + | |
384 | + if (response == GTK_RESPONSE_ACCEPT) | |
385 | + delete_locks = TRUE; | |
386 | + } | |
387 | + else | |
388 | + { | |
389 | + g_print (_("%s Continue (y/n)?"), question); | |
390 | + switch (getchar ()) | |
391 | + { | |
392 | + case 'y': | |
393 | + case 'Y': | |
394 | + delete_locks = TRUE; | |
395 | + break; | |
396 | + } | |
397 | + } | |
398 | + | |
399 | + if (delete_locks) | |
400 | + { | |
401 | + GSList* addresses; | |
402 | + GSList* tmp; | |
403 | + char *conffile; | |
404 | + | |
405 | + conffile = g_strconcat (GCONF_CONFDIR, "/path", NULL); | |
406 | + | |
407 | + addresses = gconf_load_source_path (conffile, NULL); | |
408 | + | |
409 | + g_free (conffile); | |
410 | + | |
411 | + if (addresses == NULL) | |
412 | + g_printerr ("Failed to load addresses to delete locks\n"); | |
413 | + | |
414 | + tmp = addresses; | |
415 | + while (tmp != NULL) | |
416 | + { | |
417 | + const char *address; | |
418 | + | |
419 | + address = tmp->data; | |
420 | + | |
421 | + gconf_blow_away_locks (address); | |
422 | + | |
423 | + g_free (tmp->data); | |
424 | + | |
425 | + tmp = tmp->next; | |
426 | + } | |
427 | + | |
428 | + g_slist_free (addresses); | |
429 | + | |
430 | + gconf_daemon_blow_away_locks (); | |
431 | + | |
432 | + return TRUE; | |
433 | + } | |
434 | + | |
435 | + return FALSE; | |
436 | } | |
437 | ||
438 | /* this is because setting up gtk is kind of slow, no point doing it |