summaryrefslogtreecommitdiff
path: root/src/shared/install.c
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/install.c
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/install.c')
-rw-r--r--src/shared/install.c19
1 files changed, 19 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;