]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Add job control support to emergency shell
authorMichal Soltys <soltys@ziu.info>
Mon, 26 Dec 2011 06:29:15 +0000 (14:29 +0800)
committerHarald Hoyer <harald@redhat.com>
Mon, 23 Jan 2012 08:48:35 +0000 (09:48 +0100)
Option --ctty will optionally add setsid binary to dracut's image.

During runtime, if rd.ctty is set and is a character device,
emergency shells will be spawned with job control.

in case no ctty was provided, shell was spawned without caring about
/dev/console. Also, the ctty is more opportunistic. If the image was
generated with --ctty, we will fallback to /dev/tty1 if rc.ctty is
invalid or missing. Otherwise we spawn standard shell on /dev/console

[dyoung@redhat.com: Rebased to usrmove branch]

Signed-off-by: Michal Soltys <soltys@ziu.info>
Signed-off-by: Dave Young <dyoung@redhat.com>
dracut
dracut.8.xml
dracut.cmdline.7.xml
modules.d/99base/init
modules.d/99base/module-setup.sh
modules.d/99shutdown/shutdown

diff --git a/dracut b/dracut
index 8c24e7b0345939fc483734c502b0bb2cf65fabec..3c2156118189ffb883507a880e335cde696c5caa 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -232,6 +232,7 @@ while (($# > 0)); do
         --nolvmconf)   lvmconf_l="no";;
         --debug)       debug="yes";;
         --profile)     profile="yes";;
+        --ctty)        cttyhack="yes";;
         -v|--verbose)  ((verbosity_mod_l++));;
         -q|--quiet)    ((verbosity_mod_l--));;
         -l|--local)    allowlocal="yes" ;;
@@ -585,7 +586,7 @@ done
 export initdir dracutbasedir dracutmodules drivers \
     fw_dir drivers_dir debug no_kernel kernel_only \
     add_drivers mdadmconf lvmconf filesystems \
-    use_fstab libdir usrlibdir fscks nofscks \
+    use_fstab libdir usrlibdir fscks nofscks cttyhack \
     stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
     debug host_fs_types host_devs
 
index 221ad2e2b5fa515198ce0a364894365d8e4600cc..955d4d2878b378d7bb061be8072a6cc44ff3b177 100644 (file)
@@ -295,6 +295,15 @@ include in the generic initramfs. This parameter can be specified multiple times
             <para>do not prefix initramfs files (default)</para>
           </listitem>
         </varlistentry>
+        <varlistentry>
+          <term>
+            <option>--ctty</option>
+          </term>
+          <listitem>
+            <para>if possible, try to spawn an emergency shell on a terminal
+              with job control</para>
+          </listitem>
+        </varlistentry>
         <varlistentry>
           <term>
             <option>-h</option>
index 74e617c134b94f808399643195a5578f803dd966..0fa4762655ca44aba4a9e9a809b4e6faf8dc4905 100644 (file)
@@ -109,6 +109,20 @@ This parameter can be specified multiple times.</para>
            <para>force loading kernel module &lt;drivername&gt; after all automatic loading modules have been loaded. This parameter can be specified multiple times.</para>
           </listitem>
         </varlistentry>
+        <varlistentry>
+          <term>
+            <envar>rd.ctty=<replaceable>&lt;terminal&gt;</replaceable></envar>
+          </term>
+          <listitem>
+            <para>
+              if the dracut image was generated with --ctty option, try to
+              spawn an emergency shell on the specified terminal; if
+              <envar>rd.ctty</envar> is specified without a value or not
+              provided at all, the default is /dev/tty1. The '/dev' prefix
+              can be omitted.
+            </para>
+          </listitem>
+        </varlistentry>
       </variablelist>
     </refsect2>
     <refsect2 id="dracut-kernel-debug">
index 1e5444988a79ccd616d3053fb6a30126bfd3022c..33a73790d8455163673b4de686864b6ce294ddfb 100755 (executable)
@@ -40,6 +40,7 @@ wait_for_loginit()
 
 emergency_shell()
 {
+    local _ctty
     set +e
     if [ "$1" = "-n" ]; then
         _rdshell_name=$2
@@ -57,8 +58,15 @@ emergency_shell()
         echo "Dropping to debug shell."
         echo
         export PS1="$_rdshell_name:\${PWD}# "
-        [ -e /.profile ] || echo "exec 0<>/dev/console 1<>/dev/console 2<>/dev/console" > /.profile
-        sh -i -l
+        [ -e /.profile ] || >/.profile
+        _ctty=/dev/console
+        if type setsid >/dev/null 2>&1; then
+            _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
+            [ -c "$_ctty" ] || _ctty=/dev/tty1
+            setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
+        else
+            sh -i -l 0<$_ctty 1>$_ctty 2>&1
+        fi
     else
         warn "Boot has failed. To debug this issue add \"rdshell\" to the kernel command line."
         # cause a kernel panic
index f6c1209c7ef27319db71f0b903946fca7e42ea29..03058b147cf2ca2ef774f0b415fd75053a5e8900 100755 (executable)
@@ -16,6 +16,7 @@ install() {
     dracut_install mount mknod mkdir modprobe pidof sleep chroot \
         sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink
     dracut_install -o less
+    [[ $cttyhack = yes ]] && dracut_install -o setsid
     if [ ! -e "${initdir}/bin/sh" ]; then
         dracut_install bash
         (ln -s bash "${initdir}/bin/sh" || :)
index a31a95d39d9ecb6cd52c2f9b53ccc1939e5b3fce..21bb37f8d9f1254e0c3449f4ac5196c962a8b52d 100755 (executable)
@@ -13,6 +13,7 @@ export TERM=linux
 
 emergency_shell()
 {
+    local _ctty
     set +e
     if [ "$1" = "-n" ]; then
         _rdshell_name=$2
@@ -29,8 +30,15 @@ emergency_shell()
         echo "Dropping to debug shell."
         echo
         export PS1="$_rdshell_name:\${PWD}# "
-        [ -e /.profile ] || echo "exec 0<>/dev/console 1<>/dev/console 2<>/dev/console" > /.profile
-        sh -i -l
+        [ -e /.profile ] || >/.profile
+        _ctty=/dev/console
+        if type setsid >/dev/null 2>&1; then
+            _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
+            [ -c "$_ctty" ] || _ctty=/dev/tty1
+            setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
+        else
+            sh -i -l 0<$_ctty 1>$_ctty 2>&1
+        fi
     else
         exec /lib/systemd/systemd-shutdown "$@"
         warn "Shutdown has failed. To debug this issue add \"rdshell\" to the kernel command line."