summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-18 13:11:28 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-30 14:01:46 +0200
commite8630e695232bdfcd16b55f3faafb4329c961104 (patch)
treedce17c3db55aa13c5f64ed6f8a415e6eea3db7fd /src/test
parent7d1e91d1a9504ab1bc03894038f90a8e87a4e982 (diff)
downloadsystemd-e8630e695232bdfcd16b55f3faafb4329c961104.tar.gz
systemd-e8630e695232bdfcd16b55f3faafb4329c961104.tar.bz2
systemd-e8630e695232bdfcd16b55f3faafb4329c961104.zip
pid1: use a cache for all unit aliases
This reworks how we load units from disk. Instead of chasing symlinks every time we are asked to load a unit by name, we slurp all symlinks from disk and build two hashmaps: 1. from unit name to either alias target, or fragment on disk (if an alias, we put just the target name in the hashmap, if a fragment we put an absolute path, so we can distinguish both). 2. from a unit name to all aliases Reading all this data can be pretty costly (40 ms) on my machine, so we keep it around for reuse. The advantage is that we can reliably know what all the aliases of a given unit are. This means we can reliably load dropins under all names. This fixes #11972.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-unit-file.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
index 5e281b28d5..c5144a1b7e 100644
--- a/src/test/test-unit-file.c
+++ b/src/test/test-unit-file.c
@@ -24,10 +24,32 @@ static void test_unit_validate_alias_symlink_and_warn(void) {
assert_se(unit_validate_alias_symlink_and_warn("/path/a.slice", "/other/b.slice") == -EINVAL);
}
+static void test_unit_file_build_name_map(void) {
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
+ _cleanup_hashmap_free_ Hashmap *unit_ids = NULL;
+ _cleanup_hashmap_free_ Hashmap *unit_names = NULL;
+ Iterator i;
+ const char *k, *dst;
+ char **v;
+
+ assert_se(lookup_paths_init(&lp, UNIT_FILE_SYSTEM, 0, NULL) >= 0);
+
+ assert_se(unit_file_build_name_map(&lp, &unit_ids, &unit_names, NULL) == 0);
+
+ HASHMAP_FOREACH_KEY(dst, k, unit_ids, i)
+ log_info("ids: %s → %s", k, dst);
+
+ HASHMAP_FOREACH_KEY(v, k, unit_names, i) {
+ _cleanup_free_ char *j = strv_join(v, ", ");
+ log_info("aliases: %s ← %s", k, j);
+ }
+}
+
int main(int argc, char **argv) {
test_setup_logging(LOG_DEBUG);
test_unit_validate_alias_symlink_and_warn();
+ test_unit_file_build_name_map();
return 0;
}