[gvfs/gnome-3-8] metadata: Flush all scheduled writeouts on daemon exit



commit 60f04600f58a7f4d1779f369f9cb97059fe18441
Author: Tomas Bzatek <tbzatek redhat com>
Date:   Mon May 13 17:43:40 2013 +0200

    metadata: Flush all scheduled writeouts on daemon exit
    
    This patch ensures that we safely write all data from journals to
    metatrees on exit. E.g. if anything happens to session bus or we get
    replaced by some other instance.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=637095
    (cherry picked from commit e793a0476feeaa0a3cc4f1fd043c15c297707455)

 metadata/meta-daemon.c |   46 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 40 insertions(+), 6 deletions(-)
---
diff --git a/metadata/meta-daemon.c b/metadata/meta-daemon.c
index f29e7f0..05e1630 100644
--- a/metadata/meta-daemon.c
+++ b/metadata/meta-daemon.c
@@ -79,6 +79,24 @@ tree_info_schedule_writeout (TreeInfo *info)
     }
 }
 
+static void
+flush_single (const gchar *filename,
+              TreeInfo *info,
+              gpointer user_data)
+{
+  if (info->writeout_timeout != 0)
+    {
+      g_source_remove (info->writeout_timeout);
+      writeout_timeout (info);
+    }
+}
+
+static void
+flush_all ()
+{
+  g_hash_table_foreach (tree_infos, (GHFunc) flush_single, NULL);
+}
+
 static TreeInfo *
 tree_info_new (const char *filename)
 {
@@ -433,9 +451,22 @@ on_name_lost (GDBusConnection *connection,
   GMainLoop *loop = user_data;
 
   /* means that someone has claimed our name (we allow replacement) */
+  flush_all ();
   g_main_loop_quit (loop);
 }
 
+static void
+on_connection_closed (GDBusConnection *connection,
+                      gboolean         remote_peer_vanished,
+                      GError          *error,
+                      gpointer         user_data)
+{
+  GMainLoop *loop = user_data;
+
+  /* session bus died */
+  flush_all ();
+  g_main_loop_quit (loop);
+}
 
 int
 main (int argc, char *argv[])
@@ -496,7 +527,15 @@ main (int argc, char *argv[])
       g_error_free (error);
       return 1;
     }
-  
+
+  tree_infos = g_hash_table_new_full (g_str_hash,
+                                     g_str_equal,
+                                     NULL,
+                                     (GDestroyNotify)tree_info_free);
+
+  g_dbus_connection_set_exit_on_close (conn, FALSE);
+  g_signal_connect (conn, "closed", G_CALLBACK (on_connection_closed), loop);
+
   flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
   if (replace)
     flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;
@@ -509,11 +548,6 @@ main (int argc, char *argv[])
                                                 loop,
                                                 NULL);
   
-  tree_infos = g_hash_table_new_full (g_str_hash,
-                                     g_str_equal,
-                                     NULL,
-                                     (GDestroyNotify)tree_info_free);
-
   g_main_loop_run (loop);
   
   if (skeleton)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]