From: Lennart Poettering Date: Fri, 14 May 2010 02:35:51 +0000 (+0200) Subject: main: acquire console before execing crash shell X-Git-Tag: 0.git+20100605+dfd8ee-1~13^2~32 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea5652c296f325eceea351c19bf81a783cea4537;p=systemd main: acquire console before execing crash shell --- diff --git a/main.c b/main.c index b0b3cfb5..6c730eb4 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));