From 91bbd9b796ec9a2926660fd0e1c9a1b326a1a98a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 13 Nov 2018 22:10:38 +0100 Subject: core: make log messages about unit processes exiting recognizable --- catalog/systemd.catalog.in | 9 +++++++++ src/core/mount.c | 7 +++++-- src/core/service.c | 30 ++++++++++++------------------ src/core/socket.c | 8 +++++--- src/core/swap.c | 7 +++++-- src/core/unit.c | 29 +++++++++++++++++++++++++++++ src/core/unit.h | 1 + src/systemd/sd-messages.h | 3 +++ 8 files changed, 69 insertions(+), 25 deletions(-) diff --git a/catalog/systemd.catalog.in b/catalog/systemd.catalog.in index 1e64209e9c..c99da0a634 100644 --- a/catalog/systemd.catalog.in +++ b/catalog/systemd.catalog.in @@ -359,6 +359,15 @@ Support: %SUPPORT_URL% The unit @UNIT@ has entered the 'failed' state with result '@UNIT_RESULT@'. +-- 98e322203f7a4ed290d09fe03c09fe15 +Subject: Unit process exited +Defined-By: systemd +Support: %SUPPORT_URL% + +An @COMMAND@= process belonging to unit @UNIT@ has exited. + +The process' exit code is '@EXIT_CODE@' and its exit status is @EXIT_STATUS@. + -- 50876a9db00f4c40bde1a2ad381c3a1b Subject: The system is configured in a way that might cause problems Defined-By: systemd diff --git a/src/core/mount.c b/src/core/mount.c index e13b07d33b..002127bf10 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -1270,8 +1270,11 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) { m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID; } - log_unit_full(u, f == MOUNT_SUCCESS ? LOG_DEBUG : LOG_NOTICE, 0, - "Mount process exited, code=%s status=%i", sigchld_code_to_string(code), status); + unit_log_process_exit( + u, f == MOUNT_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + "Mount process", + mount_exec_command_to_string(m->control_command_id), + code, status); /* Note that due to the io event priority logic, we can be sure the new mountinfo is loaded * before we process the SIGCHLD for the mount command. */ diff --git a/src/core/service.c b/src/core/service.c index c008062411..49a1131c38 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3233,21 +3233,13 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { /* 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. However, if the service - * died due to a signal, then it most likely didn't say anything about any reason, hence let's raise - * our log level to WARNING then. */ - - log_struct(f == SERVICE_SUCCESS ? LOG_DEBUG : - (code == CLD_EXITED ? LOG_NOTICE : LOG_WARNING), - LOG_UNIT_MESSAGE(u, "Main process exited, code=%s, status=%i/%s", - sigchld_code_to_string(code), status, - strna(code == CLD_EXITED - ? exit_status_to_string(status, EXIT_STATUS_FULL) - : signal_to_string(status))), - "EXIT_CODE=%s", sigchld_code_to_string(code), - "EXIT_STATUS=%i", status, - LOG_UNIT_ID(u), - LOG_UNIT_INVOCATION_ID(u)); + * 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, + "Main process", + service_exec_command_to_string(SERVICE_EXEC_START), + code, status); if (s->result == SERVICE_SUCCESS) s->result = f; @@ -3336,9 +3328,11 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { f = SERVICE_SUCCESS; } - log_unit_full(u, f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE, 0, - "Control process exited, code=%s status=%i", - sigchld_code_to_string(code), status); + unit_log_process_exit( + u, f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + "Control process", + service_exec_command_to_string(s->control_command_id), + code, status); if (s->result == SERVICE_SUCCESS) s->result = f; diff --git a/src/core/socket.c b/src/core/socket.c index 5d44ce3fb1..de1a558023 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -2968,9 +2968,11 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) { f = SOCKET_SUCCESS; } - log_unit_full(u, f == SOCKET_SUCCESS ? LOG_DEBUG : LOG_NOTICE, 0, - "Control process exited, code=%s status=%i", - sigchld_code_to_string(code), status); + unit_log_process_exit( + u, f == SOCKET_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + "Control process", + socket_exec_command_to_string(s->control_command_id), + code, status); if (s->result == SOCKET_SUCCESS) s->result = f; diff --git a/src/core/swap.c b/src/core/swap.c index d3d0e40e2d..40517f2aad 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -1011,8 +1011,11 @@ static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) { s->control_command_id = _SWAP_EXEC_COMMAND_INVALID; } - log_unit_full(u, f == SWAP_SUCCESS ? LOG_DEBUG : LOG_NOTICE, 0, - "Swap process exited, code=%s status=%i", sigchld_code_to_string(code), status); + unit_log_process_exit( + u, f == SWAP_SUCCESS ? LOG_DEBUG : LOG_NOTICE, + "Swap process", + swap_exec_command_to_string(s->control_command_id), + code, status); switch (s->state) { diff --git a/src/core/unit.c b/src/core/unit.c index 88d20a1b9f..54a1bd963c 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -5456,6 +5456,35 @@ void unit_log_failure(Unit *u, const char *result) { "UNIT_RESULT=%s", result); } +void unit_log_process_exit( + Unit *u, + int level, + const char *kind, + const char *command, + int code, + int status) { + + assert(u); + assert(kind); + + if (code != CLD_EXITED) + level = LOG_WARNING; + + log_struct(level, + "MESSAGE_ID=" SD_MESSAGE_UNIT_PROCESS_EXIT_STR, + LOG_UNIT_MESSAGE(u, "%s exited, code=%s, status=%i/%s", + kind, + sigchld_code_to_string(code), status, + strna(code == CLD_EXITED + ? exit_status_to_string(status, EXIT_STATUS_FULL) + : signal_to_string(status))), + "EXIT_CODE=%s", sigchld_code_to_string(code), + "EXIT_STATUS=%i", status, + "COMMAND=%s", strna(command), + LOG_UNIT_ID(u), + LOG_UNIT_INVOCATION_ID(u)); +} + static const char* const collect_mode_table[_COLLECT_MODE_MAX] = { [COLLECT_INACTIVE] = "inactive", [COLLECT_INACTIVE_OR_FAILED] = "inactive-or-failed", diff --git a/src/core/unit.h b/src/core/unit.h index e3f859d5ef..da48438519 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -807,6 +807,7 @@ const char *unit_label_path(Unit *u); int unit_pid_attachable(Unit *unit, pid_t pid, sd_bus_error *error); void unit_log_failure(Unit *u, const char *result); +void unit_log_process_exit(Unit *u, int level, const char *kind, const char *command, int code, int status); /* Macros which append UNIT= or USER_UNIT= to the message */ diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h index 1ea79fc661..9ac263c89f 100644 --- a/src/systemd/sd-messages.h +++ b/src/systemd/sd-messages.h @@ -113,6 +113,9 @@ _SD_BEGIN_DECLARATIONS; #define SD_MESSAGE_SPAWN_FAILED SD_ID128_MAKE(64,12,57,65,1c,1b,4e,c9,a8,62,4d,7a,40,a9,e1,e7) #define SD_MESSAGE_SPAWN_FAILED_STR SD_ID128_MAKE_STR(64,12,57,65,1c,1b,4e,c9,a8,62,4d,7a,40,a9,e1,e7) +#define SD_MESSAGE_UNIT_PROCESS_EXIT SD_ID128_MAKE(98,e3,22,20,3f,7a,4e,d2,90,d0,9f,e0,3c,09,fe,15) +#define SD_MESSAGE_UNIT_PROCESS_EXIT_STR SD_ID128_MAKE_STR(98,e3,22,20,3f,7a,4e,d2,90,d0,9f,e0,3c,09,fe,15) + #define SD_MESSAGE_FORWARD_SYSLOG_MISSED SD_ID128_MAKE(00,27,22,9c,a0,64,41,81,a7,6c,4e,92,45,8a,fa,2e) #define SD_MESSAGE_FORWARD_SYSLOG_MISSED_STR \ SD_ID128_MAKE_STR(00,27,22,9c,a0,64,41,81,a7,6c,4e,92,45,8a,fa,2e) -- cgit v1.2.1