From 2561e2a35601383bfba30da58d378303cb9e39aa Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 7 Aug 2024 21:23:37 +0200 Subject: [PATCH 1/3] mkosi: Disable debuginfod We generally don't care about library debuginfo so let's just disable debuginfod so it doesn't get in the way when debugging. We use /root/.gdbinit as the systemwide gdbinit location is distribution specific. --- mkosi.extra/root/.gdbinit | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 mkosi.extra/root/.gdbinit diff --git a/mkosi.extra/root/.gdbinit b/mkosi.extra/root/.gdbinit new file mode 100644 index 0000000000..e576a26803 --- /dev/null +++ b/mkosi.extra/root/.gdbinit @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +set debuginfod enabled off From bc3477fdc561f6eda5e73a357e2049d46f2b3077 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 7 Aug 2024 20:44:38 +0200 Subject: [PATCH 2/3] crash-handler: Call vhangup on /dev/console before spawning crash shell When pid 1 crashes, the getty unit for the console will happily keep running which means we end up with two shells competing for the same tty. Let's call vhangup on /dev/console to kill every other process attached to the console before we spawn the crash shell. The getty units have Restart=always but lucky for us, pid 1 just crashed in fire and flames so it isn't actually able to restart the getty unit. --- src/basic/terminal-util.c | 12 ++++++++++++ src/basic/terminal-util.h | 1 + src/core/crash-handler.c | 1 + 3 files changed, 14 insertions(+) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index c2ff3ca85a..1f5204cca5 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -434,6 +434,18 @@ int terminal_vhangup_fd(int fd) { return RET_NERRNO(ioctl(fd, TIOCVHANGUP)); } +int terminal_vhangup(const char *tty) { + _cleanup_close_ int fd = -EBADF; + + assert(tty); + + fd = open_terminal(tty, O_RDWR|O_NOCTTY|O_CLOEXEC); + if (fd < 0) + return fd; + + return terminal_vhangup_fd(fd); +} + int vt_disallocate(const char *tty_path) { assert(tty_path); diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index 84d4731ea8..f8a30bbb64 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -68,6 +68,7 @@ const char* color_mode_to_string(ColorMode m) _const_; ColorMode color_mode_from_string(const char *s) _pure_; int terminal_vhangup_fd(int fd); +int terminal_vhangup(const char *tty); int terminal_set_size_fd(int fd, const char *ident, unsigned rows, unsigned cols); int proc_cmdline_tty_size(const char *tty, unsigned *ret_rows, unsigned *ret_cols); diff --git a/src/core/crash-handler.c b/src/core/crash-handler.c index 056cb103fe..26e59b92d2 100644 --- a/src/core/crash-handler.c +++ b/src/core/crash-handler.c @@ -165,6 +165,7 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) { "MESSAGE_ID=" SD_MESSAGE_CRASH_SHELL_FORK_FAILED_STR); else if (pid == 0) { (void) setsid(); + (void) terminal_vhangup("/dev/console"); (void) make_console_stdio(); (void) rlimit_nofile_safe(); (void) execle("/bin/sh", "/bin/sh", NULL, environ); From 570a11eb9d534ab3825855a50775d268283082be Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 7 Aug 2024 20:48:09 +0200 Subject: [PATCH 3/3] crash-handler: Drop 10s sleep before we spawn the crash shell It pointlessly delays getting to the crash shell so let's drop the 10s sleep. --- man/systemd.xml | 5 ++--- src/core/crash-handler.c | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/man/systemd.xml b/man/systemd.xml index af3d57b657..58e76eecb2 100644 --- a/man/systemd.xml +++ b/man/systemd.xml @@ -843,9 +843,8 @@ Takes a boolean argument or enables the option if specified without an argument. If enabled, the system manager (PID 1) spawns a shell - when it crashes, after a 10s delay. Otherwise, no shell is spawned. Defaults - to disabled, for security reasons, as the shell is not protected by password - authentication. + when it crashes. Otherwise, no shell is spawned. Defaults to disabled, for + security reasons, as the shell is not protected by password authentication. diff --git a/src/core/crash-handler.c b/src/core/crash-handler.c index 26e59b92d2..a9425c0790 100644 --- a/src/core/crash-handler.c +++ b/src/core/crash-handler.c @@ -155,9 +155,6 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) { (void) sigaction(SIGCHLD, &sa, NULL); if (arg_crash_shell) { - log_notice("Executing crash shell in 10s..."); - (void) sleep(10); - pid = raw_clone(SIGCHLD); if (pid < 0) log_struct_errno(LOG_EMERG, errno,