summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-05-14 04:35:51 +0200
committerLennart Poettering <lennart@poettering.net>2010-05-14 04:35:51 +0200
commitea5652c296f325eceea351c19bf81a783cea4537 (patch)
tree3bcd020b653a51d6d66f354e9dfb96ee96d21ee2 /main.c
parent64c1b5bf9c5777261bdf4058b6cd1cb5de193d5b (diff)
main: acquire console before execing crash shell
Diffstat (limited to 'main.c')
-rw-r--r--main.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/main.c b/main.c
index b0b3cfb580..6c730eb435 100644
--- a/main.c
+++ b/main.c
@@ -136,6 +136,23 @@ _noreturn static void crash(int sig) {
if ((pid = fork()) < 0)
log_error("Failed to fork off crash shell: %s", strerror(errno));
else if (pid == 0) {
+ int fd;
+
+ if ((fd = acquire_terminal("/dev/console", false, true)) < 0) {
+ log_error("Failed to acquire terminal: %s", strerror(-fd));
+ _exit(1);
+ }
+
+ if (dup2(fd, STDIN_FILENO) < 0 ||
+ dup2(fd, STDOUT_FILENO) < 0 ||
+ dup2(fd, STDERR_FILENO) < 0) {
+ log_error("Failed to duplicate terminal fd: %s", strerror(errno));
+ _exit(1);
+ }
+
+ if (fd >= 3)
+ close_nointr_nofail(fd);
+
execl("/bin/sh", "/bin/sh", NULL);
log_error("execl() failed: %s", strerror(errno));