summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorkayrus <kayrus@users.noreply.github.com>2016-04-29 15:59:51 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-29 15:59:51 +0200
commit313fe66fbd0cd3d62566edece7944d6cf45b1b21 (patch)
tree5659eec8391c56f12133e136c406a010c07b694d /src/shared
parent3e39355a96f615f2cb1e805c7d74efbc272de1cd (diff)
core: Filter by unit name behind the D-Bus, instead on the client side (#3142)
This commit improves systemd performance on the systems which have thousands of units.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/install.c11
-rw-r--r--src/shared/install.h2
2 files changed, 11 insertions, 2 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index b74ff6de22..931d3e2907 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -2653,7 +2653,9 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(UnitFileList*, unit_file_list_free_one);
int unit_file_get_list(
UnitFileScope scope,
const char *root_dir,
- Hashmap *h) {
+ Hashmap *h,
+ char **states,
+ char **patterns) {
_cleanup_lookup_paths_free_ LookupPaths paths = {};
char **i;
@@ -2685,6 +2687,9 @@ int unit_file_get_list(
if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
continue;
+ if (!strv_fnmatch_or_empty(patterns, de->d_name, FNM_NOESCAPE))
+ continue;
+
if (hashmap_get(h, de->d_name))
continue;
@@ -2705,6 +2710,10 @@ int unit_file_get_list(
if (r < 0)
f->state = UNIT_FILE_BAD;
+ if (!strv_isempty(states) &&
+ !strv_contains(states, unit_file_state_to_string(f->state)))
+ continue;
+
r = hashmap_put(h, basename(f->path), f);
if (r < 0)
return r;
diff --git a/src/shared/install.h b/src/shared/install.h
index 4133faffa2..4ffc5a21f2 100644
--- a/src/shared/install.h
+++ b/src/shared/install.h
@@ -232,7 +232,7 @@ int unit_file_add_dependency(
int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name);
-int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h);
+int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns);
Hashmap* unit_file_list_free(Hashmap *h);
int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source);