Skip to content

Commit

Permalink
Journal: Add message IDs for emergency-level log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
1awesomeJ committed Aug 30, 2023
1 parent 13f0082 commit 7723895
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 36 deletions.
159 changes: 159 additions & 0 deletions catalog/systemd.catalog.in
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,165 @@ System factory reset has been initiated. The precise operation this
executes is implementation-defined, but typically has the effect of
reverting the system's state and configuration to vendor defaults.

--d9ec5e95e4b646aaaea2fd05214edbda
Subject: Exiting PID 1...
Defined-By: systemd
Support: %SUPPORT_URL%

When systemd crashes, we want to either freeze or exit or reboot.
For containers we choose the option of exiting.
The details of the crash can be obtained from the container manager.

To fix:
Check the container manager for details.

-- 3ed0163e868a4417ab8b9e210407a96c
Subject: Failed to reboot
Defined-By: systemd
Support: %SUPPORT_URL%

Reboot has failed when systemd attempted to reboot after a crash.

-- 645c735537634ae0a32b15a7c6cba7d4
Subject: Freezing execution
Defined-By: systemd
Support: %SUPPORT_URL%

Freezing execution after fatal error.

-- 5addb3a06a734d3396b794bf98fb2d01
Subject: Caught <signal>, not dumping core
Defined-By: systemd
Support: %SUPPORT_URL%

In the instance of a crash arising from corrupted memory. The signal caught is propagated, but the core is not dumped.

-- 5c9e98de4ab94c6a9d04d0ad793bd903
Subject: Caught <signal>, cannot fork for core dump
Defined-By: systemd
Support: %SUPPORT_URL%

-- 5e6f1f5e4db64a0eaee3368249d20b94
Subject: Caught <signal> from unknown sender process
Defined-By: systemd
Support: %SUPPORT_URL%

-- 83f84b35ee264f74a3896a9717af34cb
Subject: Caught <signal> from our own process
Defined-By: systemd
Support: %SUPPORT_URL%

-- 3a73a98baf5b4b199929e3226c0be783
Subject: Caught <signal> from <PID>
Defined-By: systemd
Support: %SUPPORT_URL%

-- 2ed18d4f78ca47f0a9bc25271c26adb4
Subject: Caught <signal>, waitpid() failed
Defined-By: systemd
Support: %SUPPORT_URL%

-- 56b1cd96f24246c5b607666fda952356
Subject: Caught <signal>, coredump failed (child <PID>, code=<code>, status=<status>.
Defined-By: systemd
Support: %SUPPORT_URL%

-- 4ac7566d4d7548f4981f629a28f0f829
Subject: Caught <signal>, dumped core as pid <PID>
Defined-By: systemd
Support: %SUPPORT_URL%

-- 38e8b1e039ad469291b18b44c553a5b7
Subject: Failed to fork off crash shell

Defined-By: systemd
Support: %SUPPORT_URL%

-- 872729b47dbe473eb768ccecd477beda
Subject: execle() failed
Defined-By: systemd
Support: %SUPPORT_URL%

-- 658a67adc1c940b3b3316e7e8628834a
Subject: Failed to load SELinux policy.
Defined-By: systemd
Support: %SUPPORT_URL%

-- e6f456bd92004d9580160b2207555186
Subject: Battery level critically low. Please connect your charger or the system will power off in 10 seconds.
Defined-By: systemd
Support: %SUPPORT_URL%

-- 267437d33fdd41099ad76221cc24a335
Subject: Battery level critically low, powering off.
Defined-By: systemd
Support: %SUPPORT_URL%

-- 79e05b67bc4545d1922fe47107ee60c5
Subject: Failed to run main loop
Defined-By: systemd
Support: %SUPPORT_URL%

-- dbb136b10ef4457ba47a795d62f108c9
Subject: Failed to determine <XDG_DIR> path
Defined-By: systemd
Support: %SUPPORT_URL%

-- ed158c2df8884fa584eead2d902c1032
Subject: Failed to drop capability bounding set of usermode helpers
Defined-By: systemd
Support: %SUPPORT_URL%

-- 42695b500df048298bee37159caa9f2e
Subject: Failed to drop capability bounding set
Defined-By: systemd
Support: %SUPPORT_URL%

-- bfc2430724ab44499735b4f94cca9295
Subject: Failed to disable new privileges
Defined-By: systemd
Support: %SUPPORT_URL%

-- 59288af523be43a28d494e41e26e4510
Subject: Failed to start default target <target>
Defined-By: systemd
Support: %SUPPORT_URL%

-- 689b4fcc97b4486ea5da92db69c9e314
Subject: Failed to isolate default target <target>
Defined-By: systemd
Support: %SUPPORT_URL%

-- 5ed836f1766f4a8a9fc5da45aae23b29
Subject: Failed to allocate fd set
Defined-By: systemd
Support: %SUPPORT_URL%

-- 6a40fbfbd2ba4b8db02fb40c9cd090d7
Subject: Failed to fix up PID1 environment
Defined-By: systemd
Support: %SUPPORT_URL%

-- 0e54470984ac419689743d957a119e2e
Subject: Failed to allocate manager object
Defined-By: systemd
Support: %SUPPORT_URL%

-- d67fa9f847aa4b048a2ae33535331adb
Subject: Failed to write Smack onlycap list
Defined-By: systemd
Support: %SUPPORT_URL%

-- af55a6f75b544431b72649f36ff6d62c
Subject: Critical error while doing system shutdown
Defined-By: systemd
Support: %SUPPORT_URL%

-- d18e0339efb24a068d9c1060221048c2
Subject: Failed to fork off valgrind helper
Defined-By: systemd
Support: %SUPPORT_URL%

-- 7d4958e842da4a758f6c1cdc7b36dcc5
Subject: A start job for unit @UNIT@ has begun execution
Defined-By: systemd
Expand Down
7 changes: 6 additions & 1 deletion src/basic/process-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <valgrind/valgrind.h>
#endif

#include "sd-messages.h"

#include "alloc-util.h"
#include "architecture.h"
#include "argv-util.h"
Expand Down Expand Up @@ -1049,7 +1051,10 @@ void valgrind_summary_hack(void) {
pid_t pid;
pid = raw_clone(SIGCHLD);
if (pid < 0)
log_emergency_errno(errno, "Failed to fork off valgrind helper: %m");
log_struct_errno(
LOG_EMERG, errno,
"MESSAGE_ID=" SD_MESSAGE_VALGRIND_HELPER_FORK_STR,
LOG_MESSAGE( "Failed to fork off valgrind helper: %m"));
else if (pid == 0)
exit(EXIT_SUCCESS);
else {
Expand Down
11 changes: 8 additions & 3 deletions src/battery-check/battery-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <sys/socket.h>
#include <unistd.h>

#include "sd-messages.h"

#include "battery-util.h"
#include "build.h"
#include "constants.h"
Expand Down Expand Up @@ -156,8 +158,9 @@ static int run(int argc, char *argv[]) {
}
if (r == 0)
return 0;

log_emergency("%s " BATTERY_LOW_MESSAGE, special_glyph(SPECIAL_GLYPH_LOW_BATTERY));
log_struct(LOG_EMERG,
LOG_MESSAGE("%s " BATTERY_LOW_MESSAGE, special_glyph(SPECIAL_GLYPH_LOW_BATTERY)),
"MESSAGE_ID=" SD_MESSAGE_BATTERY_LOW_WARNING_STR);

fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
Expand All @@ -178,7 +181,9 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return log_warning_errno(r, "Failed to check battery status, assuming not charged yet, powering off: %m");
if (r > 0) {
log_emergency("Battery level critically low, powering off.");
log_struct(LOG_EMERG,
LOG_MESSAGE("Battery level critically low, powering off."),
"MESSAGE_ID=" SD_MESSAGE_BATTERY_LOW_POWEROFF_STR);
return r;
}

Expand Down
64 changes: 46 additions & 18 deletions src/core/crash-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <sys/reboot.h>

#include "sd-messages.h"

#include "crash-handler.h"
#include "exit-status.h"
#include "macro.h"
Expand All @@ -19,7 +21,9 @@ _noreturn_ void freeze_or_exit_or_reboot(void) {
/* If we are running in a container, let's prefer exiting, after all we can propagate an exit code to
* the container manager, and thus inform it that something went wrong. */
if (detect_container() > 0) {
log_emergency("Exiting PID 1...");
log_struct(LOG_EMERG,
LOG_MESSAGE("Exiting PID 1..."),
"MESSAGE_ID=" SD_MESSAGE_CRASH_EXIT_STR);
_exit(EXIT_EXCEPTION);
}

Expand All @@ -29,10 +33,14 @@ _noreturn_ void freeze_or_exit_or_reboot(void) {

log_notice("Rebooting now...");
(void) reboot(RB_AUTOBOOT);
log_emergency_errno(errno, "Failed to reboot: %m");
log_struct_errno(LOG_EMERG, errno,
LOG_MESSAGE("Failed to reboot: %m"),
"MESSAGE_ID=" SD_MESSAGE_CRASH_FAILED_STR);
}

log_emergency("Freezing execution.");
log_struct(LOG_EMERG,
LOG_MESSAGE("Freezing execution."),
"MESSAGE_ID=" SD_MESSAGE_CRASH_FREEZE_STR);
sync();
freeze();
}
Expand All @@ -51,7 +59,9 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {
/* Pass this on immediately, if this is not PID 1 */
propagate_signal(sig, siginfo);
else if (!arg_dump_core)
log_emergency("Caught <%s>, not dumping core.", signal_to_string(sig));
log_struct(LOG_EMERG,
LOG_MESSAGE("Caught <%s>, not dumping core.", signal_to_string(sig)),
"MESSAGE_ID=" SD_MESSAGE_CRASH_NO_COREDUMP_STR);
else {
sa = (struct sigaction) {
.sa_handler = nop_signal_handler,
Expand All @@ -63,7 +73,9 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {

pid = raw_clone(SIGCHLD);
if (pid < 0)
log_emergency_errno(errno, "Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
log_struct_errno(LOG_EMERG, errno,
LOG_MESSAGE("Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig)),
"MESSAGE_ID=" SD_MESSAGE_CRASH_NO_FORK_STR);
else if (pid == 0) {
/* Enable default signal handler for core dump */

Expand All @@ -88,30 +100,42 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {

if (siginfo) {
if (siginfo->si_pid == 0)
log_emergency("Caught <%s> from unknown sender process.", signal_to_string(sig));
log_struct(LOG_EMERG,
LOG_MESSAGE("Caught <%s>, from unknown sender process.", signal_to_string(sig)),
"MESSAGE_ID=" SD_MESSAGE_CRASH_UNKNOWN_SIGNAL_STR);
else if (siginfo->si_pid == 1)
log_emergency("Caught <%s> from our own process.", signal_to_string(sig));
log_struct(LOG_EMERG,
LOG_MESSAGE("Caught <%s>, from our own process.", signal_to_string(sig)),
"MESSAGE_ID=" SD_MESSAGE_CRASH_SYSTEMD_SIGNAL_STR);
else
log_emergency("Caught <%s> from PID "PID_FMT".", signal_to_string(sig), siginfo->si_pid);
log_struct(LOG_EMERG,
LOG_MESSAGE("Caught <%s> from PID "PID_FMT".", signal_to_string(sig), siginfo->si_pid),
"MESSAGE_ID=" SD_MESSAGE_CRASH_PROCESS_SIGNAL_STR);
}

/* Order things nicely. */
r = wait_for_terminate(pid, &status);
if (r < 0)
log_emergency_errno(r, "Caught <%s>, waitpid() failed: %m", signal_to_string(sig));
log_struct_errno(LOG_EMERG, r,
LOG_MESSAGE("Caught <%s>, waitpid() failed: %m", signal_to_string(sig)),
"MESSAGE_ID=" SD_MESSAGE_CRASH_WAITPID_FAILED_STR);
else if (status.si_code != CLD_DUMPED) {
const char *s = status.si_code == CLD_EXITED
? exit_status_to_string(status.si_status, EXIT_STATUS_LIBC)
: signal_to_string(status.si_status);

log_emergency("Caught <%s>, core dump failed (child "PID_FMT", code=%s, status=%i/%s).",
signal_to_string(sig),
pid,
sigchld_code_to_string(status.si_code),
status.si_status, strna(s));
log_struct(LOG_EMERG,
LOG_MESSAGE("Caught <%s>, core dump failed (child "PID_FMT", code=%s, status=%i/%s).",
signal_to_string(sig),
pid,
sigchld_code_to_string(status.si_code),
status.si_status, strna(s)),
"MESSAGE_ID=" SD_MESSAGE_CRASH_COREDUMP_FAILED_STR);
} else
log_emergency("Caught <%s>, dumped core as pid "PID_FMT".",
signal_to_string(sig), pid);
log_struct(LOG_EMERG,
LOG_MESSAGE("Caught <%s>, dumped core as pid "PID_FMT".",
signal_to_string(sig), pid),
"MESSAGE_ID=" SD_MESSAGE_CRASH_COREDUMP_PID_STR);
}
}

Expand All @@ -132,14 +156,18 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {

pid = raw_clone(SIGCHLD);
if (pid < 0)
log_emergency_errno(errno, "Failed to fork off crash shell: %m");
log_struct_errno(LOG_EMERG, errno,
LOG_MESSAGE("Failed to fork off crash shell: %m"),
"MESSAGE_ID=" SD_MESSAGE_CRASH_SHELL_FORK_FAILED_STR);
else if (pid == 0) {
(void) setsid();
(void) make_console_stdio();
(void) rlimit_nofile_safe();
(void) execle("/bin/sh", "/bin/sh", NULL, environ);

log_emergency_errno(errno, "execle() failed: %m");
log_struct_errno(LOG_EMERG, errno,
LOG_MESSAGE("execle() failed: %m"),
"MESSAGE_ID=" SD_MESSAGE_CRASH_EXECLE_FAILED_STR);
_exit(EXIT_EXCEPTION);
} else {
log_info("Spawned crash shell as PID "PID_FMT".", pid);
Expand Down

0 comments on commit 7723895

Please sign in to comment.