summaryrefslogtreecommitdiff
path: root/src/unit.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-07-03 19:46:38 +0200
committerLennart Poettering <lennart@poettering.net>2010-07-03 19:46:38 +0200
commit2c966c038dc32ef39baa176371395cde4e541d01 (patch)
tree39f5104335943ad00f5f272e6d3d9de58fa8fae6 /src/unit.c
parentc5da34ef1ba450351638be0d71bddb54677a4d6e (diff)
unit: simplify things a little by introducing API to add two dependencies in one step
Diffstat (limited to 'src/unit.c')
-rw-r--r--src/unit.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/src/unit.c b/src/unit.c
index 9fed5a0f4e..8c495b46eb 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -1324,6 +1324,20 @@ fail:
return r;
}
+int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference) {
+ int r;
+
+ assert(u);
+
+ if ((r = unit_add_dependency(u, d, other, add_reference)) < 0)
+ return r;
+
+ if ((r = unit_add_dependency(u, e, other, add_reference)) < 0)
+ return r;
+
+ return 0;
+}
+
static const char *resolve_template(Unit *u, const char *name, const char*path, char **p) {
char *s;
@@ -1378,6 +1392,27 @@ finish:
return r;
}
+int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) {
+ Unit *other;
+ int r;
+ char *s;
+
+ assert(u);
+ assert(name || path);
+
+ if (!(name = resolve_template(u, name, path, &s)))
+ return -ENOMEM;
+
+ if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
+ goto finish;
+
+ r = unit_add_two_dependencies(u, d, e, other, add_reference);
+
+finish:
+ free(s);
+ return r;
+}
+
int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *name, const char *path, bool add_reference) {
Unit *other;
int r;
@@ -1399,6 +1434,28 @@ finish:
return r;
}
+int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) {
+ Unit *other;
+ int r;
+ char *s;
+
+ assert(u);
+ assert(name || path);
+
+ if (!(name = resolve_template(u, name, path, &s)))
+ return -ENOMEM;
+
+ if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
+ goto finish;
+
+ if ((r = unit_add_two_dependencies(other, d, e, u, add_reference)) < 0)
+ goto finish;
+
+finish:
+ free(s);
+ return r;
+}
+
int set_unit_path(const char *p) {
char *cwd, *c;
int r;
@@ -1907,10 +1964,7 @@ int unit_add_node_link(Unit *u, const char *what, bool wants) {
if (r < 0)
return r;
- if ((r = unit_add_dependency(u, UNIT_AFTER, device, true)) < 0)
- return r;
-
- if ((r = unit_add_dependency(u, UNIT_REQUIRES, device, true)) < 0)
+ if ((r = unit_add_two_dependencies(u, UNIT_AFTER, UNIT_REQUIRES, device, true)) < 0)
return r;
if (wants)