summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-12-01 21:56:25 -0500
committerRyan Lortie <desrt@desrt.ca>2014-01-13 16:23:30 -0500
commit690821a22313982497f41b25940fa58a1c33e91b (patch)
tree93614ac7fbd922aa016da224b260463a6db3675d /engine
parent67f739bda92bd3c0fd512ff3a4a663ae8e160b9e (diff)
downloaddconf-690821a22313982497f41b25940fa58a1c33e91b.tar.gz
engine: add support for 'file-db'
This is a new database type that is simply an absolute path to a gvdb anywhere on the filesystem. Change notification is not supported. This is intended to be used by things like gdm that wish to install databases (somewhere in /usr) as part of the software.
Diffstat (limited to 'engine')
-rw-r--r--engine/Makefile.am1
-rw-r--r--engine/dconf-engine-profile.c14
-rw-r--r--engine/dconf-engine-source-file.c79
-rw-r--r--engine/dconf-engine-source-private.h1
-rw-r--r--engine/dconf-engine-source.c4
5 files changed, 92 insertions, 7 deletions
diff --git a/engine/Makefile.am b/engine/Makefile.am
index 5266f27..0f200d5 100644
--- a/engine/Makefile.am
+++ b/engine/Makefile.am
@@ -8,6 +8,7 @@ libdconf_engine_a_SOURCES = \
dconf-engine-profile.c \
dconf-engine-source-private.h \
dconf-engine-source.h \
+ dconf-engine-source-file.c \
dconf-engine-source-user.c \
dconf-engine-source-service.c \
dconf-engine-source-system.c \
diff --git a/engine/dconf-engine-profile.c b/engine/dconf-engine-profile.c
index 6f2208d..1fbafc3 100644
--- a/engine/dconf-engine-profile.c
+++ b/engine/dconf-engine-profile.c
@@ -69,14 +69,14 @@
* Once a profile file is opened, each line is treated as a possible
* source. Comments and empty lines are ignored.
*
- * All valid source specification lines need to start with 'user-db:' or
- * 'system-db:'. If a line doesn't start with one of these then it gets
- * ignored. If all the lines in the file get ignored then the result is
- * effectively the null profile.
+ * All valid source specification lines need to start with 'user-db:',
+ * 'system-db:', 'service-db:' or 'file-db:'. If a line doesn't start
+ * with one of these then it gets ignored. If all the lines in the file
+ * get ignored then the result is effectively the null profile.
*
- * If the first source is a "user-db:" then the resulting profile will
- * be writable. No profile starting with a "system-db:" source can ever
- * be writable.
+ * If the first source is a "user-db:" or "service-db:" then the
+ * resulting profile will be writable. No profile starting with a
+ * "system-db:" or "file-db:" source can ever be writable.
*
* Note: even if the source fails to initialise (due to a missing file,
* for example) it will remain in the source list. This could have a
diff --git a/engine/dconf-engine-source-file.c b/engine/dconf-engine-source-file.c
new file mode 100644
index 0000000..6c24f9c
--- /dev/null
+++ b/engine/dconf-engine-source-file.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ * Copyright © 2012 Canonical Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt@desrt.ca>
+ */
+
+#include "config.h"
+
+#include "dconf-engine-source-private.h"
+
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static void
+dconf_engine_source_file_init (DConfEngineSource *source)
+{
+ source->bus_type = G_BUS_TYPE_NONE;
+ source->bus_name = NULL;
+ source->object_path = NULL;
+}
+
+static gboolean
+dconf_engine_source_file_needs_reopen (DConfEngineSource *source)
+{
+ return !source->values;
+}
+
+static GvdbTable *
+dconf_engine_source_file_reopen (DConfEngineSource *source)
+{
+ GError *error = NULL;
+ GvdbTable *table;
+
+ table = gvdb_table_new (source->name, FALSE, &error);
+
+ if (table == NULL)
+ {
+ if (!source->did_warn)
+ {
+ g_warning ("unable to open file '%s': %s; expect degraded performance", source->name, error->message);
+ source->did_warn = TRUE;
+ }
+
+ g_error_free (error);
+ }
+
+ return table;
+}
+
+static void
+dconf_engine_source_file_finalize (DConfEngineSource *source)
+{
+}
+
+G_GNUC_INTERNAL
+const DConfEngineSourceVTable dconf_engine_source_file_vtable = {
+ .instance_size = sizeof (DConfEngineSource),
+ .init = dconf_engine_source_file_init,
+ .finalize = dconf_engine_source_file_finalize,
+ .needs_reopen = dconf_engine_source_file_needs_reopen,
+ .reopen = dconf_engine_source_file_reopen
+};
diff --git a/engine/dconf-engine-source-private.h b/engine/dconf-engine-source-private.h
index e0b943d..d209d28 100644
--- a/engine/dconf-engine-source-private.h
+++ b/engine/dconf-engine-source-private.h
@@ -25,6 +25,7 @@
#include "dconf-engine-source.h"
+G_GNUC_INTERNAL extern const DConfEngineSourceVTable dconf_engine_source_file_vtable;
G_GNUC_INTERNAL extern const DConfEngineSourceVTable dconf_engine_source_user_vtable;
G_GNUC_INTERNAL extern const DConfEngineSourceVTable dconf_engine_source_service_vtable;
G_GNUC_INTERNAL extern const DConfEngineSourceVTable dconf_engine_source_system_vtable;
diff --git a/engine/dconf-engine-source.c b/engine/dconf-engine-source.c
index 9a34a01..e6701f4 100644
--- a/engine/dconf-engine-source.c
+++ b/engine/dconf-engine-source.c
@@ -106,6 +106,10 @@ dconf_engine_source_new (const gchar *description)
else if ((colon == description + 9) && memcmp (description, "system-db", 9) == 0)
vtable = &dconf_engine_source_system_vtable;
+ /* ...or "file-db" */
+ else if ((colon == description + 7) && memcmp (description, "file-db", 7) == 0)
+ vtable = &dconf_engine_source_file_vtable;
+
/* If it's not any of those, we have failed. */
else
return NULL;