summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-10-10 22:07:30 +0200
committerLennart Poettering <lennart@poettering.net>2016-10-10 22:57:01 +0200
commit1f0958f640b87175cd547c1e69084cfe54a22e9d (patch)
treee1a49f2a31920394f951f3d14f0e7e06125faab5 /src/basic
parent38107f5a4ad5ab148054910040d5d548a4c7a805 (diff)
core: when determining whether a process exit status is clean, consider whether it is a command or a daemon
SIGTERM should be considered a clean exit code for daemons (i.e. long-running processes, as a daemon without SIGTERM handler may be shut down without issues via SIGTERM still) while it should not be considered a clean exit code for commands (i.e. short-running processes). Let's add two different clean checking modes for this, and use the right one at the appropriate places. Fixes: #4275
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/exit-status.c8
-rw-r--r--src/basic/exit-status.h7
2 files changed, 10 insertions, 5 deletions
diff --git a/src/basic/exit-status.c b/src/basic/exit-status.c
index 96d4619da6..59557f8afe 100644
--- a/src/basic/exit-status.c
+++ b/src/basic/exit-status.c
@@ -177,17 +177,17 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
return NULL;
}
-bool is_clean_exit(int code, int status, ExitStatusSet *success_status) {
+bool is_clean_exit(int code, int status, ExitClean clean, ExitStatusSet *success_status) {
if (code == CLD_EXITED)
return status == 0 ||
(success_status &&
set_contains(success_status->status, INT_TO_PTR(status)));
- /* If a daemon does not implement handlers for some of the
- * signals that's not considered an unclean shutdown */
+ /* If a daemon does not implement handlers for some of the signals that's not considered an unclean shutdown */
if (code == CLD_KILLED)
- return IN_SET(status, SIGHUP, SIGINT, SIGTERM, SIGPIPE) ||
+ return
+ (clean == EXIT_CLEAN_DAEMON && IN_SET(status, SIGHUP, SIGINT, SIGTERM, SIGPIPE)) ||
(success_status &&
set_contains(success_status->signal, INT_TO_PTR(status)));
diff --git a/src/basic/exit-status.h b/src/basic/exit-status.h
index b3baa50cf4..0cfdfd7891 100644
--- a/src/basic/exit-status.h
+++ b/src/basic/exit-status.h
@@ -98,7 +98,12 @@ typedef struct ExitStatusSet {
const char* exit_status_to_string(int status, ExitStatusLevel level) _const_;
-bool is_clean_exit(int code, int status, ExitStatusSet *success_status);
+typedef enum ExitClean {
+ EXIT_CLEAN_DAEMON,
+ EXIT_CLEAN_COMMAND,
+} ExitClean;
+
+bool is_clean_exit(int code, int status, ExitClean clean, ExitStatusSet *success_status);
void exit_status_set_free(ExitStatusSet *x);
bool exit_status_set_is_empty(ExitStatusSet *x);