commit:     5124ba044c454c112e756c5e8024650a64008609
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Tue Aug  6 15:11:39 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Tue Aug  6 20:40:31 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=5124ba04

linuxrc: Rework debug mode

This commit will introduce $GK_DEBUGMODE_STATEFILE and a new
function is_debug() to check if debug mode is enabled or not.

Using a state file instead of a variable will allow us to
enable/disable debug mode from outside:

I.e. when you have booted in debug mode and are working remotely,
you can now remove the state file, which will disable debug mode.
This will allow you to resume booting without dropping in
another local debug shell.

It works the other way, too: When you did NOT boot in debug
mode but experiencing a problem and want to drop in another
debug shell after next step, you can now enable debug mode by
creating the state file.

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.defaults |  1 +
 defaults/initrd.scripts  | 34 ++++++++++++++++++++++++----------
 defaults/linuxrc         |  2 +-
 defaults/unlock-luks.sh  |  2 +-
 4 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
index 704a5a2..89d13ac 100644
--- a/defaults/initrd.defaults
+++ b/defaults/initrd.defaults
@@ -70,6 +70,7 @@ CDROOT_MARKER='/livecd'
 VERIFY=0
 
 IP='dhcp'
+GK_DEBUGMODE_STATEFILE="/tmp/debug.enabled"
 GK_NET_DHCP_PIDFILE='/var/run/udhcpc.pid'
 GK_NET_DHCP_RETRIES=3
 GK_NET_GW=

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 1f7dc94..994f0f0 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -49,7 +49,7 @@ modules_scan() {
                                break
                        fi
 
-                       if [ -n "${DEBUG}" ]
+                       if is_debug
                        then
                                printf "%b" "${BOLD}   ::${NORMAL} "
                                printf "%b" "Scanning for ${x} ..."
@@ -58,12 +58,12 @@ modules_scan() {
                        modprobe ${x} >/dev/null 2>&1
                        loaded=${?}
 
-                       [ -n "${DEBUG}" -a "${loaded}" = "0" ] && \
+                       is_debug && [ "${loaded}" = "0" ] && \
                                echo "loaded"
-                       [ -n "${DEBUG}" -a "${loaded}" != "0" ] && \
+                       is_debug && [ "${loaded}" != "0" ] && \
                                echo "not loaded"
 
-                       [ -z "${DEBUG}" -a "${loaded}" = "0" ] && \
+                       ! is_debug && [ "${loaded}" = "0" ] && \
                                [ -z "${QUIET}" ] && \
                                printf "%b" "${x} "
                else
@@ -462,6 +462,17 @@ conf_rc_no_umounts() {
        fi
 }
 
+is_debug() {
+       is_debug=1
+
+       if [ -f "${GK_DEBUGMODE_STATEFILE}" ]
+       then
+               is_debug=0
+       fi
+
+       return ${is_debug}
+}
+
 # is_int "${A}" ["${B}"..]
 # NOTE we consider a leading 0 false as it would be interpreted as octal
 is_int() {
@@ -880,7 +891,7 @@ test_success() {
 # $2 hide flag
 
 good_msg() {
-       [ -n "${QUIET}" ] && [ -z "${DEBUG}" ] && return 0
+       [ -n "${QUIET}" ] && ! is_debug && return 0
 
        msg_string=${1}
        msg_string="${msg_string:-...}"
@@ -888,7 +899,7 @@ good_msg() {
 }
 
 good_msg_n() {
-       [ -n "${QUIET}" ] && [ -z "${DEBUG}" ] && return 0
+       [ -n "${QUIET}" ] && ! is_debug && return 0
 
        msg_string=${1}
        msg_string="${msg_string:-...}"
@@ -1943,7 +1954,7 @@ start_sshd() {
        # setup environment variables for the ssh login shell
        local varname= varvalue=
        touch "${CRYPT_ENV_FILE}"
-       for varname in CRYPT_ROOT CRYPT_ROOT_TRIM CRYPT_SILENT CRYPT_SWAP DEBUG
+       for varname in CRYPT_ROOT CRYPT_ROOT_TRIM CRYPT_SILENT CRYPT_SWAP
        do
                eval varvalue=\$${varname}
                echo "${varname}=${varvalue}" >> "${CRYPT_ENV_FILE}"
@@ -2106,12 +2117,15 @@ setup_md_device() {
 }
 
 rundebugshell() {
-       if [ -n "${DEBUG}" ]
+       if is_debug
        then
                good_msg 'Starting debug shell as requested by "debug" option.'
-               good_msg "Stopping by: ${1}"
-               run_shell
+       else
+               return 0
        fi
+
+       good_msg "Stopping by: ${1}"
+       run_shell
 }
 
 do_resume() {

diff --git a/defaults/linuxrc b/defaults/linuxrc
index d729806..dcae3cc 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -153,7 +153,7 @@ do
                ;;
                # Debug Options
                debug)
-                       DEBUG='yes'
+                       touch "${GK_DEBUGMODE_STATEFILE}"
                ;;
                # Scan delay options
                scandelay=*)

diff --git a/defaults/unlock-luks.sh b/defaults/unlock-luks.sh
index cae5269..e8f28f6 100644
--- a/defaults/unlock-luks.sh
+++ b/defaults/unlock-luks.sh
@@ -106,7 +106,7 @@ main() {
 
        if [ -s "${LUKS_KEY}" ]
        then
-               if  [ "${DEBUG}" != 'yes' ]
+               if  ! is_debug
                then
                        rm -f "${LUKS_KEY}"
                else

Reply via email to