>From 64363af6bd4ee84e114a4846611abaedb32108c8 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Mon, 15 Apr 2013 19:10:40 +1000 Subject: [PATCH] Exit backends cleanly https://bugzilla.gnome.org/show_bug.cgi?id=511802 --- daemon/gvfsbackend.c | 39 +++++++++++++++++++++++++++++++++++++++ daemon/gvfsbackend.h | 1 + daemon/gvfsbackendcdda.c | 8 ++------ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/daemon/gvfsbackend.c b/daemon/gvfsbackend.c index 0c84c15..aabbb59 100644 --- a/daemon/gvfsbackend.c +++ b/daemon/gvfsbackend.c @@ -994,6 +994,45 @@ g_vfs_backend_unmount_with_operation (GVfsBackend *backend, } +static void +forced_unregister_mount_callback (GVfsDBusMountTracker *proxy, + GAsyncResult *res, + gpointer user_data) +{ + GVfsDaemon *daemon; + GVfsBackend *backend; + GError *error = NULL; + + g_return_if_fail (G_VFS_IS_BACKEND (user_data)); + + g_debug ("unregister_mount_callback\n"); + if (! gvfs_dbus_mount_tracker_call_unregister_mount_finish (proxy, + res, + &error)) + { + g_dbus_error_strip_remote_error (error); + g_warning ("Error unregistering mount: %s (%s, %d)\n", + error->message, g_quark_to_string (error->domain), error->code); + g_error_free (error); + } + + /* Unlink job source from daemon */ + backend = G_VFS_BACKEND (user_data); + daemon = g_vfs_backend_get_daemon (backend); + g_vfs_daemon_close_active_channels (daemon, backend); + g_vfs_job_source_closed (G_VFS_JOB_SOURCE (backend)); + +} + +void +g_vfs_backend_force_unmount (GVfsBackend *backend) +{ + g_vfs_backend_set_block_requests (backend); + g_vfs_backend_unregister_mount (backend, + (GAsyncReadyCallback) forced_unregister_mount_callback, + backend); +} + gboolean g_vfs_backend_has_blocking_processes (GVfsBackend *backend) { diff --git a/daemon/gvfsbackend.h b/daemon/gvfsbackend.h index e340cb9..ab7c2da 100644 --- a/daemon/gvfsbackend.h +++ b/daemon/gvfsbackend.h @@ -496,6 +496,7 @@ const char *g_vfs_backend_get_default_location (GVfsBackend *ba GMountSpec *g_vfs_backend_get_mount_spec (GVfsBackend *backend); GVfsDaemon *g_vfs_backend_get_daemon (GVfsBackend *backend); gboolean g_vfs_backend_is_mounted (GVfsBackend *backend); +void g_vfs_backend_force_unmount (GVfsBackend *backend); void g_vfs_backend_add_auto_info (GVfsBackend *backend, GFileAttributeMatcher *matcher, diff --git a/daemon/gvfsbackendcdda.c b/daemon/gvfsbackendcdda.c index a8213a8..0d56dbf 100644 --- a/daemon/gvfsbackendcdda.c +++ b/daemon/gvfsbackendcdda.c @@ -237,9 +237,7 @@ on_uevent (GUdevClient *client, gchar *action, GUdevDevice *device, gpointer use if (strcmp (action, "remove") == 0 || (strcmp (action, "change") == 0 && g_udev_device_get_property_as_int (device, "ID_CDROM_MEDIA") != 1)) { - /*g_warning ("we have been removed!");*/ - /* TODO: need a cleaner way to force unmount ourselves */ - exit (1); + g_vfs_backend_force_unmount (cdda_backend); } } @@ -292,9 +290,7 @@ _hal_device_removed (LibHalContext *hal_ctx, const char *udi) if (cdda_backend->hal_udi != NULL && strcmp (udi, cdda_backend->hal_udi) == 0) { - /*g_warning ("we have been removed!");*/ - /* TODO: need a cleaner way to force unmount ourselves */ - exit (1); + g_vfs_backend_force_unmount (cdda_backend); } } #endif -- 1.8.1.2