[PATCH] Use module's shutdown functions
- From: Christian Neumair <chris gnome-de org>
- To: gnome-vfs-list gnome org
- Subject: [PATCH] Use module's shutdown functions
- Date: Sun, 09 Apr 2006 14:24:29 +0200
The attached patch ensures that each module's shutdown function is
called when gnome_vfs_shutdown is called:
http://bugzilla.gnome.org/show_bug.cgi?id=154980
--
Christian Neumair <chris gnome-de org>
Index: libgnomevfs/gnome-vfs-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-method.c,v
retrieving revision 1.35
diff -u -p -r1.35 gnome-vfs-method.c
--- libgnomevfs/gnome-vfs-method.c 13 Dec 2005 15:18:06 -0000 1.35
+++ libgnomevfs/gnome-vfs-method.c 9 Apr 2006 12:20:39 -0000
@@ -47,7 +47,7 @@ struct _ModuleElement {
const char *args;
GnomeVFSMethod *method;
GnomeVFSTransform *transform;
- int nusers;
+ GnomeVFSMethodShutdownFunc shutdown_function;
gboolean run_in_daemon;
};
typedef struct _ModuleElement ModuleElement;
@@ -93,10 +93,24 @@ _gnome_vfs_get_daemon_force_probe_callba
return daemon_force_probe_callback;
}
+static void
+module_element_free (gpointer elementp)
+{
+ ModuleElement *element = (ModuleElement *) elementp;
+ if (element->shutdown_function != NULL) {
+ (* element->shutdown_function) (element->method);
+ }
+
+ /* NB: this is the key */
+ g_free (element->name);
+ g_free (element);
+}
+
static gboolean
init_hash_table (void)
{
- module_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ module_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+ NULL, module_element_free);
return TRUE;
}
@@ -192,7 +206,8 @@ gnome_vfs_method_init (void)
static void
load_module (const gchar *module_name, const char *method_name, const char *args,
- GnomeVFSMethod **method, GnomeVFSTransform **transform)
+ GnomeVFSMethod **method, GnomeVFSTransform **transform,
+ GnomeVFSMethodShutdownFunc *shutdown_function)
{
GModule *module;
GnomeVFSMethod *temp_method = NULL;
@@ -200,10 +215,10 @@ load_module (const gchar *module_name, c
GnomeVFSMethodInitFunc init_function = NULL;
GnomeVFSTransformInitFunc transform_function = NULL;
- GnomeVFSMethodShutdownFunc shutdown_function = NULL;
*method = NULL;
*transform = NULL;
+ *shutdown_function = NULL;
module = g_module_open (module_name, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
if (module == NULL) {
@@ -216,11 +231,11 @@ load_module (const gchar *module_name, c
g_module_symbol (module, GNOME_VFS_MODULE_TRANSFORM,
(gpointer *) &transform_function);
g_module_symbol (module, GNOME_VFS_MODULE_SHUTDOWN,
- (gpointer *) &shutdown_function);
+ (gpointer *) shutdown_function);
- if ((init_function == NULL || shutdown_function == NULL) &&
+ if ((init_function == NULL || *shutdown_function == NULL) &&
(transform_function == NULL)) {
- g_warning ("module '%s' has no init function; may be an out-of-date module", module_name);
+ g_warning ("module '%s' does not have init, transform and shutfown functions; may be an out-of-date module", module_name);
return;
}
@@ -285,7 +300,8 @@ load_module (const gchar *module_name, c
static void
load_module_in_path_list (const gchar *base_name, const char *method_name, const char *args,
- GnomeVFSMethod **method, GnomeVFSTransform **transform)
+ GnomeVFSMethod **method, GnomeVFSTransform **transform,
+ GnomeVFSMethodShutdownFunc *shutdown_function)
{
GList *p;
@@ -299,7 +315,7 @@ load_module_in_path_list (const gchar *b
path = p->data;
name = g_module_build_path (path, base_name);
- load_module (name, method_name, args, method, transform);
+ load_module (name, method_name, args, method, transform, shutdown_function);
g_free (name);
if (*method != NULL || *transform != NULL)
@@ -312,6 +328,7 @@ gnome_vfs_add_module_to_hash_table (cons
{
GnomeVFSMethod *method = NULL;
GnomeVFSTransform *transform = NULL;
+ GnomeVFSMethodShutdownFunc shutdown_function = NULL;
ModuleElement *module_element;
const char *module_name;
#if defined (HAVE_SETEUID) || defined (HAVE_SETRESUID)
@@ -356,9 +373,9 @@ gnome_vfs_add_module_to_hash_table (cons
#endif
if (g_path_is_absolute (module_name))
- load_module (module_name, name, args, &method, &transform);
+ load_module (module_name, name, args, &method, &transform, &shutdown_function);
else
- load_module_in_path_list (module_name, name, args, &method, &transform);
+ load_module_in_path_list (module_name, name, args, &method, &transform, &shutdown_function);
#if defined(HAVE_SETEUID)
seteuid (saved_uid);
@@ -380,6 +397,7 @@ gnome_vfs_add_module_to_hash_table (cons
module_element->name = g_strdup (name);
module_element->method = method;
module_element->transform = transform;
+ module_element->shutdown_function = shutdown_function;
module_element->run_in_daemon = run_in_daemon;
g_hash_table_insert (module_hash, module_element->name, module_element);
@@ -426,4 +444,21 @@ gnome_vfs_transform_get (const gchar *na
module_element = gnome_vfs_add_module_to_hash_table (name);
return module_element ? module_element->transform : NULL;
+}
+
+void
+_gnome_vfs_method_shutdown (void)
+{
+ ModuleElement *module_element;
+
+ G_LOCK (gnome_vfs_method_init);
+
+ if (module_hash != NULL) {
+ g_hash_table_destroy (module_hash);
+ module_hash = NULL;
+ }
+
+ method_already_initialized = FALSE;
+
+ G_UNLOCK (gnome_vfs_method_init);
}
Index: libgnomevfs/gnome-vfs-method.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-method.h,v
retrieving revision 1.17
diff -u -p -r1.17 gnome-vfs-method.h
--- libgnomevfs/gnome-vfs-method.h 2 May 2005 13:44:34 -0000 1.17
+++ libgnomevfs/gnome-vfs-method.h 9 Apr 2006 12:20:40 -0000
@@ -274,6 +274,8 @@ gboolean gnome_vfs_method_init (voi
GnomeVFSMethod *gnome_vfs_method_get (const gchar *name);
GnomeVFSTransform *gnome_vfs_transform_get (const gchar *name);
+void _gnome_vfs_method_shutdown (void);
+
G_END_DECLS
#endif /* GNOME_VFS_METHOD_H */
Index: libgnomevfs/gnome-vfs-init.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-init.c,v
retrieving revision 1.39
diff -u -p -r1.39 gnome-vfs-init.c
--- libgnomevfs/gnome-vfs-init.c 2 Dec 2005 18:25:17 -0000 1.39
+++ libgnomevfs/gnome-vfs-init.c 9 Apr 2006 12:20:40 -0000
@@ -185,6 +185,8 @@ gnome_vfs_shutdown (void)
#endif
_gnome_vfs_client_shutdown ();
bonobo_debug_shutdown ();
+
+ _gnome_vfs_method_shutdown ();
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]