anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0762-core-when-determining-whether-a-process-exit-status-.patch

661545
From 8c9d6639a22d32734d950db37bfb852a1464c621 Mon Sep 17 00:00:00 2001
661545
From: Lennart Poettering <lennart@poettering.net>
661545
Date: Mon, 10 Oct 2016 22:07:30 +0200
661545
Subject: [PATCH] core: when determining whether a process exit status is
661545
 clean, consider whether it is a command or a daemon
661545
661545
SIGTERM should be considered a clean exit code for daemons (i.e. long-running
661545
processes, as a daemon without SIGTERM handler may be shut down without issues
661545
via SIGTERM still) while it should not be considered a clean exit code for
661545
commands (i.e. short-running processes).
661545
661545
Let's add two different clean checking modes for this, and use the right one at
661545
the appropriate places.
661545
661545
Fixes: #4275
661545
(cherry picked from commit 1f0958f640b87175cd547c1e69084cfe54a22e9d)
661545
661545
Resolves: #1560417
661545
---
661545
 src/core/busname.c          |  2 +-
661545
 src/core/mount.c            |  2 +-
661545
 src/core/service.c          |  2 +-
661545
 src/core/socket.c           |  2 +-
661545
 src/core/swap.c             |  2 +-
661545
 src/remount-fs/remount-fs.c |  2 +-
661545
 src/shared/exit-status.c    | 13 ++++---------
661545
 src/shared/exit-status.h    |  7 ++++++-
661545
 8 files changed, 16 insertions(+), 16 deletions(-)
661545
661545
diff --git a/src/core/busname.c b/src/core/busname.c
661545
index 97886f1e05..f5553e5418 100644
661545
--- a/src/core/busname.c
661545
+++ b/src/core/busname.c
661545
@@ -849,7 +849,7 @@ static void busname_sigchld_event(Unit *u, pid_t pid, int code, int status) {
661545
 
661545
         n->control_pid = 0;
661545
 
661545
-        if (is_clean_exit(code, status, NULL))
661545
+        if (is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL))
661545
                 f = BUSNAME_SUCCESS;
661545
         else if (code == CLD_EXITED)
661545
                 f = BUSNAME_FAILURE_EXIT_CODE;
661545
diff --git a/src/core/mount.c b/src/core/mount.c
661545
index 8a25ebd163..bfbfc10731 100644
661545
--- a/src/core/mount.c
661545
+++ b/src/core/mount.c
661545
@@ -1203,7 +1203,7 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
661545
 
661545
         m->control_pid = 0;
661545
 
661545
-        if (is_clean_exit(code, status, NULL))
661545
+        if (is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL))
661545
                 f = MOUNT_SUCCESS;
661545
         else if (code == CLD_EXITED)
661545
                 f = MOUNT_FAILURE_EXIT_CODE;
661545
diff --git a/src/core/service.c b/src/core/service.c
661545
index 6b61ccac18..f7b859d076 100644
661545
--- a/src/core/service.c
661545
+++ b/src/core/service.c
661545
@@ -2632,7 +2632,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
661545
         assert(s);
661545
         assert(pid >= 0);
661545
 
661545
-        if (UNIT(s)->fragment_path ? is_clean_exit(code, status, &s->success_status) :
661545
+        if (UNIT(s)->fragment_path ? is_clean_exit(code, status, s->type == SERVICE_ONESHOT ? EXIT_CLEAN_COMMAND : EXIT_CLEAN_DAEMON, &s->success_status) :
661545
                                      is_clean_exit_lsb(code, status, &s->success_status))
661545
                 f = SERVICE_SUCCESS;
661545
         else if (code == CLD_EXITED)
661545
diff --git a/src/core/socket.c b/src/core/socket.c
661545
index 8489575de6..1e8ae0a6e5 100644
661545
--- a/src/core/socket.c
661545
+++ b/src/core/socket.c
661545
@@ -2344,7 +2344,7 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
661545
 
661545
         s->control_pid = 0;
661545
 
661545
-        if (is_clean_exit(code, status, NULL))
661545
+        if (is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL))
661545
                 f = SOCKET_SUCCESS;
661545
         else if (code == CLD_EXITED)
661545
                 f = SOCKET_FAILURE_EXIT_CODE;
661545
diff --git a/src/core/swap.c b/src/core/swap.c
661545
index 1f69736aa3..757a8d45c5 100644
661545
--- a/src/core/swap.c
661545
+++ b/src/core/swap.c
661545
@@ -972,7 +972,7 @@ static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) {
661545
 
661545
         s->control_pid = 0;
661545
 
661545
-        if (is_clean_exit(code, status, NULL))
661545
+        if (is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL))
661545
                 f = SWAP_SUCCESS;
661545
         else if (code == CLD_EXITED)
661545
                 f = SWAP_FAILURE_EXIT_CODE;
661545
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
661545
index 57b47021e4..db9ae391b8 100644
661545
--- a/src/remount-fs/remount-fs.c
661545
+++ b/src/remount-fs/remount-fs.c
661545
@@ -142,7 +142,7 @@ int main(int argc, char *argv[]) {
661545
 
661545
                 s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid));
661545
                 if (s) {
661545
-                        if (!is_clean_exit(si.si_code, si.si_status, NULL)) {
661545
+                        if (!is_clean_exit(si.si_code, si.si_status, EXIT_CLEAN_COMMAND, NULL)) {
661545
                                 if (si.si_code == CLD_EXITED)
661545
                                         log_error("/bin/mount for %s exited with exit status %i.", s, si.si_status);
661545
                                 else
661545
diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c
661545
index 90c83a47a8..ab09550d7a 100644
661545
--- a/src/shared/exit-status.c
661545
+++ b/src/shared/exit-status.c
661545
@@ -180,22 +180,17 @@ const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level) {
661545
         return NULL;
661545
 }
661545
 
661545
-
661545
-bool is_clean_exit(int code, int status, ExitStatusSet *success_status) {
661545
+bool is_clean_exit(int code, int status, ExitClean clean, ExitStatusSet *success_status) {
661545
 
661545
         if (code == CLD_EXITED)
661545
                 return status == 0 ||
661545
                        (success_status &&
661545
                        set_contains(success_status->status, INT_TO_PTR(status)));
661545
 
661545
-        /* If a daemon does not implement handlers for some of the
661545
-         * signals that's not considered an unclean shutdown */
661545
+        /* If a daemon does not implement handlers for some of the signals that's not considered an unclean shutdown */
661545
         if (code == CLD_KILLED)
661545
                 return
661545
-                        status == SIGHUP ||
661545
-                        status == SIGINT ||
661545
-                        status == SIGTERM ||
661545
-                        status == SIGPIPE ||
661545
+                        (clean == EXIT_CLEAN_DAEMON && IN_SET(status, SIGHUP, SIGINT, SIGTERM, SIGPIPE)) ||
661545
                         (success_status &&
661545
                         set_contains(success_status->signal, INT_TO_PTR(status)));
661545
 
661545
@@ -204,7 +199,7 @@ bool is_clean_exit(int code, int status, ExitStatusSet *success_status) {
661545
 
661545
 bool is_clean_exit_lsb(int code, int status, ExitStatusSet *success_status) {
661545
 
661545
-        if (is_clean_exit(code, status, success_status))
661545
+        if (is_clean_exit(code, status, EXIT_CLEAN_DAEMON, success_status))
661545
                 return true;
661545
 
661545
         return
661545
diff --git a/src/shared/exit-status.h b/src/shared/exit-status.h
661545
index 1d774f25dc..f7953aecb1 100644
661545
--- a/src/shared/exit-status.h
661545
+++ b/src/shared/exit-status.h
661545
@@ -95,7 +95,12 @@ typedef struct ExitStatusSet {
661545
 
661545
 const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level) _const_;
661545
 
661545
-bool is_clean_exit(int code, int status, ExitStatusSet *success_status);
661545
+typedef enum ExitClean {
661545
+        EXIT_CLEAN_DAEMON,
661545
+        EXIT_CLEAN_COMMAND,
661545
+} ExitClean;
661545
+
661545
+bool is_clean_exit(int code, int status, ExitClean clean, ExitStatusSet *success_status);
661545
 bool is_clean_exit_lsb(int code, int status, ExitStatusSet *success_status);
661545
 
661545
 void exit_status_set_free(ExitStatusSet *x);