From e169d82192996b79628970fd89900428d8816463 Mon Sep 17 00:00:00 2001 From: Evgenii Shatokhin Date: Tue, 17 Nov 2015 15:59:05 +0300 Subject: [PATCH] kpatch-build: get kernel version from vmlinux if source tree is used If a kernel SRPM is used to get the kernel sources, the target kernel version is determined from the name of the SRPM. One cannot obtain the target kernel version this way if the source tree is used instead of an SRPM, so let us extract that information from vmlinux. Signed-off-by: Evgenii Shatokhin --- kpatch-build/kpatch-build | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index d487be7ab..a51300874 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -283,12 +283,6 @@ rm -f "$LOGFILE" trap cleanup EXIT INT TERM HUP -KVER=${ARCHVERSION%%-*} -if [[ $ARCHVERSION =~ - ]]; then - KREL=${ARCHVERSION##*-} - KREL=${KREL%.*} -fi - if [[ -n $USERSRCDIR ]]; then # save .config and vmlinux since they'll get removed with mrproper so # we can restore them later and be able to run kpatch-build multiple @@ -300,6 +294,15 @@ if [[ -n $USERSRCDIR ]]; then [[ -z $VMLINUX ]] && VMLINUX="$USERSRCDIR"/vmlinux [[ ! -e "$VMLINUX" ]] && die "can't find vmlinux" [[ "$VMLINUX" = "$USERSRCDIR"/vmlinux ]] && cp -f "$VMLINUX" $TEMPDIR/vmlinux && VMLINUX=$TEMPDIR/vmlinux + + # Extract the target kernel version from vmlinux in this case. + ARCHVERSION=$(strings "$VMLINUX" | grep -e "^Linux version" | awk '{ print($3); }') +fi + +KVER=${ARCHVERSION%%-*} +if [[ $ARCHVERSION =~ - ]]; then + KREL=${ARCHVERSION##*-} + KREL=${KREL%.*} fi [[ -z $TARGETS ]] && TARGETS="vmlinux modules"