ryantimwilson / rpms / systemd

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