summaryrefslogtreecommitdiff
path: root/bus
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2017-02-15 14:13:05 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2017-02-21 13:23:37 +0000
commit613dd7dd64d0681dc2d6deb5b213327f12fe5e19 (patch)
tree4506b3b4ecba999dea1c2d16734b55174c0c1191 /bus
parentf2b6cc4207ef3e263a7ddcbc8c03b815f8f651b8 (diff)
downloaddbus-613dd7dd64d0681dc2d6deb5b213327f12fe5e19.tar.gz
bus_config_parser_get_watched_dirs: Turn into a helper function
This means we can test it more easily. At the moment it just contains service directories, because this config file is so cut-down that it doesn't have any config.d directories. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825 Reviewed-by: Philip Withnall <withnall@endlessm.com> Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Diffstat (limited to 'bus')
-rw-r--r--bus/bus.c30
-rw-r--r--bus/config-parser.c76
-rw-r--r--bus/config-parser.h2
3 files changed, 79 insertions, 29 deletions
diff --git a/bus/bus.c b/bus/bus.c
index 70f1d40b..b0138664 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -670,32 +670,6 @@ process_config_every_time (BusContext *context,
return retval;
}
-static dbus_bool_t
-list_concat_new (DBusList **a,
- DBusList **b,
- DBusList **result)
-{
- DBusList *link;
-
- *result = NULL;
-
- for (link = _dbus_list_get_first_link (a); link; link = _dbus_list_get_next_link (a, link))
- {
- if (!_dbus_list_append (result, link->data))
- goto oom;
- }
- for (link = _dbus_list_get_first_link (b); link; link = _dbus_list_get_next_link (b, link))
- {
- if (!_dbus_list_append (result, link->data))
- goto oom;
- }
-
- return TRUE;
-oom:
- _dbus_list_clear (result);
- return FALSE;
-}
-
static void
raise_file_descriptor_limit (BusContext *context)
{
@@ -756,9 +730,7 @@ process_config_postinit (BusContext *context,
/* We need to monitor both the configuration directories and directories
* containing .service files.
*/
- if (!list_concat_new (bus_config_parser_get_conf_dirs (parser),
- bus_config_parser_get_service_dirs (parser),
- &watched_dirs))
+ if (!bus_config_parser_get_watched_dirs (parser, &watched_dirs))
{
BUS_SET_OOM (error);
return FALSE;
diff --git a/bus/config-parser.c b/bus/config-parser.c
index 5275f8f1..c1e2ff35 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -2789,6 +2789,46 @@ bus_config_parser_steal_service_context_table (BusConfigParser *parser)
return table;
}
+/*
+ * Return a list of the directories that should be watched with inotify,
+ * as strings. The list might be empty and is in arbitrary order.
+ *
+ * The list must be empty on entry. On success, the links are owned by the
+ * caller and must be freed, but the data in each link remains owned by
+ * the BusConfigParser and must not be freed: in GObject-Introspection
+ * notation, it is (transfer container).
+ */
+dbus_bool_t
+bus_config_parser_get_watched_dirs (BusConfigParser *parser,
+ DBusList **watched_dirs)
+{
+ DBusList *link;
+
+ _dbus_assert (*watched_dirs == NULL);
+
+ for (link = _dbus_list_get_first_link (&parser->conf_dirs);
+ link != NULL;
+ link = _dbus_list_get_next_link (&parser->conf_dirs, link))
+ {
+ if (!_dbus_list_append (watched_dirs, link->data))
+ goto oom;
+ }
+
+ for (link = _dbus_list_get_first_link (&parser->service_dirs);
+ link != NULL;
+ link = _dbus_list_get_next_link (&parser->service_dirs, link))
+ {
+ if (!_dbus_list_append (watched_dirs, link->data))
+ goto oom;
+ }
+
+ return TRUE;
+
+oom:
+ _dbus_list_clear (watched_dirs);
+ return FALSE;
+}
+
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include <stdio.h>
@@ -3399,6 +3439,7 @@ test_default_session_servicedirs (const DBusString *test_base_dir)
BusConfigParser *parser = NULL;
DBusError error = DBUS_ERROR_INIT;
DBusList **dirs;
+ DBusList *watched_dirs = NULL;
DBusList *link;
DBusString tmp;
DBusString full_path;
@@ -3534,12 +3575,47 @@ test_default_session_servicedirs (const DBusString *test_base_dir)
goto out;
}
+ if (!bus_config_parser_get_watched_dirs (parser, &watched_dirs))
+ _dbus_assert_not_reached ("out of memory");
+
+ for (link = _dbus_list_get_first_link (&watched_dirs), i = 0;
+ link != NULL;
+ link = _dbus_list_get_next_link (&watched_dirs, link), i++)
+ {
+ printf (" watched service dir: '%s'\n", (const char *) link->data);
+ printf (" current standard service dir: '%s'\n",
+ test_session_service_dir_matches[i]);
+
+ if (test_session_service_dir_matches[i] == NULL)
+ {
+ printf ("more directories parsed than in match set\n");
+ goto out;
+ }
+
+ if (strcmp (test_session_service_dir_matches[i],
+ (const char *) link->data) != 0)
+ {
+ printf ("'%s' directory does not match '%s' in the match set\n",
+ (const char *) link->data,
+ test_session_service_dir_matches[i]);
+ goto out;
+ }
+ }
+
+ if (test_session_service_dir_matches[i] != NULL)
+ {
+ printf ("extra data %s in the match set was not matched\n",
+ test_session_service_dir_matches[i]);
+ goto out;
+ }
+
ret = TRUE;
out:
if (parser != NULL)
bus_config_parser_unref (parser);
+ _dbus_list_clear (&watched_dirs);
_dbus_string_free (&full_path);
_dbus_string_free (&install_root_based);
_dbus_string_free (&progs);
diff --git a/bus/config-parser.h b/bus/config-parser.h
index ba5bf749..2361e22f 100644
--- a/bus/config-parser.h
+++ b/bus/config-parser.h
@@ -73,6 +73,8 @@ DBusList** bus_config_parser_get_conf_dirs (BusConfigParser *parser);
BusPolicy* bus_config_parser_steal_policy (BusConfigParser *parser);
void bus_config_parser_get_limits (BusConfigParser *parser,
BusLimits *limits);
+dbus_bool_t bus_config_parser_get_watched_dirs (BusConfigParser *parser,
+ DBusList **watched_dirs);
DBusHashTable* bus_config_parser_steal_service_context_table (BusConfigParser *parser);