aboutsummaryrefslogtreecommitdiffstats
path: root/src/wgtpkg-unit.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-03-15 10:17:41 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-03-17 13:01:40 +0100
commit2a8b46d16ea5d0c99831e95b47cab037f220f7af (patch)
treee4759270fb131389e04141429c96aad9667ff154 /src/wgtpkg-unit.c
parentcdd05aa3e66a876dba01f04173d817b9e5e039a0 (diff)
utils-systemd: introduction of systemd interface
Isolate the interface to systemd. Change-Id: I03ea654da9fab2df0e6eec980b0e5623487d1b73 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/wgtpkg-unit.c')
-rw-r--r--src/wgtpkg-unit.c52
1 files changed, 16 insertions, 36 deletions
diff --git a/src/wgtpkg-unit.c b/src/wgtpkg-unit.c
index 9e6a1e2..f141766 100644
--- a/src/wgtpkg-unit.c
+++ b/src/wgtpkg-unit.c
@@ -35,13 +35,10 @@
#include "wgtpkg-mustach.h"
#include "utils-json.h"
#include "wgt-json.h"
+#include "utils-systemd.h"
#include "wgtpkg-unit.h"
-#if !defined(SYSTEMD_UNITS_ROOT)
-# define SYSTEMD_UNITS_ROOT "/usr/local/lib/systemd"
-#endif
-
#if 0
#include <ctype.h>
#else
@@ -388,54 +385,37 @@ static int check_unit_desc(const struct unitdesc *desc, int tells)
static int get_unit_path(char *path, size_t pathlen, const struct unitdesc *desc)
{
- int rc;
+ int rc = systemd_get_unit_path(
+ path, pathlen, desc->scope == unitscope_user,
+ desc->name, desc->type == unittype_socket ? "socket" : "service");
- rc = snprintf(path, pathlen, "%s/%s/%s.%s",
- SYSTEMD_UNITS_ROOT,
- desc->scope == unitscope_system ? "system" : "user",
- desc->name,
- desc->type == unittype_socket ? "socket" : "service");
+ if (rc < 0)
+ ERROR("can't get the unit path for %s", desc->name);
- if (rc >= 0 && (size_t)rc >= pathlen) {
- ERROR("can't set the unit path");
- errno = EINVAL;
- rc = -1;
- }
return rc;
}
static int get_wants_path(char *path, size_t pathlen, const struct unitdesc *desc)
{
- int rc;
+ int rc = systemd_get_wants_path(
+ path, pathlen, desc->scope == unitscope_user, desc->wanted_by,
+ desc->name, desc->type == unittype_socket ? "socket" : "service");
- rc = snprintf(path, pathlen, "%s/%s/%s.wants/%s.%s",
- SYSTEMD_UNITS_ROOT,
- desc->scope == unitscope_system ? "system" : "user",
- desc->wanted_by,
- desc->name,
- desc->type == unittype_socket ? "socket" : "service");
+ if (rc < 0)
+ ERROR("can't get the wants path for %s and %s", desc->name, desc->wanted_by);
- if (rc >= 0 && (size_t)rc >= pathlen) {
- ERROR("can't set the wants path");
- errno = EINVAL;
- rc = -1;
- }
return rc;
}
static int get_wants_target(char *path, size_t pathlen, const struct unitdesc *desc)
{
- int rc;
+ int rc = systemd_get_wants_target(
+ path, pathlen,
+ desc->name, desc->type == unittype_socket ? "socket" : "service");
- rc = snprintf(path, pathlen, "../%s.%s",
- desc->name,
- desc->type == unittype_socket ? "socket" : "service");
+ if (rc < 0)
+ ERROR("can't get the wants target for %s", desc->name);
- if (rc >= 0 && (size_t)rc >= pathlen) {
- ERROR("can't set the wants target");
- errno = EINVAL;
- rc = -1;
- }
return rc;
}