diff --git a/client/Makefile.am b/client/Makefile.am
index b53163e..8f9cc53 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -26,6 +26,7 @@ libdconf_so_0_0_0_LDFLAGS = -shared -Wl,-soname=libdconf.so.0
 libdconf_so_0_0_0_SOURCES = \
 	../common/dconf-shmdir.c	\
 	../common/dconf-paths.c		\
+	../common/dconf-fs.c		\
 	../engine/dconf-engine.c	\
 	../gvdb/gvdb-reader.c		\
 	dconf-client.vala engine.vapi
diff --git a/common/Makefile.am b/common/Makefile.am
index 0238cd1..54b00e4 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -4,4 +4,5 @@ dconfinclude_HEADERS = \
 EXTRA_DIST = \
 	dconf-shmdir.h	\
 	dconf-paths.h	\
-	dconf-paths.c
+	dconf-paths.c	\
+	dconf-fs.h
diff --git a/dbus-1/Makefile.am b/dbus-1/Makefile.am
index 6e740f1..aa406ed 100644
--- a/dbus-1/Makefile.am
+++ b/dbus-1/Makefile.am
@@ -13,6 +13,7 @@ shlib_PROGRAMS = libdconf-dbus-1.so.0.0.0
 libdconf_dbus_1_so_0_0_0_LDADD = $(glib_LIBS) $(dbus_LIBS)
 libdconf_dbus_1_so_0_0_0_LDFLAGS = -shared -Wl,-soname=libdconf-dbus-1.so.0
 libdconf_dbus_1_so_0_0_0_SOURCES = \
+	../common/dconf-fs.c		\
 	../engine/dconf-engine.c	\
 	../common/dconf-shmdir.c	\
 	../gvdb/gvdb-reader.c		\
diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c
index 58856c3..bdc2255 100644
--- a/engine/dconf-engine.c
+++ b/engine/dconf-engine.c
@@ -21,6 +21,7 @@
 
 #define _XOPEN_SOURCE 600
 #include "dconf-shmdir.h"
+#include "dconf-fs.h"
 #include "dconf-engine.h"
 #include <gvdb-reader.h>
 #include <string.h>
@@ -84,66 +85,90 @@ struct _DConfEngine
   gchar      *bus_types;
   gchar     **names;
   gint        n_dbs;
+  gboolean    user_db_on_nfs;
 };
 
 static void
 dconf_engine_setup_user (DConfEngine *engine)
 {
-  /* invariant: we never have user gvdb without shm */
-  g_assert ((engine->gvdbs[0] == NULL) >= (engine->shm == NULL));
+  /* invariant: we never have user gvdb without shm on non NFS filesystem */
+  g_assert (engine->user_db_on_nfs ||
+            (engine->gvdbs[0] == NULL) >= (engine->shm == NULL));
 
   if (engine->names[0])
     {
-      const gchar *session_dir = dconf_engine_get_session_dir ();
+      gchar *db_filename;
 
-      if (session_dir)
-        {
-          gchar *filename;
-          gint fd;
+      db_filename = g_build_filename (g_get_user_config_dir (),
+                                      "dconf",
+                                      engine->names[0],
+                                      NULL);
 
-          filename = g_build_filename (session_dir,
-                                       engine->names[0],
-                                       NULL);
-          fd = open (filename, O_RDWR | O_CREAT, 0600);
-          g_free (filename);
+      engine->user_db_on_nfs = dconf_is_on_nfs (db_filename);
+
+      if (!engine->user_db_on_nfs)
+        {
+          const gchar *session_dir = dconf_engine_get_session_dir ();
 
-          if (fd >= 0)
+          if (session_dir)
             {
-              if (ftruncate (fd, 1) == 0)
+              gchar *filename;
+              gint fd;
+
+              filename = g_build_filename (session_dir,
+                                           engine->names[0],
+                                           NULL);
+              fd = open (filename, O_RDWR | O_CREAT, 0600);
+              g_free (filename);
+
+              if (fd >= 0)
                 {
-                  engine->shm = mmap (NULL, 1, PROT_READ, MAP_SHARED, fd, 0);
+                  if (ftruncate (fd, 1) == 0)
+                    {
+                      engine->shm = mmap (NULL, 1, PROT_READ, MAP_SHARED, fd, 0);
+
+                      if (engine->shm == MAP_FAILED)
+                        engine->shm = NULL;
+                    }
 
-                  if (engine->shm == MAP_FAILED)
-                    engine->shm = NULL;
+                  close (fd);
                 }
+            }
 
-              close (fd);
+          if (engine->shm)
+            {
+              engine->gvdbs[0] = gvdb_table_new (db_filename, FALSE, NULL);
             }
-        }
 
-      if (engine->shm)
+        }
+      else
         {
-          gchar *filename;
+          gchar *rt_filename;
 
-          filename = g_build_filename (g_get_user_config_dir (),
-                                       "dconf",
-                                       engine->names[0],
-                                       NULL);
-          engine->gvdbs[0] = gvdb_table_new (filename, FALSE, NULL);
-          g_free (filename);
+          rt_filename = g_build_filename (g_get_user_runtime_dir (),
+                                          "dconf",
+                                          "local",
+                                          engine->names[0],
+                                          NULL);
+          engine->gvdbs[0] = gvdb_table_new (rt_filename, FALSE, NULL);
+
+          g_free (rt_filename);
         }
+
+      g_free (db_filename);
     }
 
-  g_assert ((engine->gvdbs[0] == NULL) >= (engine->shm == NULL));
+  g_assert (engine->user_db_on_nfs
+            || (engine->gvdbs[0] == NULL) >= (engine->shm == NULL));
 }
 
 static void
 dconf_engine_refresh_user (DConfEngine *engine)
 {
-  g_assert ((engine->gvdbs[0] == NULL) >= (engine->shm == NULL));
+  g_assert (engine->user_db_on_nfs ||
+            (engine->gvdbs[0] == NULL) >= (engine->shm == NULL));
 
-  /* if we failed the first time, fail forever */
-  if (engine->shm && *engine->shm == 1)
+  if (engine->user_db_on_nfs)
     {
       if (engine->gvdbs[0])
         {
@@ -151,14 +176,30 @@ dconf_engine_refresh_user (DConfEngine *engine)
           engine->gvdbs[0] = NULL;
         }
 
-      munmap (engine->shm, 1);
-      engine->shm = NULL;
-
       dconf_engine_setup_user (engine);
       engine->state++;
     }
+  else
+    {
+      /* if we failed the first time, fail forever */
+      if (engine->shm && *engine->shm == 1)
+        {
+          if (engine->gvdbs[0])
+            {
+              gvdb_table_unref (engine->gvdbs[0]);
+              engine->gvdbs[0] = NULL;
+            }
+
+          munmap (engine->shm, 1);
+          engine->shm = NULL;
+
+          dconf_engine_setup_user (engine);
+          engine->state++;
+        }
+    }
 
-  g_assert ((engine->gvdbs[0] == NULL) >= (engine->shm == NULL));
+  g_assert (engine->user_db_on_nfs ||
+            (engine->gvdbs[0] == NULL) >= (engine->shm == NULL));
 }
 
 static void
@@ -282,6 +323,7 @@ dconf_engine_new (const gchar *profile)
   engine = g_slice_new (DConfEngine);
   g_mutex_init (&engine->lock);
   engine->shm = NULL;
+  engine->user_db_on_nfs = FALSE;
 
   if (profile == NULL)
     profile = getenv ("DCONF_PROFILE");
diff --git a/gsettings/Makefile.am b/gsettings/Makefile.am
index ace7da0..a265814 100644
--- a/gsettings/Makefile.am
+++ b/gsettings/Makefile.am
@@ -6,6 +6,7 @@ giomodules_PROGRAMS = libdconfsettings.so
 libdconfsettings_so_LDADD = $(gio_LIBS)
 libdconfsettings_so_LDFLAGS = -shared
 libdconfsettings_so_SOURCES = \
+	../common/dconf-fs.c		\
 	../engine/dconf-engine.c	\
 	../common/dconf-shmdir.c	\
 	../gvdb/gvdb-reader.c		\
diff --git a/service/Makefile.am b/service/Makefile.am
index d3eddf7..60134b0 100644
--- a/service/Makefile.am
+++ b/service/Makefile.am
@@ -9,6 +9,7 @@ dconf_service_SOURCES = \
 	../gvdb/gvdb-builder.c		\
 	../gvdb/gvdb-reader.c		\
 	../common/dconf-shmdir.c	\
+	../common/dconf-fs.c		\
 	dconf-interfaces.h		\
 	dconf-interfaces.c		\
 	dconf-rebuilder.h		\
diff --git a/service/dconf-state.c b/service/dconf-state.c
index 0ed156e..6b3bc34 100644
--- a/service/dconf-state.c
+++ b/service/dconf-state.c
@@ -1,6 +1,7 @@
 #include "dconf-state.h"
 
 #include "dconf-shmdir.h"
+#include "dconf-fs.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -11,15 +12,20 @@ static void
 dconf_state_init_session (DConfState *state)
 {
   const gchar *config_dir = g_get_user_config_dir ();
+  const gchar *runtime_dir = g_get_user_runtime_dir ();
+  gchar *db_filename;
 
   state->db_dir = g_build_filename (config_dir, "dconf", NULL);
+  state->db_runtime_dir = NULL;
+
+  db_filename = g_build_filename (state->db_dir, "user", NULL);
 
   if (g_mkdir_with_parents (state->db_dir, 0700))
     {
       /* XXX remove this after a while... */
       if (errno == ENOTDIR)
         {
-          gchar *tmp, *final;
+          gchar *tmp;
 
           g_message ("Attempting to migrate ~/.config/dconf "
                      "to ~/.config/dconf/user");
@@ -34,15 +40,12 @@ dconf_state_init_session (DConfState *state)
             g_error ("Can not create directory '%s': %s",
                      state->db_dir, g_strerror (errno));
 
-          final = g_build_filename (state->db_dir, "user", NULL);
-
-          if (rename (tmp, final))
+          if (rename (tmp, db_filename))
             g_error ("Can not rename '%s' to '%s': %s",
-                     tmp, final, g_strerror (errno));
+                     tmp, db_filename, g_strerror (errno));
 
           g_message ("Successful.");
 
-          g_free (final);
           g_free (tmp);
         }
       else
@@ -62,6 +65,18 @@ dconf_state_init_session (DConfState *state)
       if ((state->shm_dir = mkdtemp (shmdir)) == NULL)
         g_error ("Can not create reasonable shm directory");
     }
+
+  if (dconf_is_on_nfs (db_filename))
+    {
+      state->db_runtime_dir = g_build_filename (runtime_dir,
+                                                "dconf", "local", NULL);
+
+      if (g_mkdir_with_parents (state->db_runtime_dir, 0700))
+        g_error ("Can not create directory '%s': %s",
+                 state->db_runtime_dir, g_strerror (errno));
+    }
+
+  g_free (db_filename);
 }
 
 void
diff --git a/service/dconf-state.h b/service/dconf-state.h
index 8bbe612..ab75a91 100644
--- a/service/dconf-state.h
+++ b/service/dconf-state.h
@@ -9,6 +9,7 @@ typedef struct
   GMainLoop *main_loop;
   guint64 serial;
   gchar *db_dir;
+  gchar *db_runtime_dir;
   gchar *shm_dir;
   gchar *id;
 } DConfState;
diff --git a/service/dconf-writer.c b/service/dconf-writer.c
index 3f2aeee..9ceeeae 100644
--- a/service/dconf-writer.c
+++ b/service/dconf-writer.c
@@ -23,19 +23,25 @@
 
 #include "dconf-rebuilder.h"
 #include "dconf-state.h"
+#include "dconf-fs.h"
 
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <stdio.h>
+#include <fcntl.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
 
 struct OPAQUE_TYPE__DConfWriter
 {
   DConfState *state;
   gchar *name;
   gchar *path;
+  gchar *runtime_path;
   gchar *shm;
+  gboolean on_nfs;
 };
 
 /* Each element must only contain the ASCII characters "[A-Z][a-z][0-9]_"
@@ -103,10 +109,13 @@ dconf_writer_write (DConfWriter  *writer,
                     GVariant     *value,
                     GError      **error)
 {
-  if (!dconf_rebuilder_rebuild (writer->path, "", &name, &value, 1, error))
+  if (!dconf_rebuilder_rebuild (writer->path, "", &name, &value, 1, error) ||
+      (writer->on_nfs && !dconf_rebuilder_rebuild (writer->runtime_path, "",
+                                                   &name, &value, 1, error)))
     return FALSE;
 
-  dconf_writer_touch_shm (writer);
+  if (!writer->on_nfs)
+    dconf_writer_touch_shm (writer);
 
   return TRUE;
 }
@@ -120,10 +129,13 @@ dconf_writer_write_many (DConfWriter          *writer,
                          GError              **error)
 {
   if (!dconf_rebuilder_rebuild (writer->path, prefix, keys,
-                                values, n_items, error))
+                                values, n_items, error) ||
+      (writer->on_nfs && !dconf_rebuilder_rebuild (writer->path, prefix, keys,
+                                                   values, n_items, error)))
     return FALSE;
 
-  dconf_writer_touch_shm (writer);
+  if (!writer->on_nfs)
+    dconf_writer_touch_shm (writer);
 
   return TRUE;
 }
@@ -151,6 +163,13 @@ dconf_writer_new (DConfState  *state,
   writer->path = g_build_filename (state->db_dir, name, NULL);
   writer->shm = g_build_filename (state->shm_dir, name, NULL);
   writer->name = g_strdup (name);
+  writer->on_nfs = dconf_is_on_nfs (writer->path);
+
+  if (writer->on_nfs)
+    writer->runtime_path = g_build_filename (state->db_runtime_dir,
+                                             name, NULL);
+  else
+    writer->runtime_path = NULL;
 
   return writer;
 }
diff --git a/service/service.c b/service/service.c
index b2ab1cf..69a0980 100644
--- a/service/service.c
+++ b/service/service.c
@@ -24,10 +24,32 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <glib/gstdio.h>
 
 #include "dconf-interfaces.h"
 #include "dconf-writer.h"
 #include "dconf-state.h"
+#include "dconf-fs.h"
+
+#define DB_CHECK_TIMEOUT 60000
+
+typedef struct
+{
+  GDBusConnection  *connection;
+  time_t           *mtimes;
+  gchar            *config_dir;
+  gchar            *runtime_dir;
+  gchar           **names;
+  guint             num_of_dbs;
+  guint             timeout_id;
+} DConfTimeoutData;
+
+DConfTimeoutData *timeout_data = NULL;
+
+static gboolean database_copy   (const gchar *src_db_filename,
+                                 const gchar *dest_db_filename);
+static int      database_lock   (const gchar *filename);
+static void     database_unlock (int          lock_fd);
 
 static void
 emit_notify_signal (GDBusConnection  *connection,
@@ -139,6 +161,76 @@ unwrap_maybe (GVariant **ptr)
   *ptr = child;
 }
 
+/*
+ * Synchronize local copy of user database
+ * in runtime directory with user database in
+ * user config directory if needed.
+ * Return TRUE if there was a change.
+ */
+static gboolean
+synchronize_db (const gchar *name)
+{
+  gboolean  changed = FALSE;
+  GStatBuf  buf;
+  time_t    mtime = 0;
+  gchar    *remote_file;
+  gchar    *local_file;
+  guint     i;
+
+  for (i = 0; i < timeout_data->num_of_dbs; i++)
+    {
+      if (g_str_equal (name, timeout_data->names[i]))
+        {
+          remote_file = g_build_filename (timeout_data->config_dir,
+                                          timeout_data->names[i], NULL);
+
+          if (g_stat (remote_file, &buf) == 0)
+            mtime = buf.st_mtime;
+
+          if (mtime > timeout_data->mtimes[i])
+            {
+              local_file = g_build_filename (timeout_data->runtime_dir,
+                                             timeout_data->names[i], NULL);
+
+              if (database_copy (remote_file, local_file))
+                {
+                  timeout_data->mtimes[i] = mtime;
+                  changed = TRUE;
+                }
+
+              g_free (local_file);
+            }
+
+          g_free (remote_file);
+        }
+    }
+
+  return changed;
+}
+
+static void
+synchronize_db_mtime (const gchar *name)
+{
+  GStatBuf  buf;
+  gchar    *remote_file;
+  guint     i;
+
+  for (i = 0; i < timeout_data->num_of_dbs; i++)
+    {
+      if (g_str_equal (name, timeout_data->names[i]))
+        {
+          remote_file = g_build_filename (timeout_data->config_dir,
+                                          timeout_data->names[i], NULL);
+
+          if (g_stat (remote_file, &buf) == 0 &&
+              buf.st_mtime != timeout_data->mtimes[i])
+            timeout_data->mtimes[i] = buf.st_mtime;
+
+          g_free (remote_file);
+        }
+    }
+}
+
 static void
 method_call (GDBusConnection       *connection,
              const gchar           *sender,
@@ -151,6 +243,8 @@ method_call (GDBusConnection       *connection,
 {
   DConfWriter *writer = user_data;
   DConfState *state;
+  gchar *db_filename;
+  int lock_fd;
 
   state = dconf_writer_get_state (writer);
 
@@ -191,6 +285,14 @@ method_call (GDBusConnection       *connection,
           return;
         }
 
+      db_filename = g_build_filename (timeout_data->config_dir,
+                                      dconf_writer_get_name (writer),
+                                      NULL);
+      lock_fd = database_lock (db_filename);
+      g_free (db_filename);
+
+      synchronize_db (dconf_writer_get_name (writer));
+
       if (!dconf_writer_write (writer, key, value, &error))
         {
           g_dbus_method_invocation_return_gerror (invocation, error);
@@ -200,6 +302,10 @@ method_call (GDBusConnection       *connection,
           return;
         }
 
+      synchronize_db_mtime (dconf_writer_get_name (writer));
+
+      database_unlock (lock_fd);
+
       tag = dconf_state_get_tag (state);
       g_dbus_method_invocation_return_value (invocation,
                                              g_variant_new ("(s)", tag));
@@ -260,6 +366,14 @@ method_call (GDBusConnection       *connection,
       g_variant_iter_free (iter);
       keys[i] = NULL;
 
+      db_filename = g_build_filename (timeout_data->config_dir,
+                                      dconf_writer_get_name (writer),
+                                      NULL);
+      lock_fd = database_lock (db_filename);
+      g_free (db_filename);
+
+      synchronize_db (dconf_writer_get_name (writer));
+
       if (!dconf_writer_write_many (writer, prefix, keys, values, i, &error))
         {
           g_dbus_method_invocation_return_gerror (invocation, error);
@@ -267,6 +381,10 @@ method_call (GDBusConnection       *connection,
           return;
         }
 
+      synchronize_db_mtime (dconf_writer_get_name (writer));
+
+      database_unlock (lock_fd);
+
       tag = dconf_state_get_tag (state);
       g_dbus_method_invocation_return_value (invocation,
                                              g_variant_new ("(s)", tag));
@@ -386,6 +504,59 @@ subtree_introspect (GDBusConnection *connection,
     }
 }
 
+static gboolean
+check_db_changes ()
+{
+  gboolean  changed;
+  GStatBuf  buf;
+  gchar    *remote_file;
+  gchar    *local_file;
+  gint      i;
+
+  for (i = 0; i < timeout_data->num_of_dbs; i++)
+    {
+      changed = FALSE;
+      remote_file = g_build_filename (timeout_data->config_dir,
+                                      timeout_data->names[i], NULL);
+
+      if (timeout_data->mtimes[i] != 0 &&
+          g_stat (remote_file, &buf) == 0 &&
+          buf.st_mtime > timeout_data->mtimes[i])
+        changed = TRUE;
+
+      if (changed)
+        {
+          GVariant *none;
+          gchar    *path;
+
+          none = g_variant_new_array (G_VARIANT_TYPE_STRING, NULL, 0);
+
+          local_file = g_build_filename (timeout_data->runtime_dir,
+                                         timeout_data->names[i],
+                                         NULL);
+
+          if (database_copy (remote_file, local_file))
+            timeout_data->mtimes[i] = buf.st_mtime;
+          g_free (local_file);
+
+          path = g_strjoin (NULL, "/ca/desrt/dconf/Writer/",
+                            timeout_data->names[i], NULL);
+          g_dbus_connection_emit_signal (timeout_data->connection, NULL,
+                                         path,
+                                         "ca.desrt.dconf.Writer", "Notify",
+                                         g_variant_new ("(s@ass)",
+                                                        "/", none, ""),
+                                         NULL);
+
+          g_free (path);
+        }
+
+      g_free (remote_file);
+    }
+
+  return TRUE;
+}
+
 static void
 bus_acquired (GDBusConnection *connection,
               const gchar     *name,
@@ -396,12 +567,71 @@ bus_acquired (GDBusConnection *connection,
   };
   DConfState *state = user_data;
   GDBusSubtreeFlags flags;
+  gchar **existing;
+  guint i;
 
   dconf_state_set_id (state, g_dbus_connection_get_unique_name (connection));
 
   flags = G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES;
   g_dbus_connection_register_subtree (connection, "/ca/desrt/dconf/Writer",
                                       &vtable, flags, state, NULL, NULL);
+
+  existing = dconf_writer_list_existing ();
+
+  if (g_strv_length (existing) > 0)
+    {
+      gchar *filename = g_build_filename (g_get_user_config_dir (),
+                                          "dconf",
+                                          existing[0],
+                                          NULL);
+
+      if (dconf_is_on_nfs (filename))
+        {
+          GStatBuf buf;
+          gint     lock_fd;
+
+          timeout_data = g_new0 (DConfTimeoutData, 1);
+          timeout_data->num_of_dbs = g_strv_length (existing);
+          timeout_data->names = g_strdupv (existing);
+          timeout_data->mtimes = g_new0 (time_t, timeout_data->num_of_dbs);
+          timeout_data->config_dir = g_build_filename (g_get_user_config_dir (),
+                                                       "dconf", NULL);
+          timeout_data->runtime_dir = g_build_filename (g_get_user_runtime_dir (),
+                                                        "dconf", "local", NULL);
+          timeout_data->connection = connection;
+
+          for (i = 0; i < timeout_data->num_of_dbs; i++)
+            {
+              gchar *remote_file;
+              gchar *local_file;
+
+              remote_file = g_build_filename (timeout_data->config_dir,
+                                              timeout_data->names[i],
+                                              NULL);
+              local_file = g_build_filename (timeout_data->runtime_dir,
+                                             timeout_data->names[i],
+                                             NULL);
+
+              lock_fd = database_lock (remote_file);
+
+              if (database_copy (remote_file, local_file) &&
+                  g_stat (remote_file, &buf) == 0)
+                timeout_data->mtimes[i] = buf.st_mtime;
+
+              database_unlock (lock_fd);
+
+              g_free (local_file);
+              g_free (remote_file);
+            }
+
+          timeout_data->timeout_id = g_timeout_add (DB_CHECK_TIMEOUT,
+                                                    check_db_changes, NULL);
+        }
+
+      g_free (filename);
+    }
+
+  g_strfreev (existing);
 }
 
 static void
@@ -430,6 +660,84 @@ exit_service (gpointer data)
   return TRUE;
 }
 
+static gboolean
+database_copy (const gchar *src_db_filename,
+               const gchar *dest_db_filename)
+{
+  gboolean  result;
+  GError   *error = NULL;
+  GFile    *destination;
+  GFile    *source;
+
+  source = g_file_new_for_path (src_db_filename);
+  destination = g_file_new_for_path (dest_db_filename);
+
+  result = g_file_copy (source,
+                        destination,
+                        G_FILE_COPY_OVERWRITE,
+                        NULL, NULL, NULL, &error);
+
+  if (!result)
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+    }
+
+  return result;
+}
+
+/*
+ * Creates lock file for given filename.
+ * Returns file descriptor of the lock file.
+ */
+static int
+database_lock (const gchar *filename)
+{
+  struct flock  lock;
+  int           lock_fd = -1;
+  gchar        *lock_filename;
+
+  lock_filename = g_strdup_printf ("%s-lock", filename);
+
+  if ((lock_fd = open (lock_filename,
+                       O_CREAT | O_WRONLY | O_SYNC,
+                       S_IRUSR | S_IWUSR)) != -1)
+    {
+      lock.l_whence = SEEK_SET;
+      lock.l_start = 0;
+      lock.l_len = 0;
+      lock.l_type = F_WRLCK;
+
+      /* Create a lock on the file 'filename' */
+      if (fcntl (lock_fd, F_SETLKW, &lock) == -1)
+        {
+          g_warning ("Can not get lock on '%s': %s",
+                     lock_filename,
+                     g_strerror (errno));
+        }
+    }
+  else
+    {
+      g_warning ("Can not open '%s': %s",
+                 lock_filename,
+                 g_strerror (errno));
+    }
+
+  g_free (lock_filename);
+
+  return lock_fd;
+}
+
+/*
+ * Closes given lock file.
+ */
+static void
+database_unlock (int lock_fd)
+{
+  if (lock_fd != -1)
+    close (lock_fd);
+}
+
 int
 main (void)
 {
@@ -456,5 +764,17 @@ main (void)
 
   dconf_state_destroy (&state);
 
+  if (timeout_data)
+    {
+      if (timeout_data->timeout_id)
+        g_source_remove (timeout_data->timeout_id);
+      if (timeout_data->names)
+        g_strfreev (timeout_data->names);
+      g_free (timeout_data->config_dir);
+      g_free (timeout_data->runtime_dir);
+      g_free (timeout_data->mtimes);
+      g_free (timeout_data);
+    }
+
   return 0;
 }
