summaryrefslogtreecommitdiffstats
path: root/src/basic
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2024-08-07 20:44:38 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2024-08-07 21:24:57 +0200
commitbc3477fdc561f6eda5e73a357e2049d46f2b3077 (patch)
treef47ad8c16636a5117098c23f74e59206d64ce93d /src/basic
parentmkosi: Disable debuginfod (diff)
downloadsystemd-bc3477fdc561f6eda5e73a357e2049d46f2b3077.tar.xz
systemd-bc3477fdc561f6eda5e73a357e2049d46f2b3077.zip
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.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/terminal-util.c12
-rw-r--r--src/basic/terminal-util.h1
2 files changed, 13 insertions, 0 deletions
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);