685deb
kpatch: clarify that "kpatch unload" isn't supported
685deb
685deb
Add a user-prompt to the kpatch unload subcommand and make a similiar
685deb
mention in the manual page.
685deb
685deb
Provide an undocumented force option so that QE and dev scripts can
685deb
still run unload kpatch modules from scripts.
685deb
685deb
RHEL-only.
685deb
685deb
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
685deb
diff -Nupr kpatch-0.6.1.old/kpatch/kpatch kpatch-0.6.1/kpatch/kpatch
685deb
--- kpatch-0.9.2.old/kpatch/kpatch	2019-08-28 10:35:01.191259434 -0400
685deb
+++ kpatch-0.9.2/kpatch/kpatch	2019-08-28 16:11:13.067926576 -0400
685deb
@@ -49,8 +49,8 @@ usage () {
685deb
 	echo >&2
685deb
 	usage_cmd "load --all" "load all installed patch modules into the running kernel"
685deb
 	usage_cmd "load <module>" "load patch module into the running kernel"
685deb
-	usage_cmd "unload --all" "unload all patch modules from the running kernel"
685deb
-	usage_cmd "unload <module>" "unload patch module from the running kernel"
685deb
+	usage_cmd "unload --all (UNSUPPORTED)" "unload all patch modules from the running kernel"
685deb
+	usage_cmd "unload <module> (UNSUPPORTED)" "unload patch module from the running kernel"
685deb
 	echo >&2
685deb
 	usage_cmd "info <module>" "show information about a patch module"
685deb
 	echo >&2
685deb
@@ -71,6 +71,16 @@ die() {
685deb
 	exit 1
685deb
 }
685deb
 
685deb
+confirm_prompt() {
685deb
+	local prompt="$1"
685deb
+	local answer
685deb
+	while true; do
685deb
+		read -rp "$prompt [Y/N] " answer
685deb
+		[[ $answer == 'Y' || $answer == 'y' ]] && return 0
685deb
+		[[ $answer == 'N' || $answer == 'n' ]] && return 1
685deb
+	done
685deb
+}
685deb
+
685deb
 __find_module () {
685deb
 	MODULE="$1"
685deb
 	[[ -f "$MODULE" ]] && return
685deb
@@ -406,6 +416,19 @@ unset MODULE
685deb
 init_sysfs_var
685deb
 
685deb
 [[ "$#" -lt 1 ]] && usage
685deb
+
685deb
+# RHEL-specific support options
685deb
+case "$1" in
685deb
+"force")
685deb
+	# For scripting purposes, support "kpatch force unload".
685deb
+	# Shift out the "force" to avoid the user-prompt check below.
685deb
+	shift
685deb
+	;;
685deb
+"unload")
685deb
+	confirm_prompt "WARNING: Red Hat doesn't support unloading of kpatches, continue anyway?" || exit 1
685deb
+	;;
685deb
+esac
685deb
+
685deb
 case "$1" in
685deb
 "load")
685deb
 	[[ "$#" -ne 2 ]] && usage
685deb
diff -Nupr kpatch-0.6.1.old/man/kpatch.1 kpatch-0.6.1/man/kpatch.1
685deb
--- kpatch-0.9.2.old/man/kpatch.1	2019-08-28 10:35:01.191259434 -0400
685deb
+++ kpatch-0.9.2/man/kpatch.1	2019-08-28 14:51:23.268198897 -0400
685deb
@@ -23,10 +23,10 @@ load --all
685deb
 load <module>
685deb
        load patch module into the running kernel
685deb
 
685deb
-unload --all
685deb
+unload --all (UNSUPPORTED)
685deb
        unload all patch modules from the running kernel
685deb
 
685deb
-unload <module>
685deb
+unload <module> (UNSUPPORTED)
685deb
        unload patch module from the running kernel
685deb
 
685deb
 info <module>