Skip to content

Commit 7347b3d

Browse files
lclgoyuwata
authored andcommitted
main: log which process send SIGNAL to PID1
This can help users to figure out what makes systemd freeze. 1. Someone kills systemd accidentally, then the sender_pid won't be 1; 2. systemd triggers segfault or assert, then the sender_pid will be 1;
1 parent 4db6256 commit 7347b3d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/core/main.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ _noreturn_ static void freeze_or_exit_or_reboot(void) {
228228
freeze();
229229
}
230230

231-
_noreturn_ static void crash(int sig) {
231+
_noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {
232232
struct sigaction sa;
233233
pid_t pid;
234234

@@ -273,6 +273,14 @@ _noreturn_ static void crash(int sig) {
273273
siginfo_t status;
274274
int r;
275275

276+
if (siginfo) {
277+
_cleanup_free_ char *cmdline = NULL;
278+
pid_t sender_pid = siginfo->si_pid;
279+
280+
(void) get_process_cmdline(sender_pid, SIZE_MAX, 0, &cmdline);
281+
log_emergency("Caught <%s> from PID "PID_FMT" (%s)", signal_to_string(sig), sender_pid, strna(cmdline));
282+
}
283+
276284
/* Order things nicely. */
277285
r = wait_for_terminate(pid, &status);
278286
if (r < 0)
@@ -330,8 +338,8 @@ _noreturn_ static void crash(int sig) {
330338

331339
static void install_crash_handler(void) {
332340
static const struct sigaction sa = {
333-
.sa_handler = crash,
334-
.sa_flags = SA_NODEFER, /* So that we can raise the signal again from the signal handler */
341+
.sa_sigaction = crash,
342+
.sa_flags = SA_NODEFER | SA_SIGINFO, /* So that we can raise the signal again from the signal handler */
335343
};
336344
int r;
337345

0 commit comments

Comments
 (0)