summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-07 17:40:11 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-12 13:43:32 +0200
commite735decc38fd60921c8d8c0345d01fd4ed874677 (patch)
treee6031ab5bf607cb0d4b278d9d1ad0596ace97570 /src/shared
parent27c06cb516c3b87c34f2a1c2c227152997d05c8c (diff)
systemctl: move check whether a service exists as native unit file to install.c
Move the search path check from the SysV service compat support into install.c so that we can reuse the usual algorithm instead of rolling a private loop for this.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/install.c19
-rw-r--r--src/shared/install.h1
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);