diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/install.c | 19 | ||||
-rw-r--r-- | src/shared/install.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/shared/install.c b/src/shared/install.c index f78cc814e5..b5453adeee 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -2052,6 +2052,25 @@ int unit_file_get_state( return unit_file_lookup_state(scope, &paths, name, ret); } +int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name) { + _cleanup_(install_context_done) InstallContext c = {}; + int r; + + assert(paths); + assert(name); + + if (!unit_name_is_valid(name, UNIT_NAME_ANY)) + return -EINVAL; + + r = install_info_discover(scope, &c, paths, name, 0, NULL); + if (r == -ENOENT) + return 0; + if (r < 0) + return r; + + return 1; +} + int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name) { _cleanup_strv_free_ char **files = NULL; char **p; diff --git a/src/shared/install.h b/src/shared/install.h index 578664dd48..c57c23934b 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -139,6 +139,7 @@ int unit_file_add_dependency(UnitFileScope scope, bool runtime, const char *root int unit_file_lookup_state(UnitFileScope scope, const LookupPaths *paths, const char *name, UnitFileState *ret); 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); Hashmap* unit_file_list_free(Hashmap *h); |