summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/automount.c9
-rw-r--r--src/core/path.c9
-rw-r--r--src/core/timer.c9
-rw-r--r--src/core/unit.c15
-rw-r--r--src/core/unit.h2
5 files changed, 26 insertions, 18 deletions
diff --git a/src/core/automount.c b/src/core/automount.c
index eff357bb3d..8ffdad18c7 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -796,7 +796,6 @@ fail:
static int automount_start(Unit *u) {
Automount *a = AUTOMOUNT(u);
- Unit *trigger;
int r;
assert(a);
@@ -807,11 +806,9 @@ static int automount_start(Unit *u) {
return -EEXIST;
}
- trigger = UNIT_TRIGGER(u);
- if (!trigger || trigger->load_state != UNIT_LOADED) {
- log_unit_error(u, "Refusing to start, unit to trigger not loaded.");
- return -ENOENT;
- }
+ r = unit_test_trigger_loaded(u);
+ if (r < 0)
+ return r;
r = unit_test_start_limit(u);
if (r < 0) {
diff --git a/src/core/path.c b/src/core/path.c
index a7a7ec28ae..3fe14ef2bc 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -555,17 +555,14 @@ static void path_mkdir(Path *p) {
static int path_start(Unit *u) {
Path *p = PATH(u);
- Unit *trigger;
int r;
assert(p);
assert(IN_SET(p->state, PATH_DEAD, PATH_FAILED));
- trigger = UNIT_TRIGGER(u);
- if (!trigger || trigger->load_state != UNIT_LOADED) {
- log_unit_error(u, "Refusing to start, unit to trigger not loaded.");
- return -ENOENT;
- }
+ r = unit_test_trigger_loaded(u);
+ if (r < 0)
+ return r;
r = unit_test_start_limit(u);
if (r < 0) {
diff --git a/src/core/timer.c b/src/core/timer.c
index 736ffaa437..d1e351c30d 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -595,17 +595,14 @@ fail:
static int timer_start(Unit *u) {
Timer *t = TIMER(u);
TimerValue *v;
- Unit *trigger;
int r;
assert(t);
assert(IN_SET(t->state, TIMER_DEAD, TIMER_FAILED));
- trigger = UNIT_TRIGGER(u);
- if (!trigger || trigger->load_state != UNIT_LOADED) {
- log_unit_error(u, "Refusing to start, unit to trigger not loaded.");
- return -ENOENT;
- }
+ r = unit_test_trigger_loaded(u);
+ if (r < 0)
+ return r;
r = unit_test_start_limit(u);
if (r < 0) {
diff --git a/src/core/unit.c b/src/core/unit.c
index 9f75c97682..8a599a571c 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1736,6 +1736,7 @@ static bool unit_verify_deps(Unit *u) {
* -EOPNOTSUPP: Unit type not supported
* -ENOLINK: The necessary dependencies are not fulfilled.
* -ESTALE: This unit has been started before and can't be started a second time
+ * -ENOENT: This is a triggering unit and unit to trigger is not loaded
*/
int unit_start(Unit *u) {
UnitActiveState state;
@@ -5590,6 +5591,20 @@ int unit_success_action_exit_status(Unit *u) {
return r;
}
+int unit_test_trigger_loaded(Unit *u) {
+ Unit *trigger;
+
+ /* Tests whether the unit to trigger is loaded */
+
+ trigger = UNIT_TRIGGER(u);
+ if (!trigger)
+ return log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOENT), "Refusing to start, unit to trigger not loaded.");
+ if (trigger->load_state != UNIT_LOADED)
+ return log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOENT), "Refusing to start, unit %s to trigger not loaded.", u->id);
+
+ return 0;
+}
+
static const char* const collect_mode_table[_COLLECT_MODE_MAX] = {
[COLLECT_INACTIVE] = "inactive",
[COLLECT_INACTIVE_OR_FAILED] = "inactive-or-failed",
diff --git a/src/core/unit.h b/src/core/unit.h
index 8c67676c8a..35b936771c 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -830,6 +830,8 @@ int unit_exit_status(Unit *u);
int unit_success_action_exit_status(Unit *u);
int unit_failure_action_exit_status(Unit *u);
+int unit_test_trigger_loaded(Unit *u);
+
/* Macros which append UNIT= or USER_UNIT= to the message */
#define log_unit_full(unit, level, error, ...) \