Skip to content

Commit 1bb4f41

Browse files
committed
Allow ctrl-c to be used during user input
Globally disable ctrl-c in /bin/zfsbootmenu by pointing it to an empty handler. Inside a subshell, unset the empty handler and then invoke zfsbootmenu-input with a single quoted argument; the pre-filled line that the user can edit. If ctrl-c is detected here, the script kills itself. Otherwise, it echos the line the user entered. It is up to the caller to determine how to handle an empty response.
1 parent cb18f0b commit 1bb4f41

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

90zfsbootmenu/module-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ install() {
131131
inst_simple "${moddir}/zfsbootmenu-preview.sh" "/bin/zfsbootmenu-preview.sh" || _ret=$?
132132
inst_simple "${moddir}/zfs-chroot" "/bin/zfs-chroot" || _ret=$?
133133
inst_simple "${moddir}/zfsbootmenu.sh" "/bin/zfsbootmenu" || _ret=$?
134+
inst_simple "${moddir}/zfsbootmenu-input.sh" "/bin/zfsbootmenu-input" || _ret=$?
134135
inst_hook cmdline 95 "${moddir}/zfsbootmenu-parse-commandline.sh" || _ret=$?
135136
inst_hook pre-mount 90 "${moddir}/zfsbootmenu-exec.sh" || _ret=$?
136137

90zfsbootmenu/zfsbootmenu-input.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
trap - SIGINT
3+
def_args="$1"
4+
5+
function sigint() {
6+
exit 1
7+
}
8+
9+
trap sigint SIGINT
10+
read -r -e -i "${def_args}" -p "> " input
11+
echo "${input}"
12+
exit 0

90zfsbootmenu/zfsbootmenu.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ printk=${printk:0:1}
88
# Set it to 0
99
echo 0 > /proc/sys/kernel/printk
1010

11+
# disable ctrl-c (SIGINT)
12+
trap '' SIGINT
13+
1114
# shellcheck disable=SC1091
1215
test -f /lib/zfsbootmenu-lib.sh && source /lib/zfsbootmenu-lib.sh
1316
# shellcheck disable=SC1091
@@ -288,7 +291,12 @@ while true; do
288291
while true;
289292
do
290293
echo -e "\nNew boot environment name"
291-
read -r -e -i "${pre_populated}" -p "> " new_be
294+
new_be="$( zfsbootmenu-input "${pre_populated}" )"
295+
296+
if [ -z "${new_be}" ] ; then
297+
break
298+
fi
299+
292300
if [ -n "${new_be}" ] ; then
293301
valid_name=$( echo "${new_be}" | tr -c -d 'a-zA-Z0-9-_.,' )
294302
# If the entered name is invalid, set the prompt to the valid form of the name
@@ -339,7 +347,8 @@ while true; do
339347
done <<< "${BE_ARGS}"
340348

341349
echo -e "\nNew kernel command line"
342-
read -r -e -i "${def_args}" -p "> " cmdline
350+
cmdline="$( zfsbootmenu-input "${def_args}" )"
351+
343352
if [ -n "${cmdline}" ] ; then
344353
echo "${cmdline}" > "${BASE}/cmdline"
345354
fi

testing/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ fi
7979
-object rng-random,id=rng0,filename=/dev/urandom \
8080
-device virtio-rng-pci,rng=rng0 \
8181
-display "${DISPLAY_TYPE}" \
82+
-serial mon:stdio \
8283
-append "${APPEND}"

0 commit comments

Comments
 (0)