+general captive shutdown
[captive.git] / src / client / libcaptive-gnomevfs / gnome-vfs-module.c
index ebb6e1b..64d54cb 100644 (file)
@@ -22,6 +22,7 @@
 #include "gnome-vfs-method.h"
 #include <libgnomevfs/gnome-vfs-module.h>
 #include <glib/gmessages.h>
+#include <glib/gutils.h>       /* for g_atexit() */
 
 
 /* Are we initialized? */
@@ -31,6 +32,9 @@ static gboolean active;
 G_LOCK_DEFINE(libcaptive);
 
 
+static void vfs_module_shutdown_atexit(void);
+
+
 /**
  * vfs_module_init:
  * @method_name: FIXME
@@ -52,19 +56,30 @@ GnomeVFSMethod *captive_gnomevfs_method_ptr;
        captive_gnomevfs_method_ptr=captive_gnomevfs_method_init(
                        args);  /* captive_args */
 
+       g_atexit(vfs_module_shutdown_atexit);
+
        active=TRUE;
        return captive_gnomevfs_method_ptr;
 }
 
+
 /**
  * vfs_module_shutdown:
- * @method:
  */
 void vfs_module_shutdown(GnomeVFSMethod *method)
 {
-       g_return_if_fail(method!=NULL);
+       /* 'method' may be NULL iff we are called from vfs_module_shutdown_atexit() */
 
        g_return_if_fail(active==TRUE);
 
+       captive_gnomevfs_method_shutdown();
+
        active=FALSE;
 }
+
+
+static void vfs_module_shutdown_atexit(void)
+{
+       if (active)
+               vfs_module_shutdown(NULL);
+}