From 5cc2cd1cd8faf01258a2130e38229fedc35e6cef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 21 Aug 2019 16:20:59 +0200 Subject: [PATCH] pid1: always log successfull process termination quietly Fixes #13372. --- src/core/mount.c | 3 ++- src/core/service.c | 10 ++++------ src/core/socket.c | 3 ++- src/core/swap.c | 3 ++- src/core/unit.c | 14 ++++++++++++-- src/core/unit.h | 2 +- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index fb6a516..4f37d3e 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -1323,9 +1323,10 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) { } unit_log_process_exit( - u, f == MOUNT_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + u, "Mount process", mount_exec_command_to_string(m->control_command_id), + f == MOUNT_SUCCESS, code, status); /* Note that due to the io event priority logic, we can be sure the new mountinfo is loaded diff --git a/src/core/service.c b/src/core/service.c index d189322..d8cfb40 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3417,14 +3417,11 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { f = SERVICE_SUCCESS; } - /* When this is a successful exit, let's log about the exit code on DEBUG level. If this is a failure - * and the process exited on its own via exit(), then let's make this a NOTICE, under the assumption - * that the service already logged the reason at a higher log level on its own. (Internally, - * unit_log_process_exit() will possibly bump this to WARNING if the service died due to a signal.) */ unit_log_process_exit( - u, f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + u, "Main process", service_exec_command_to_string(SERVICE_EXEC_START), + f == SERVICE_SUCCESS, code, status); if (s->result == SERVICE_SUCCESS) @@ -3519,9 +3516,10 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { } unit_log_process_exit( - u, f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + u, "Control process", service_exec_command_to_string(s->control_command_id), + f == SERVICE_SUCCESS, code, status); if (s->state != SERVICE_RELOAD && s->result == SERVICE_SUCCESS) diff --git a/src/core/socket.c b/src/core/socket.c index cc3dc59..46fe405 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -3014,9 +3014,10 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) { } unit_log_process_exit( - u, f == SOCKET_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + u, "Control process", socket_exec_command_to_string(s->control_command_id), + f == SOCKET_SUCCESS, code, status); if (s->result == SOCKET_SUCCESS) diff --git a/src/core/swap.c b/src/core/swap.c index 303afc9..74381c0 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -1043,9 +1043,10 @@ static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) { } unit_log_process_exit( - u, f == SWAP_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + u, "Swap process", swap_exec_command_to_string(s->control_command_id), + f == SWAP_SUCCESS, code, status); switch (s->state) { diff --git a/src/core/unit.c b/src/core/unit.c index f468586..31ed473 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -5779,16 +5779,26 @@ void unit_log_skip(Unit *u, const char *result) { void unit_log_process_exit( Unit *u, - int level, const char *kind, const char *command, + bool success, int code, int status) { + int level; + assert(u); assert(kind); - if (code != CLD_EXITED) + /* If this is a successful exit, let's log about the exit code on DEBUG level. If this is a failure + * and the process exited on its own via exit(), then let's make this a NOTICE, under the assumption + * that the service already logged the reason at a higher log level on its own. Otherwise, make it a + * WARNING. */ + if (success) + level = LOG_DEBUG; + else if (code == CLD_EXITED) + level = LOG_NOTICE; + else level = LOG_WARNING; log_struct(level, diff --git a/src/core/unit.h b/src/core/unit.h index 9ad86fd..4732d72 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -852,7 +852,7 @@ static inline void unit_log_result(Unit *u, bool success, const char *result) { unit_log_failure(u, result); } -void unit_log_process_exit(Unit *u, int level, const char *kind, const char *command, int code, int status); +void unit_log_process_exit(Unit *u, const char *kind, const char *command, bool success, int code, int status); int unit_exit_status(Unit *u); int unit_success_action_exit_status(Unit *u); -- 2.7.4