diff --git a/contrib/Makefile b/contrib/Makefile index e873f27..0b0eeeb 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -6,12 +6,12 @@ install: all $(INSTALL) -d $(SYSTEMDDIR) $(INSTALL) -m 0644 kpatch.service $(SYSTEMDDIR) sed -i 's~PREFIX~$(PREFIX)~' $(SYSTEMDDIR)/kpatch.service -# $(INSTALL) -d $(UPSTARTDIR) -# $(INSTALL) -m 0644 kpatch.conf $(UPSTARTDIR) -# sed -i 's~PREFIX~$(PREFIX)~' $(UPSTARTDIR)/kpatch.conf + $(INSTALL) -d $(UPSTARTDIR) + $(INSTALL) -m 0644 kpatch.conf $(UPSTARTDIR) + sed -i 's~PREFIX~$(PREFIX)~' $(UPSTARTDIR)/kpatch.conf uninstall: $(RM) $(SYSTEMDDIR)/kpatch.service -# $(RM) $(UPSTARTDIR)/kpatch.conf + $(RM) $(UPSTARTDIR)/kpatch.conf clean: diff --git a/contrib/kpatch.service b/contrib/kpatch.service index cf13f40..5286f6c 100644 --- a/contrib/kpatch.service +++ b/contrib/kpatch.service @@ -6,6 +6,7 @@ ConditionKernelCommandLine=!kpatch.enable=0 Type=oneshot RemainAfterExit=yes ExecStart=PREFIX/sbin/kpatch load --all +ExecStop=PREFIX/sbin/kpatch unload --all [Install] WantedBy=multi-user.target diff --git a/kpatch/kpatch b/kpatch/kpatch index 1ba0425..2e02245 100755 --- a/kpatch/kpatch +++ b/kpatch/kpatch @@ -49,8 +49,8 @@ usage () { echo >&2 usage_cmd "load --all" "load all installed patch modules into the running kernel" usage_cmd "load " "load patch module into the running kernel" - usage_cmd "unload --all (UNSUPPORTED)" "unload all patch modules from the running kernel" - usage_cmd "unload (UNSUPPORTED)" "unload patch module from the running kernel" + usage_cmd "unload --all" "unload all patch modules from the running kernel" + usage_cmd "unload " "unload patch module from the running kernel" echo >&2 usage_cmd "info " "show information about a patch module" echo >&2 @@ -71,16 +71,6 @@ die() { exit 1 } -confirm_prompt() { - local prompt="$1" - local answer - while true; do - read -rp "$prompt [Y/N] " answer - [[ $answer == 'Y' || $answer == 'y' ]] && return 0 - [[ $answer == 'N' || $answer == 'n' ]] && return 1 - done -} - __find_module () { MODULE="$1" [[ -f "$MODULE" ]] && return @@ -136,7 +126,7 @@ find_core_module() { } core_loaded () { - grep -q -e "T klp_enable_patch" -e "T kpatch_register" /proc/kallsyms + grep -q -e "T klp_register_patch" -e "T kpatch_register" /proc/kallsyms } get_module_name () { @@ -324,31 +314,31 @@ load_module () { die "error: cannot re-enable patch module $modname, cannot verify checksum match" fi else - echo "module named $modname already loaded and enabled" + die "error: module named $modname already loaded and enabled" fi - else - echo "loading patch module: $module" - local i=0 - while true; do - out="$(LC_ALL=C insmod "$module" 2>&1)" - [[ -z "$out" ]] && break - echo "$out" 1>&2 - [[ ! "$out" =~ "Device or resource busy" ]] && - die "failed to load module $module" - - # "Device or resource busy" means the activeness safety check - # failed. Retry in a few seconds. - i=$((i+1)) - if [[ $i -eq $MAX_LOAD_ATTEMPTS ]]; then - die "failed to load module $module" - break - else - warn "retrying..." - sleep $RETRY_INTERVAL - fi - done fi + echo "loading patch module: $module" + local i=0 + while true; do + out="$(LC_ALL=C insmod "$module" 2>&1)" + [[ -z "$out" ]] && break + echo "$out" 1>&2 + [[ ! "$out" =~ "Device or resource busy" ]] && + die "failed to load module $module" + + # "Device or resource busy" means the activeness safety check + # failed. Retry in a few seconds. + i=$((i+1)) + if [[ $i -eq $MAX_LOAD_ATTEMPTS ]]; then + die "failed to load module $module" + break + else + warn "retrying..." + sleep $RETRY_INTERVAL + fi + done + if ! wait_for_patch_transition "$modname" ; then echo "module $modname did not complete its transition, unloading..." unload_module "$modname" @@ -416,19 +406,6 @@ unset MODULE init_sysfs_var [[ "$#" -lt 1 ]] && usage - -# RHEL-specific support options -case "$1" in -"force") - # For scripting purposes, support "kpatch force unload". - # Shift out the "force" to avoid the user-prompt check below. - shift - ;; -"unload") - confirm_prompt "WARNING: Red Hat doesn't support unloading of kpatches, continue anyway?" || exit 1 - ;; -esac - case "$1" in "load") [[ "$#" -ne 2 ]] && usage diff --git a/man/kpatch.1 b/man/kpatch.1 index ea4c5d4..511f646 100644 --- a/man/kpatch.1 +++ b/man/kpatch.1 @@ -23,10 +23,10 @@ load --all load load patch module into the running kernel -unload --all (UNSUPPORTED) +unload --all unload all patch modules from the running kernel -unload (UNSUPPORTED) +unload unload patch module from the running kernel info