commit:     f49a899ce13f9e41bdf592187e0d157b071bf82d
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Tue Aug  6 15:43:40 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Tue Aug  6 20:40:32 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=f49a899c

linuxrc: Fix console support

- Make sure we set console after processing CMDLINE so that we will
  use last set console which matches kernel documentation.

- Strip any set option from console= value.

- Regain control after spawning a shell.

Bug: https://bugs.gentoo.org/473128
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.scripts | 15 ++++++++++++---
 defaults/linuxrc        | 25 +++++++++++++++++++++----
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 2452f5f..6f7530f 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -827,9 +827,14 @@ run_shell() {
        GOOD=${BLUE} good_msg "${NORMAL}...running Linux kernel 
${BOLD}${kernel_ver}${NORMAL}"
        echo
 
-       if [ -n "${CONSOLE}" ] && [ -c "/dev/${CONSOLE}" ]
-       then
-               setsid ${SH} -c "exec sh --login </dev/${CONSOLE} 
>/dev/${CONSOLE} 2>&1"
+       # Avoid /dev/{console,tty0} due to "can't access tty; job control 
turned off" problem;
+       # cttyhack will handle this for us...
+       if [ -n "${CONSOLE}" ] \
+               && [ "${CONSOLE}" != "/dev/console" ] \
+               && [ "${CONSOLE}" != "/dev/tty0" ] \
+               && [ -c "${CONSOLE}" ]
+       then
+               setsid ${SH} -c "exec sh --login <${CONSOLE} >${CONSOLE} 2>&1"
        elif command -v cttyhack 1>/dev/null 2>&1
        then
                setsid cttyhack ${SH} --login
@@ -843,6 +848,10 @@ run_shell() {
        rm "${GK_SHELL_LOCKFILE}"
 
        echo
+
+       # We maybe have called exec and dettached from main script; We
+       # must restore control...
+       exec >${CONSOLE} <${CONSOLE} 2>&1
 }
 
 fs_type_in_use() {

diff --git a/defaults/linuxrc b/defaults/linuxrc
index dcae3cc..e3d5a2b 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -11,11 +11,13 @@
 [ ! -e /dev/tty ]      && mknod /dev/tty c 5 0
 [ ! -e /dev/tty0 ]     && mknod /dev/tty0 c 4 0
 [ ! -e /dev/tty1 ]     && mknod /dev/tty1 c 4 1
+[ ! -e /dev/ttyS0 ]    && mknod /dev/ttyS0 c 4 64
+[ ! -e /dev/ttyS1 ]    && mknod /dev/ttyS1 c 4 65
 [ ! -e /dev/urandom ]  && mknod /dev/urandom c 1 9
 [ ! -e /dev/random ]   && mknod /dev/random c 1 8
 [ ! -e /dev/zero ]     && mknod /dev/zero c 1 5
 
-# Clean input/output
+# Take control
 exec >${CONSOLE} <${CONSOLE} 2>&1
 
 if [ "$$" != '1' ]
@@ -184,9 +186,9 @@ do
                ;;
                # Redirect output to a specific tty
                CONSOLE=*|console=*)
-                       CONSOLE=${x#*=}
-                       CONSOLE=$(basename ${CONSOLE})
-#                      exec >${CONSOLE} <${CONSOLE} 2>&1
+                       NEW_CONSOLE=${x#*=}
+                       NEW_CONSOLE=$(basename ${NEW_CONSOLE})
+                       NEW_CONSOLE=${NEW_CONSOLE%%,*}
                ;;
                # /dev/md
                lvmraid=*)
@@ -362,6 +364,21 @@ do
        esac
 done
 
+if [ -n "${NEW_CONSOLE}" ]
+then
+       # We cannot update console while processing CMDLINE because we
+       # are only interested in last console= value.
+       [ ! -c "${NEW_CONSOLE}" ] && NEW_CONSOLE="/dev/${NEW_CONSOLE}"
+       if [ -c "${NEW_CONSOLE}" ]
+       then
+               exec >${NEW_CONSOLE} <${NEW_CONSOLE} 2>&1
+               good_msg "Console switched from '${CONSOLE}' to 
'${NEW_CONSOLE}'!"
+               CONSOLE="${NEW_CONSOLE}"
+       else
+               bad_msg "Unable to switch console: '${NEW_CONSOLE}' not found 
or not a character device!"
+       fi
+fi
+
 quiet_kmsg
 
 if [ "${CDROOT}" = '0' ]

Reply via email to