]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: make log messages about units entering a 'failed' state recognizable
authorLennart Poettering <lennart@poettering.net>
Tue, 13 Nov 2018 20:25:22 +0000 (21:25 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 16 Nov 2018 14:22:48 +0000 (15:22 +0100)
Let's make this recognizable, and carry result information in a
structure fashion.

12 files changed:
catalog/systemd.catalog.in
src/core/automount.c
src/core/mount.c
src/core/path.c
src/core/scope.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/timer.c
src/core/unit.c
src/core/unit.h
src/systemd/sd-messages.h

index 2136c93d02dc85484da75678c7c7b7dba8a07738..1e64209e9cd3f179840087eeebd913eefe482760 100644 (file)
@@ -352,6 +352,13 @@ Support: %SUPPORT_URL%
 
 The unit @UNIT@ completed and consumed the indicated resources.
 
+-- d9b373ed55a64feb8242e02dbe79a49c
+Subject: Unit failed
+Defined-By: systemd
+Support: %SUPPORT_URL%
+
+The unit @UNIT@ has entered the 'failed' state with result '@UNIT_RESULT@'.
+
 -- 50876a9db00f4c40bde1a2ad381c3a1b
 Subject: The system is configured in a way that might cause problems
 Defined-By: systemd
index eaacf5e8b9faa42d1ae8caf649b32d67a21174d8..57e6a985fd0486005108a881608748164e32ea5c 100644 (file)
@@ -316,7 +316,7 @@ static void automount_enter_dead(Automount *a, AutomountResult f) {
                 a->result = f;
 
         if (a->result != AUTOMOUNT_SUCCESS)
-                log_unit_warning(UNIT(a), "Failed with result '%s'.", automount_result_to_string(a->result));
+                unit_log_failure(UNIT(a), automount_result_to_string(a->result));
 
         automount_set_state(a, a->result != AUTOMOUNT_SUCCESS ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
 }
index 5e1ef1e6acee52edd2e6a49fdb60f4281b66b311..e13b07d33b235df276855040a04480cddaeb6ca8 100644 (file)
@@ -800,7 +800,7 @@ static void mount_enter_dead(Mount *m, MountResult f) {
                 m->result = f;
 
         if (m->result != MOUNT_SUCCESS)
-                log_unit_warning(UNIT(m), "Failed with result '%s'.", mount_result_to_string(m->result));
+                unit_log_failure(UNIT(m), mount_result_to_string(m->result));
 
         mount_set_state(m, m->result != MOUNT_SUCCESS ? MOUNT_FAILED : MOUNT_DEAD);
 
index 258e3a00cb2a6a837943f975a1b88bc04f700f19..a134fc288c45cc38798daa1069c0f28eabebcc1b 100644 (file)
@@ -450,7 +450,7 @@ static void path_enter_dead(Path *p, PathResult f) {
                 p->result = f;
 
         if (p->result != PATH_SUCCESS)
-                log_unit_warning(UNIT(p), "Failed with result '%s'.", path_result_to_string(p->result));
+                unit_log_failure(UNIT(p), path_result_to_string(p->result));
 
         path_set_state(p, p->result != PATH_SUCCESS ? PATH_FAILED : PATH_DEAD);
 }
index 7883d19325bfce5401282342a59bd968f91bdf29..9ff082df3aaa166b497591713dab1176d55c3619 100644 (file)
@@ -241,7 +241,7 @@ static void scope_enter_dead(Scope *s, ScopeResult f) {
                 s->result = f;
 
         if (s->result != SCOPE_SUCCESS)
-                log_unit_warning(UNIT(s), "Failed with result '%s'.", scope_result_to_string(s->result));
+                unit_log_failure(UNIT(s), scope_result_to_string(s->result));
 
         scope_set_state(s, s->result != SCOPE_SUCCESS ? SCOPE_FAILED : SCOPE_DEAD);
 }
index 50ceda7ac60f33a99025660653ee0857e300fd63..c008062411fcc9fe63d67eabfc40f5180052654a 100644 (file)
@@ -1700,7 +1700,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
                 s->result = f;
 
         if (s->result != SERVICE_SUCCESS)
-                log_unit_warning(UNIT(s), "Failed with result '%s'.", service_result_to_string(s->result));
+                unit_log_failure(UNIT(s), service_result_to_string(s->result));
 
         if (allow_restart && service_shall_restart(s))
                 s->will_auto_restart = true;
index 407ad1352c81fd046a8981ad7e6a8d763fc23ac3..5d44ce3fb18eb8dbb17da7e7048c7ac65e09b564 100644 (file)
@@ -1986,7 +1986,7 @@ static void socket_enter_dead(Socket *s, SocketResult f) {
                 s->result = f;
 
         if (s->result != SOCKET_SUCCESS)
-                log_unit_warning(UNIT(s), "Failed with result '%s'.", socket_result_to_string(s->result));
+                unit_log_failure(UNIT(s), socket_result_to_string(s->result));
 
         socket_set_state(s, s->result != SOCKET_SUCCESS ? SOCKET_FAILED : SOCKET_DEAD);
 
index ff1412879f30ea46cf0e2e31944db8032f0b12c9..d3d0e40e2d7b352879c7fb1a5a66c472722820ea 100644 (file)
@@ -654,7 +654,7 @@ static void swap_enter_dead(Swap *s, SwapResult f) {
                 s->result = f;
 
         if (s->result != SWAP_SUCCESS)
-                log_unit_warning(UNIT(s), "Failed with result '%s'.", swap_result_to_string(s->result));
+                unit_log_failure(UNIT(s), swap_result_to_string(s->result));
 
         swap_set_state(s, s->result != SWAP_SUCCESS ? SWAP_FAILED : SWAP_DEAD);
 
index bd119cabd371cf2f5ff47c04716c92c4780a531a..98ba868bb106a79e64c21f9915a0065eadfc82e2 100644 (file)
@@ -289,7 +289,7 @@ static void timer_enter_dead(Timer *t, TimerResult f) {
                 t->result = f;
 
         if (t->result != TIMER_SUCCESS)
-                log_unit_warning(UNIT(t), "Failed with result '%s'.", timer_result_to_string(t->result));
+                unit_log_failure(UNIT(t), timer_result_to_string(t->result));
 
         timer_set_state(t, t->result != TIMER_SUCCESS ? TIMER_FAILED : TIMER_DEAD);
 }
index 1dc62768a2424cc26e4b9a10f42c57a8bf3f84d6..88d20a1b9f1b397dd2dcb78767bf7db3d7bb158b 100644 (file)
@@ -5444,6 +5444,18 @@ int unit_pid_attachable(Unit *u, pid_t pid, sd_bus_error *error) {
         return 0;
 }
 
+void unit_log_failure(Unit *u, const char *result) {
+        assert(u);
+        assert(result);
+
+        log_struct(LOG_WARNING,
+                   "MESSAGE_ID=" SD_MESSAGE_UNIT_FAILURE_RESULT_STR,
+                   LOG_UNIT_ID(u),
+                   LOG_UNIT_INVOCATION_ID(u),
+                   LOG_UNIT_MESSAGE(u, "Failed with result '%s'.", result),
+                   "UNIT_RESULT=%s", result);
+}
+
 static const char* const collect_mode_table[_COLLECT_MODE_MAX] = {
         [COLLECT_INACTIVE] = "inactive",
         [COLLECT_INACTIVE_OR_FAILED] = "inactive-or-failed",
index eb8f1f5653cea162d390209c20228b2079dcb4cd..e3f859d5efe611085923f6f1faae9e0eb9568a98 100644 (file)
@@ -806,6 +806,8 @@ 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);
+
 /* Macros which append UNIT= or USER_UNIT= to the message */
 
 #define log_unit_full(unit, level, error, ...)                          \
index 749038aed7ff9d740c0a108ef95dd34e760f28dd..1ea79fc6619cd1aac07d6c7b0d050720eadccedf 100644 (file)
@@ -106,6 +106,10 @@ _SD_BEGIN_DECLARATIONS;
 #define SD_MESSAGE_UNIT_RESOURCES         SD_ID128_MAKE(ae,8f,7b,86,6b,03,47,b9,af,31,fe,1c,80,b1,27,c0)
 #define SD_MESSAGE_UNIT_RESOURCES_STR     SD_ID128_MAKE_STR(ae,8f,7b,86,6b,03,47,b9,af,31,fe,1c,80,b1,27,c0)
 
+#define SD_MESSAGE_UNIT_FAILURE_RESULT    SD_ID128_MAKE(d9,b3,73,ed,55,a6,4f,eb,82,42,e0,2d,be,79,a4,9c)
+#define SD_MESSAGE_UNIT_FAILURE_RESULT_STR \
+                                          SD_ID128_MAKE_STR(d9,b3,73,ed,55,a6,4f,eb,82,42,e0,2d,be,79,a4,9c)
+
 #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)