1 |
commit: 5124ba044c454c112e756c5e8024650a64008609 |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Aug 6 15:11:39 2019 +0000 |
4 |
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Aug 6 20:40:31 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=5124ba04 |
7 |
|
8 |
linuxrc: Rework debug mode |
9 |
|
10 |
This commit will introduce $GK_DEBUGMODE_STATEFILE and a new |
11 |
function is_debug() to check if debug mode is enabled or not. |
12 |
|
13 |
Using a state file instead of a variable will allow us to |
14 |
enable/disable debug mode from outside: |
15 |
|
16 |
I.e. when you have booted in debug mode and are working remotely, |
17 |
you can now remove the state file, which will disable debug mode. |
18 |
This will allow you to resume booting without dropping in |
19 |
another local debug shell. |
20 |
|
21 |
It works the other way, too: When you did NOT boot in debug |
22 |
mode but experiencing a problem and want to drop in another |
23 |
debug shell after next step, you can now enable debug mode by |
24 |
creating the state file. |
25 |
|
26 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
27 |
|
28 |
defaults/initrd.defaults | 1 + |
29 |
defaults/initrd.scripts | 34 ++++++++++++++++++++++++---------- |
30 |
defaults/linuxrc | 2 +- |
31 |
defaults/unlock-luks.sh | 2 +- |
32 |
4 files changed, 27 insertions(+), 12 deletions(-) |
33 |
|
34 |
diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults |
35 |
index 704a5a2..89d13ac 100644 |
36 |
--- a/defaults/initrd.defaults |
37 |
+++ b/defaults/initrd.defaults |
38 |
@@ -70,6 +70,7 @@ CDROOT_MARKER='/livecd' |
39 |
VERIFY=0 |
40 |
|
41 |
IP='dhcp' |
42 |
+GK_DEBUGMODE_STATEFILE="/tmp/debug.enabled" |
43 |
GK_NET_DHCP_PIDFILE='/var/run/udhcpc.pid' |
44 |
GK_NET_DHCP_RETRIES=3 |
45 |
GK_NET_GW= |
46 |
|
47 |
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts |
48 |
index 1f7dc94..994f0f0 100644 |
49 |
--- a/defaults/initrd.scripts |
50 |
+++ b/defaults/initrd.scripts |
51 |
@@ -49,7 +49,7 @@ modules_scan() { |
52 |
break |
53 |
fi |
54 |
|
55 |
- if [ -n "${DEBUG}" ] |
56 |
+ if is_debug |
57 |
then |
58 |
printf "%b" "${BOLD} ::${NORMAL} " |
59 |
printf "%b" "Scanning for ${x} ..." |
60 |
@@ -58,12 +58,12 @@ modules_scan() { |
61 |
modprobe ${x} >/dev/null 2>&1 |
62 |
loaded=${?} |
63 |
|
64 |
- [ -n "${DEBUG}" -a "${loaded}" = "0" ] && \ |
65 |
+ is_debug && [ "${loaded}" = "0" ] && \ |
66 |
echo "loaded" |
67 |
- [ -n "${DEBUG}" -a "${loaded}" != "0" ] && \ |
68 |
+ is_debug && [ "${loaded}" != "0" ] && \ |
69 |
echo "not loaded" |
70 |
|
71 |
- [ -z "${DEBUG}" -a "${loaded}" = "0" ] && \ |
72 |
+ ! is_debug && [ "${loaded}" = "0" ] && \ |
73 |
[ -z "${QUIET}" ] && \ |
74 |
printf "%b" "${x} " |
75 |
else |
76 |
@@ -462,6 +462,17 @@ conf_rc_no_umounts() { |
77 |
fi |
78 |
} |
79 |
|
80 |
+is_debug() { |
81 |
+ is_debug=1 |
82 |
+ |
83 |
+ if [ -f "${GK_DEBUGMODE_STATEFILE}" ] |
84 |
+ then |
85 |
+ is_debug=0 |
86 |
+ fi |
87 |
+ |
88 |
+ return ${is_debug} |
89 |
+} |
90 |
+ |
91 |
# is_int "${A}" ["${B}"..] |
92 |
# NOTE we consider a leading 0 false as it would be interpreted as octal |
93 |
is_int() { |
94 |
@@ -880,7 +891,7 @@ test_success() { |
95 |
# $2 hide flag |
96 |
|
97 |
good_msg() { |
98 |
- [ -n "${QUIET}" ] && [ -z "${DEBUG}" ] && return 0 |
99 |
+ [ -n "${QUIET}" ] && ! is_debug && return 0 |
100 |
|
101 |
msg_string=${1} |
102 |
msg_string="${msg_string:-...}" |
103 |
@@ -888,7 +899,7 @@ good_msg() { |
104 |
} |
105 |
|
106 |
good_msg_n() { |
107 |
- [ -n "${QUIET}" ] && [ -z "${DEBUG}" ] && return 0 |
108 |
+ [ -n "${QUIET}" ] && ! is_debug && return 0 |
109 |
|
110 |
msg_string=${1} |
111 |
msg_string="${msg_string:-...}" |
112 |
@@ -1943,7 +1954,7 @@ start_sshd() { |
113 |
# setup environment variables for the ssh login shell |
114 |
local varname= varvalue= |
115 |
touch "${CRYPT_ENV_FILE}" |
116 |
- for varname in CRYPT_ROOT CRYPT_ROOT_TRIM CRYPT_SILENT CRYPT_SWAP DEBUG |
117 |
+ for varname in CRYPT_ROOT CRYPT_ROOT_TRIM CRYPT_SILENT CRYPT_SWAP |
118 |
do |
119 |
eval varvalue=\$${varname} |
120 |
echo "${varname}=${varvalue}" >> "${CRYPT_ENV_FILE}" |
121 |
@@ -2106,12 +2117,15 @@ setup_md_device() { |
122 |
} |
123 |
|
124 |
rundebugshell() { |
125 |
- if [ -n "${DEBUG}" ] |
126 |
+ if is_debug |
127 |
then |
128 |
good_msg 'Starting debug shell as requested by "debug" option.' |
129 |
- good_msg "Stopping by: ${1}" |
130 |
- run_shell |
131 |
+ else |
132 |
+ return 0 |
133 |
fi |
134 |
+ |
135 |
+ good_msg "Stopping by: ${1}" |
136 |
+ run_shell |
137 |
} |
138 |
|
139 |
do_resume() { |
140 |
|
141 |
diff --git a/defaults/linuxrc b/defaults/linuxrc |
142 |
index d729806..dcae3cc 100644 |
143 |
--- a/defaults/linuxrc |
144 |
+++ b/defaults/linuxrc |
145 |
@@ -153,7 +153,7 @@ do |
146 |
;; |
147 |
# Debug Options |
148 |
debug) |
149 |
- DEBUG='yes' |
150 |
+ touch "${GK_DEBUGMODE_STATEFILE}" |
151 |
;; |
152 |
# Scan delay options |
153 |
scandelay=*) |
154 |
|
155 |
diff --git a/defaults/unlock-luks.sh b/defaults/unlock-luks.sh |
156 |
index cae5269..e8f28f6 100644 |
157 |
--- a/defaults/unlock-luks.sh |
158 |
+++ b/defaults/unlock-luks.sh |
159 |
@@ -106,7 +106,7 @@ main() { |
160 |
|
161 |
if [ -s "${LUKS_KEY}" ] |
162 |
then |
163 |
- if [ "${DEBUG}" != 'yes' ] |
164 |
+ if ! is_debug |
165 |
then |
166 |
rm -f "${LUKS_KEY}" |
167 |
else |