Blame 0051-remove-openvt-and-use-setsid-c-if-possible.patch

Harald Hoyer 1ee1e3
From c3d81de59b3828c35bbab6973f2ab0777777cf51 Mon Sep 17 00:00:00 2001
Harald Hoyer 1ee1e3
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 1ee1e3
Date: Wed, 14 Mar 2012 16:19:53 +0100
Harald Hoyer 1ee1e3
Subject: [PATCH] remove openvt and use "setsid -c", if possible
Harald Hoyer 1ee1e3
Harald Hoyer 1ee1e3
---
Harald Hoyer 1ee1e3
 dracut.conf.d/fedora.conf.example |    2 +-
Harald Hoyer 1ee1e3
 modules.d/99base/dracut-lib.sh    |   21 ++++++++++++---------
Harald Hoyer 1ee1e3
 modules.d/99base/module-setup.sh  |    2 +-
Harald Hoyer 1ee1e3
 modules.d/99shutdown/shutdown.sh  |   21 ++++++++++++---------
Harald Hoyer 1ee1e3
 4 files changed, 26 insertions(+), 20 deletions(-)
Harald Hoyer 1ee1e3
Harald Hoyer 1ee1e3
diff --git a/dracut.conf.d/fedora.conf.example b/dracut.conf.d/fedora.conf.example
Harald Hoyer 1ee1e3
index efec77e..02a530e 100644
Harald Hoyer 1ee1e3
--- a/dracut.conf.d/fedora.conf.example
Harald Hoyer 1ee1e3
+++ b/dracut.conf.d/fedora.conf.example
Harald Hoyer 1ee1e3
@@ -7,4 +7,4 @@ omit_dracutmodules+=" dash "
Harald Hoyer 1ee1e3
 omit_drivers+=" .*/fs/ocfs/.* "
Harald Hoyer 1ee1e3
 stdloglvl=3
Harald Hoyer 1ee1e3
 realinitpath="/usr/lib/systemd/systemd"
Harald Hoyer 1ee1e3
-install_items+=" vi /etc/virc ps grep cat rm openvt "
Harald Hoyer 1ee1e3
+install_items+=" vi /etc/virc ps grep cat rm "
Harald Hoyer 1ee1e3
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer 1ee1e3
index 80e093b..a6c4e24 100755
Harald Hoyer 1ee1e3
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer 1ee1e3
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer 1ee1e3
@@ -803,16 +803,19 @@ emergency_shell()
Harald Hoyer 1ee1e3
         echo
Harald Hoyer 1ee1e3
         export PS1="$_rdshell_name:\${PWD}# "
Harald Hoyer 1ee1e3
         [ -e /.profile ] || >/.profile
Harald Hoyer 1ee1e3
-        _ctty=/dev/console
Harald Hoyer 1ee1e3
-        if [ -n "$(command -v setsid)" ]; then
Harald Hoyer 1ee1e3
-            _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
Harald Hoyer 1ee1e3
-            [ -c "$_ctty" ] || _ctty=/dev/tty1
Harald Hoyer 1ee1e3
-            setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
Harald Hoyer 1ee1e3
-        elif [ -n "$(command -v openvt)" ] && ! getarg "console=" >/dev/null 2>&1 && getargbool 1 "rd.openvt" ; then
Harald Hoyer 1ee1e3
-            openvt -f -c 1 -w -s -l -- sh
Harald Hoyer 1ee1e3
-        else
Harald Hoyer 1ee1e3
-            sh -i -l 0<$_ctty 1>$_ctty 2>&1
Harald Hoyer 1ee1e3
+
Harald Hoyer 1ee1e3
+        _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
Harald Hoyer 1ee1e3
+        if [ -z "$_ctty" ]; then
Harald Hoyer 1ee1e3
+            _ctty=console
Harald Hoyer 1ee1e3
+            while [ -f /sys/class/tty/$_ctty/active ]; do
Harald Hoyer 1ee1e3
+                _ctty=$(cat /sys/class/tty/$_ctty/active)
Harald Hoyer 1ee1e3
+                _ctty=${_ctty##* } # last one in the list
Harald Hoyer 1ee1e3
+            done
Harald Hoyer 1ee1e3
+            _ctty=/dev/$_ctty
Harald Hoyer 1ee1e3
         fi
Harald Hoyer 1ee1e3
+        [ -c "$_ctty" ] || _ctty=/dev/tty1
Harald Hoyer 1ee1e3
+        strstr "$(setsid --help)" "control" && CTTY="-c"
Harald Hoyer 1ee1e3
+        setsid $CTTY /bin/sh -i -l 0<$_ctty 1>$_ctty 2>&1
Harald Hoyer 1ee1e3
     else
Harald Hoyer 1ee1e3
         warn "Boot has failed. To debug this issue add \"rdshell\" to the kernel command line."
Harald Hoyer 1ee1e3
         # cause a kernel panic
Harald Hoyer 1ee1e3
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
Harald Hoyer 1ee1e3
index 98742f5..581ba93 100755
Harald Hoyer 1ee1e3
--- a/modules.d/99base/module-setup.sh
Harald Hoyer 1ee1e3
+++ b/modules.d/99base/module-setup.sh
Harald Hoyer 1ee1e3
@@ -14,7 +14,7 @@ depends() {
Harald Hoyer 1ee1e3
 install() {
Harald Hoyer 1ee1e3
     local _d
Harald Hoyer 1ee1e3
     dracut_install mount mknod mkdir modprobe pidof sleep chroot \
Harald Hoyer 1ee1e3
-        sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink
Harald Hoyer 1ee1e3
+        sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid
Harald Hoyer 1ee1e3
     dracut_install -o less
Harald Hoyer 1ee1e3
     if [ ! -e "${initdir}/bin/sh" ]; then
Harald Hoyer 1ee1e3
         dracut_install bash
Harald Hoyer 1ee1e3
diff --git a/modules.d/99shutdown/shutdown.sh b/modules.d/99shutdown/shutdown.sh
Harald Hoyer 1ee1e3
index 2576687..c8ca664 100755
Harald Hoyer 1ee1e3
--- a/modules.d/99shutdown/shutdown.sh
Harald Hoyer 1ee1e3
+++ b/modules.d/99shutdown/shutdown.sh
Harald Hoyer 1ee1e3
@@ -30,16 +30,19 @@ emergency_shell()
Harald Hoyer 1ee1e3
         echo
Harald Hoyer 1ee1e3
         export PS1="$_rdshell_name:\${PWD}# "
Harald Hoyer 1ee1e3
         [ -e /.profile ] || >/.profile
Harald Hoyer 1ee1e3
-        _ctty=/dev/console
Harald Hoyer 1ee1e3
-        if [ -n "$(command -v setsid)" ]; then
Harald Hoyer 1ee1e3
-            _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
Harald Hoyer 1ee1e3
-            [ -c "$_ctty" ] || _ctty=/dev/tty1
Harald Hoyer 1ee1e3
-            setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
Harald Hoyer 1ee1e3
-        elif [ -n "$(command -v openvt)" ] && ! getarg "console=" >/dev/null 2>&1 && getargbool 1 "rd.openvt" ; then
Harald Hoyer 1ee1e3
-            openvt -f -c 1 -w -s -l -- sh
Harald Hoyer 1ee1e3
-        else
Harald Hoyer 1ee1e3
-            sh -i -l 0<$_ctty 1>$_ctty 2>&1
Harald Hoyer 1ee1e3
+
Harald Hoyer 1ee1e3
+        _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
Harald Hoyer 1ee1e3
+        if [ -z "$_ctty" ]; then
Harald Hoyer 1ee1e3
+            _ctty=console
Harald Hoyer 1ee1e3
+            while [ -f /sys/class/tty/$_ctty/active ]; do
Harald Hoyer 1ee1e3
+                _ctty=$(cat /sys/class/tty/$_ctty/active)
Harald Hoyer 1ee1e3
+                _ctty=${_ctty##* } # last one in the list
Harald Hoyer 1ee1e3
+            done
Harald Hoyer 1ee1e3
+            _ctty=/dev/$_ctty
Harald Hoyer 1ee1e3
         fi
Harald Hoyer 1ee1e3
+        [ -c "$_ctty" ] || _ctty=/dev/tty1
Harald Hoyer 1ee1e3
+        strstr "$(setsid --help)" "control" && CTTY="-c"
Harald Hoyer 1ee1e3
+        setsid $CTTY /bin/sh -i -l 0<$_ctty 1>$_ctty 2>&1
Harald Hoyer 1ee1e3
     else
Harald Hoyer 1ee1e3
         exec /lib/systemd/systemd-shutdown "$@"
Harald Hoyer 1ee1e3
         warn "Shutdown has failed. To debug this issue add \"rdshell\" to the kernel command line."