mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-02-05 07:40:35 +01:00
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>
This commit is contained in:
parent
f2b6cc4207
commit
613dd7dd64
3 changed files with 79 additions and 29 deletions
30
bus/bus.c
30
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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue