|
|
661545 |
From 5f0bb278dfe913bd2c7dcbc9f457892f5e8aca9d Mon Sep 17 00:00:00 2001
|
|
|
661545 |
From: Jouke Witteveen <j.witteveen@gmail.com>
|
|
|
661545 |
Date: Tue, 6 Dec 2016 13:30:28 +0100
|
|
|
661545 |
Subject: [PATCH] service: go through stop_post on failure (#4770)
|
|
|
661545 |
|
|
|
661545 |
(cherry picked from commit c3fda31da36706b045f5de800d6a77e65e7a8ec9)
|
|
|
661545 |
|
|
|
661545 |
Resolves: #1733998
|
|
|
661545 |
---
|
|
|
661545 |
src/core/service.c | 24 +++++++++++-------------
|
|
|
661545 |
1 file changed, 11 insertions(+), 13 deletions(-)
|
|
|
661545 |
|
|
|
661545 |
diff --git a/src/core/service.c b/src/core/service.c
|
|
|
661545 |
index b6f302ec33..e538280bad 100644
|
|
|
661545 |
--- a/src/core/service.c
|
|
|
661545 |
+++ b/src/core/service.c
|
|
|
661545 |
@@ -1532,7 +1532,7 @@ static void service_enter_running(Service *s, ServiceResult f) {
|
|
|
661545 |
service_set_state(s, SERVICE_RUNNING);
|
|
|
661545 |
|
|
|
661545 |
} else if (f != SERVICE_SUCCESS)
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, f);
|
|
|
661545 |
else if (s->remain_after_exit)
|
|
|
661545 |
service_set_state(s, SERVICE_EXITED);
|
|
|
661545 |
else
|
|
|
661545 |
@@ -1671,7 +1671,7 @@ static void service_enter_start(Service *s) {
|
|
|
661545 |
|
|
|
661545 |
fail:
|
|
|
661545 |
log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run 'start' task: %m", UNIT(s)->id);
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_RESOURCES);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_RESOURCES);
|
|
|
661545 |
}
|
|
|
661545 |
|
|
|
661545 |
static void service_enter_start_pre(Service *s) {
|
|
|
661545 |
@@ -1823,9 +1823,7 @@ static void service_run_next_control(Service *s) {
|
|
|
661545 |
fail:
|
|
|
661545 |
log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run next control task: %m", UNIT(s)->id);
|
|
|
661545 |
|
|
|
661545 |
- if (s->state == SERVICE_START_PRE)
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_RESOURCES);
|
|
|
661545 |
- else if (s->state == SERVICE_STOP)
|
|
|
661545 |
+ if (IN_SET(s->state, SERVICE_START_PRE, SERVICE_STOP))
|
|
|
661545 |
service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_RESOURCES);
|
|
|
661545 |
else if (s->state == SERVICE_STOP_POST)
|
|
|
661545 |
service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true);
|
|
|
661545 |
@@ -2572,7 +2570,7 @@ static void service_notify_cgroup_empty_event(Unit *u) {
|
|
|
661545 |
|
|
|
661545 |
service_unwatch_pid_file(s);
|
|
|
661545 |
if (s->state == SERVICE_START)
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_PROTOCOL);
|
|
|
661545 |
+ service_enter_stop_post(s, SERVICE_FAILURE_PROTOCOL);
|
|
|
661545 |
else
|
|
|
661545 |
service_enter_stop(s, SERVICE_FAILURE_PROTOCOL);
|
|
|
661545 |
}
|
|
|
661545 |
@@ -2701,17 +2699,17 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|
|
661545 |
if (f == SERVICE_SUCCESS)
|
|
|
661545 |
service_enter_start_post(s);
|
|
|
661545 |
else
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, f);
|
|
|
661545 |
break;
|
|
|
661545 |
} else if (s->type == SERVICE_NOTIFY) {
|
|
|
661545 |
/* Only enter running through a notification, so that the
|
|
|
661545 |
* SERVICE_START state signifies that no ready notification
|
|
|
661545 |
* has been received */
|
|
|
661545 |
if (f != SERVICE_SUCCESS)
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, f);
|
|
|
661545 |
else if (!s->remain_after_exit)
|
|
|
661545 |
/* The service has never been active */
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_PROTOCOL);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_PROTOCOL);
|
|
|
661545 |
break;
|
|
|
661545 |
}
|
|
|
661545 |
|
|
|
661545 |
@@ -2792,7 +2790,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|
|
661545 |
if (f == SERVICE_SUCCESS)
|
|
|
661545 |
service_enter_start(s);
|
|
|
661545 |
else
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, f);
|
|
|
661545 |
break;
|
|
|
661545 |
|
|
|
661545 |
case SERVICE_START:
|
|
|
661545 |
@@ -2801,7 +2799,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|
|
661545 |
break;
|
|
|
661545 |
|
|
|
661545 |
if (f != SERVICE_SUCCESS) {
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, f);
|
|
|
661545 |
break;
|
|
|
661545 |
}
|
|
|
661545 |
|
|
|
661545 |
@@ -2818,7 +2816,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|
|
661545 |
if (!has_start_post && r < 0) {
|
|
|
661545 |
r = service_demand_pid_file(s);
|
|
|
661545 |
if (r < 0 || !cgroup_good(s))
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_PROTOCOL);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_PROTOCOL);
|
|
|
661545 |
break;
|
|
|
661545 |
}
|
|
|
661545 |
} else
|
|
|
661545 |
@@ -2914,7 +2912,7 @@ static int service_dispatch_timer(sd_event_source *source, usec_t usec, void *us
|
|
|
661545 |
case SERVICE_START_PRE:
|
|
|
661545 |
case SERVICE_START:
|
|
|
661545 |
log_unit_warning(UNIT(s)->id, "%s %s operation timed out. Terminating.", UNIT(s)->id, s->state == SERVICE_START ? "start" : "start-pre");
|
|
|
661545 |
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_TIMEOUT);
|
|
|
661545 |
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_TIMEOUT);
|
|
|
661545 |
break;
|
|
|
661545 |
|
|
|
661545 |
case SERVICE_START_POST:
|