summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2012-07-08 14:41:33 -0400
committerRyan Lortie <desrt@desrt.ca>2012-07-08 14:52:03 -0400
commitdd9c1a0cad35082724bba59235af031246c06ce5 (patch)
treed87fae1e6ce41e19ca1b8506424c1801faf8cc7a /service
parent4228ef3194fff11dcdcdce0b61aa0474fffb066d (diff)
downloaddconf-dd9c1a0cad35082724bba59235af031246c06ce5.tar.gz
clean up and factor out the 'shm' code
Remove the shm code from the engine and the service and put it in a separate convenience library in shm/. Remove the vestigial shmdir weirdness from the service (since shmdir is now always relative to XDG_RUNTIME_DIR and has been for some time). The purpose of this is so that dconf-engine can be properly unit-tested. dconf-engine now has five points of contact with the world (excluding the users of the engine themselves): - the DCONF_PROFILE environment variable - fopen() of profile files - shm - gvdb - dbus The environment variable is quite easily controlled. fopen() is intercepted in the engine testcase with a interpose of the libc symbol. With this commit now each of dbus, gvdb and shm are implemented in separate utility modules that can be mocked from the testcases.
Diffstat (limited to 'service')
-rw-r--r--service/Makefile.am4
-rw-r--r--service/dconf-interfaces.c10
-rw-r--r--service/dconf-state.c15
-rw-r--r--service/dconf-state.h1
-rw-r--r--service/dconf-writer.c29
-rw-r--r--service/service.c20
6 files changed, 8 insertions, 71 deletions
diff --git a/service/Makefile.am b/service/Makefile.am
index eed852a..96ad94e 100644
--- a/service/Makefile.am
+++ b/service/Makefile.am
@@ -1,12 +1,12 @@
include $(top_srcdir)/Makefile.gtester
-AM_CFLAGS = $(gio_CFLAGS) -I$(top_srcdir)/gvdb -I$(top_srcdir)/common -Wall -Wmissing-prototypes -Wwrite-strings
+AM_CFLAGS = $(gio_CFLAGS) -I$(top_srcdir)/gvdb -I$(top_srcdir)/common -I$(top_srcdir)/shm -Wall -Wmissing-prototypes -Wwrite-strings
libexec_PROGRAMS = dconf-service
dbusservice_DATA = ca.desrt.dconf.service
-dconf_service_LDADD = $(gio_LIBS) ../common/libdconf-common.a
+dconf_service_LDADD = $(gio_LIBS) ../common/libdconf-common.a ../shm/libdconf-shm.a
dconf_service_SOURCES = \
../gvdb/gvdb-builder.c \
../gvdb/gvdb-reader.c \
diff --git a/service/dconf-interfaces.c b/service/dconf-interfaces.c
index e824aca..45c6593 100644
--- a/service/dconf-interfaces.c
+++ b/service/dconf-interfaces.c
@@ -67,10 +67,6 @@ static const GDBusMethodInfo blame_method = {
(GDBusArgInfo **) blame_out
};
-static const GDBusPropertyInfo shmdir_property = {
- -1, (gchar *) "ShmDirectory", (gchar *) "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE
-};
-
static const GDBusMethodInfo *writer_methods[] = {
&change_method, &write_method, &writemany_method, NULL
};
@@ -83,10 +79,6 @@ static const GDBusMethodInfo *writer_info_methods[] = {
&blame_method, NULL
};
-static const GDBusPropertyInfo *writer_info_properties[] = {
- &shmdir_property, NULL
-};
-
const GDBusInterfaceInfo ca_desrt_dconf_Writer = {
-1, (gchar *) "ca.desrt.dconf.Writer",
(GDBusMethodInfo **) writer_methods,
@@ -98,5 +90,5 @@ const GDBusInterfaceInfo ca_desrt_dconf_WriterInfo = {
-1, (gchar *) "ca.desrt.dconf.WriterInfo",
(GDBusMethodInfo **) writer_info_methods,
(GDBusSignalInfo **) NULL,
- (GDBusPropertyInfo **) writer_info_properties
+ (GDBusPropertyInfo **) NULL
};
diff --git a/service/dconf-state.c b/service/dconf-state.c
index a30054c..79e9753 100644
--- a/service/dconf-state.c
+++ b/service/dconf-state.c
@@ -1,7 +1,5 @@
#include "dconf-state.h"
-#include "dconf-shmdir.h"
-
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -51,19 +49,6 @@ dconf_state_init_session (DConfState *state)
g_error ("Can not create directory '%s': %s",
state->db_dir, g_strerror (errno));
}
-
- state->shm_dir = dconf_shmdir_from_environment ();
-
- if (state->shm_dir == NULL)
- {
- const gchar *tmpdir = g_get_tmp_dir ();
- gchar *shmdir;
-
- shmdir = g_build_filename (tmpdir, "dconf.XXXXXX", NULL);
-
- if ((state->shm_dir = mkdtemp (shmdir)) == NULL)
- g_error ("Can not create reasonable shm directory");
- }
}
static gboolean
diff --git a/service/dconf-state.h b/service/dconf-state.h
index 6a2ac58..f68ac3e 100644
--- a/service/dconf-state.h
+++ b/service/dconf-state.h
@@ -11,7 +11,6 @@ typedef struct
GMainLoop *main_loop;
guint64 serial;
gchar *db_dir;
- gchar *shm_dir;
gchar *id;
} DConfState;
diff --git a/service/dconf-writer.c b/service/dconf-writer.c
index 4218977..6c44c40 100644
--- a/service/dconf-writer.c
+++ b/service/dconf-writer.c
@@ -23,6 +23,7 @@
#include "dconf-rebuilder.h"
#include "dconf-state.h"
+#include "dconf-shm.h"
#include <stdlib.h>
#include <unistd.h>
@@ -35,7 +36,6 @@ struct OPAQUE_TYPE__DConfWriter
DConfState *state;
gchar *name;
gchar *path;
- gchar *shm;
};
/* Each element must only contain the ASCII characters "[A-Z][a-z][0-9]_"
@@ -77,26 +77,6 @@ dconf_writer_list_existing (void)
return (gchar **) g_ptr_array_free (array, FALSE);
}
-static void
-dconf_writer_touch_shm (DConfWriter *writer)
-{
- gchar one = 1;
- gint fd;
-
- fd = open (writer->shm, O_WRONLY);
-
- if (fd >= 0)
- {
- write (fd, &one, sizeof one);
- close (fd);
-
- unlink (writer->shm);
- }
-
- else if (errno != ENOENT)
- unlink (writer->shm);
-}
-
gboolean
dconf_writer_write (DConfWriter *writer,
const gchar *name,
@@ -106,7 +86,7 @@ dconf_writer_write (DConfWriter *writer,
if (!dconf_rebuilder_rebuild (writer->path, "", &name, &value, 1, error))
return FALSE;
- dconf_writer_touch_shm (writer);
+ dconf_shm_flag (writer->name);
return TRUE;
}
@@ -123,7 +103,7 @@ dconf_writer_write_many (DConfWriter *writer,
values, n_items, error))
return FALSE;
- dconf_writer_touch_shm (writer);
+ dconf_shm_flag (writer->name);
return TRUE;
}
@@ -146,7 +126,7 @@ dconf_writer_change (DConfWriter *writer,
if (!dconf_rebuilder_rebuild (writer->path, prefix, keys, values, n_items, error))
return FALSE;
- dconf_writer_touch_shm (writer);
+ dconf_shm_flag (writer->name);
return TRUE;
}
@@ -172,7 +152,6 @@ dconf_writer_new (DConfState *state,
writer = g_slice_new (DConfWriter);
writer->state = 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);
return writer;
diff --git a/service/service.c b/service/service.c
index 13dcc88..19eadb2 100644
--- a/service/service.c
+++ b/service/service.c
@@ -447,24 +447,6 @@ writer_info_method (GDBusConnection *connection,
g_assert_not_reached ();
}
-static GVariant *
-writer_info_get_property (GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *property_name,
- GError **error,
- gpointer user_data)
-{
- DConfState *state = user_data;
-
- /* debugging... */
- if G_UNLIKELY (state->blame_mode)
- gather_blame_info (state, connection, sender, object_path, "GetProperty", NULL);
-
- return g_variant_new_string (state->shm_dir);
-}
-
static const GDBusInterfaceVTable *
subtree_dispatch (GDBusConnection *connection,
const gchar *sender,
@@ -506,7 +488,7 @@ subtree_dispatch (GDBusConnection *connection,
else if (strcmp (interface_name, "ca.desrt.dconf.WriterInfo") == 0)
{
static const GDBusInterfaceVTable vtable = {
- writer_info_method, writer_info_get_property, NULL
+ writer_info_method, NULL
};
*out_user_data = state;