summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-06-01 19:06:19 +0200
committerLennart Poettering <lennart@poettering.net>2018-06-01 19:08:30 +0200
commit2ad2e41a72ec19159c0746a78e15ff880fe32a63 (patch)
tree56c695bb689e7932f72604945e9e2ef765beb178 /src/core
parent7f66b026bbdda6bd3ddf7f617bf2c3a475e4a665 (diff)
downloadsystemd-2ad2e41a72ec19159c0746a78e15ff880fe32a63.tar.gz
core: don't trigger OnFailure= deps when a unit is going to restart
This adds a flags parameter to unit_notify() which can be used to pass additional notification information to the function. We the make the old reload_failure boolean parameter one of these flags, and then add a new flag that let's unit_notify() if we are configured to restart the service. Note that this adjusts behaviour of systemd to match what the docs say. Fixes: #8398
Diffstat (limited to 'src/core')
-rw-r--r--src/core/automount.c2
-rw-r--r--src/core/device.c2
-rw-r--r--src/core/mount.c3
-rw-r--r--src/core/path.c2
-rw-r--r--src/core/scope.c2
-rw-r--r--src/core/service.c5
-rw-r--r--src/core/slice.c2
-rw-r--r--src/core/socket.c2
-rw-r--r--src/core/swap.c2
-rw-r--r--src/core/target.c2
-rw-r--r--src/core/timer.c2
-rw-r--r--src/core/unit.c10
-rw-r--r--src/core/unit.h7
13 files changed, 27 insertions, 16 deletions
diff --git a/src/core/automount.c b/src/core/automount.c
index c49b523eb2..d4572774ac 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -252,7 +252,7 @@ static void automount_set_state(Automount *a, AutomountState state) {
if (state != old_state)
log_unit_debug(UNIT(a), "Changed %s -> %s", automount_state_to_string(old_state), automount_state_to_string(state));
- unit_notify(UNIT(a), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(a), state_translation_table[old_state], state_translation_table[state], 0);
}
static int automount_coldplug(Unit *u) {
diff --git a/src/core/device.c b/src/core/device.c
index a775e8bb95..b3f8eb4e02 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -123,7 +123,7 @@ static void device_set_state(Device *d, DeviceState state) {
if (state != old_state)
log_unit_debug(UNIT(d), "Changed %s -> %s", device_state_to_string(old_state), device_state_to_string(state));
- unit_notify(UNIT(d), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(d), state_translation_table[old_state], state_translation_table[state], 0);
}
static int device_coldplug(Unit *u) {
diff --git a/src/core/mount.c b/src/core/mount.c
index d5463b7621..d1590567d6 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -657,7 +657,8 @@ static void mount_set_state(Mount *m, MountState state) {
if (state != old_state)
log_unit_debug(UNIT(m), "Changed %s -> %s", mount_state_to_string(old_state), mount_state_to_string(state));
- unit_notify(UNIT(m), state_translation_table[old_state], state_translation_table[state], m->reload_result == MOUNT_SUCCESS);
+ unit_notify(UNIT(m), state_translation_table[old_state], state_translation_table[state],
+ m->reload_result == MOUNT_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE);
}
static int mount_coldplug(Unit *u) {
diff --git a/src/core/path.c b/src/core/path.c
index c0c0f07563..4a3ff27b2c 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -425,7 +425,7 @@ static void path_set_state(Path *p, PathState state) {
if (state != old_state)
log_unit_debug(UNIT(p), "Changed %s -> %s", path_state_to_string(old_state), path_state_to_string(state));
- unit_notify(UNIT(p), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(p), state_translation_table[old_state], state_translation_table[state], 0);
}
static void path_enter_waiting(Path *p, bool initial, bool recheck);
diff --git a/src/core/scope.c b/src/core/scope.c
index 1469cebff9..7410f154e6 100644
--- a/src/core/scope.c
+++ b/src/core/scope.c
@@ -98,7 +98,7 @@ static void scope_set_state(Scope *s, ScopeState state) {
if (state != old_state)
log_debug("%s changed %s -> %s", UNIT(s)->id, scope_state_to_string(old_state), scope_state_to_string(state));
- unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], 0);
}
static int scope_add_default_dependencies(Scope *s) {
diff --git a/src/core/service.c b/src/core/service.c
index 1af3032597..89ac9964cb 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1080,7 +1080,9 @@ static void service_set_state(Service *s, ServiceState state) {
if (old_state != state)
log_unit_debug(UNIT(s), "Changed %s -> %s", service_state_to_string(old_state), service_state_to_string(state));
- unit_notify(UNIT(s), table[old_state], table[state], s->reload_result == SERVICE_SUCCESS);
+ unit_notify(UNIT(s), table[old_state], table[state],
+ (s->reload_result == SERVICE_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE) |
+ (s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0));
}
static usec_t service_coldplug_timeout(Service *s) {
@@ -1590,6 +1592,7 @@ static bool service_will_restart(Unit *u) {
return false;
if (UNIT(s)->job->type == JOB_START)
return true;
+
return false;
}
diff --git a/src/core/slice.c b/src/core/slice.c
index 3a5ab3bc6c..71614e4b89 100644
--- a/src/core/slice.c
+++ b/src/core/slice.c
@@ -42,7 +42,7 @@ static void slice_set_state(Slice *t, SliceState state) {
slice_state_to_string(old_state),
slice_state_to_string(state));
- unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], 0);
}
static int slice_add_parent_slice(Slice *s) {
diff --git a/src/core/socket.c b/src/core/socket.c
index 238c942a1a..d287ee6f36 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -1795,7 +1795,7 @@ static void socket_set_state(Socket *s, SocketState state) {
if (state != old_state)
log_unit_debug(UNIT(s), "Changed %s -> %s", socket_state_to_string(old_state), socket_state_to_string(state));
- unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], 0);
}
static int socket_coldplug(Unit *u) {
diff --git a/src/core/swap.c b/src/core/swap.c
index e75c9f2464..b352ff3f23 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -496,7 +496,7 @@ static void swap_set_state(Swap *s, SwapState state) {
if (state != old_state)
log_unit_debug(UNIT(s), "Changed %s -> %s", swap_state_to_string(old_state), swap_state_to_string(state));
- unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], 0);
/* If there other units for the same device node have a job
queued it might be worth checking again if it is runnable
diff --git a/src/core/target.c b/src/core/target.c
index e7e4914146..11175f3456 100644
--- a/src/core/target.c
+++ b/src/core/target.c
@@ -31,7 +31,7 @@ static void target_set_state(Target *t, TargetState state) {
target_state_to_string(old_state),
target_state_to_string(state));
- unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], 0);
}
static int target_add_default_dependencies(Target *t) {
diff --git a/src/core/timer.c b/src/core/timer.c
index 3adbe57d55..b2fe05d4cf 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -264,7 +264,7 @@ static void timer_set_state(Timer *t, TimerState state) {
if (state != old_state)
log_unit_debug(UNIT(t), "Changed %s -> %s", timer_state_to_string(old_state), timer_state_to_string(state));
- unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], true);
+ unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], 0);
}
static void timer_enter_waiting(Timer *t, bool initial);
diff --git a/src/core/unit.c b/src/core/unit.c
index 693d726922..26aaf6f3fb 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1932,7 +1932,7 @@ int unit_reload(Unit *u) {
if (!UNIT_VTABLE(u)->reload) {
/* Unit doesn't have a reload function, but we need to propagate the reload anyway */
- unit_notify(u, unit_active_state(u), unit_active_state(u), true);
+ unit_notify(u, unit_active_state(u), unit_active_state(u), 0);
return 0;
}
@@ -2301,7 +2301,7 @@ static void unit_update_on_console(Unit *u) {
}
-void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) {
+void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags) {
bool unexpected;
Manager *m;
@@ -2377,7 +2377,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
if (u->job->state == JOB_RUNNING) {
if (ns == UNIT_ACTIVE)
- job_finish_and_invalidate(u->job, reload_success ? JOB_DONE : JOB_FAILED, true, false);
+ job_finish_and_invalidate(u->job, (flags & UNIT_NOTIFY_RELOAD_FAILURE) ? JOB_FAILED : JOB_DONE, true, false);
else if (!IN_SET(ns, UNIT_ACTIVATING, UNIT_RELOADING)) {
unexpected = true;
@@ -2430,7 +2430,9 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
if (ns != os && ns == UNIT_FAILED) {
log_unit_debug(u, "Unit entered failed state.");
- unit_start_on_failure(u);
+
+ if (!(flags & UNIT_NOTIFY_WILL_AUTO_RESTART))
+ unit_start_on_failure(u);
}
}
diff --git a/src/core/unit.h b/src/core/unit.h
index 767cd96aeb..f1b5d61af7 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -639,7 +639,12 @@ int unit_reload(Unit *u);
int unit_kill(Unit *u, KillWho w, int signo, sd_bus_error *error);
int unit_kill_common(Unit *u, KillWho who, int signo, pid_t main_pid, pid_t control_pid, sd_bus_error *error);
-void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success);
+typedef enum UnitNotifyFlags {
+ UNIT_NOTIFY_RELOAD_FAILURE = 1U << 0,
+ UNIT_NOTIFY_WILL_AUTO_RESTART = 1U << 1,
+} UnitNotifyFlags;
+
+void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags);
int unit_watch_pid(Unit *u, pid_t pid);
void unit_unwatch_pid(Unit *u, pid_t pid);