• [gentoo-dev] [PATCH 1/2] linux-info.eclass: rework get_running_version

    From Mike Gilbert@21:1/5 to All on Mon Sep 13 18:30:01 2021
    This function may fail if the version cannot be parsed from a Makefile
    found by following the /lib/modules/${KV_FULL}/{source,build} symlinks.
    Instead of failing, we should just split KV_FULL as a fallback.

    Also, simplify the existance checks for the kernel Makefile; if we can't
    find the kernel source directory, there is really no point in checking
    for the kernel build directory. The latter will probably contain a
    Makefile with no version information.

    Bug: https://bugs.gentoo.org/811726
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>
    ---
    eclass/linux-info.eclass | 47 +++++++++++++++++-----------------------
    1 file changed, 20 insertions(+), 27 deletions(-)

    diff --git a/eclass/linux-info.eclass b/eclass/linux-info.eclass
    index 4e08949a385..97f7b5c06a9 100644
    --- a/eclass/linux-info.eclass
    +++ b/eclass/linux-info.eclass
    @@ -629,34 +629,27 @@ get_running_version() {
    die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
    fi

    - KV_FULL=$(uname -r)
    -
    - if [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
    - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
    - KBUILD_OUTPUT=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
    - unset KV_FULL
    - get_version
    - return $?
    - elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile ]]; then
    - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
    - unset KV_FULL
    - get_version
    - return $?
    - elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]];
  • From Mike@21:1/5 to Mike Gilbert on Tue Sep 14 00:30:02 2021
    On 9/13/21 12:27 PM, Mike Gilbert wrote:
    This function may fail if the version cannot be parsed from a Makefile
    found by following the /lib/modules/${KV_FULL}/{source,build} symlinks. Instead of failing, we should just split KV_FULL as a fallback.

    Also, simplify the existance checks for the kernel Makefile; if we can't
    find the kernel source directory, there is really no point in checking
    for the kernel build directory. The latter will probably contain a
    Makefile with no version information.

    Bug: https://bugs.gentoo.org/811726
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>
    ---
    eclass/linux-info.eclass | 47 +++++++++++++++++-----------------------
    1 file changed, 20 insertions(+), 27 deletions(-)

    diff --git a/eclass/linux-info.eclass b/eclass/linux-info.eclass
    index 4e08949a385..97f7b5c06a9 100644
    --- a/eclass/linux-info.eclass
    +++ b/eclass/linux-info.eclass
    @@ -629,34 +629,27 @@ get_running_version() {
    die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
    fi

    - KV_FULL=$(uname -r)
    -
    - if [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
    - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
    - KBUILD_OUTPUT=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
    - unset KV_FULL
    - get_version
    - return $?
    - elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile ]]; then
    - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
    - unset KV_FULL
    - get_version
    - return $?
    - elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
    - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
    - unset KV_FULL
    - get_version
    - return $?
    - else
    - # This handles a variety of weird kernel versions. Make sure to update
    - # tests/linux-info_get_running_version.sh if you want to change this.
    - local kv_full=${KV_FULL//[-+_]*}
    - KV_MAJOR=$(ver_cut 1 ${kv_full})
    - KV_MINOR=$(ver_cut 2 ${kv_full})
    - KV_PATCH=$(ver_cut 3 ${kv_full})
    - KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}"
    - : ${KV_PATCH:=0}
    + local kv=$(uname -r)
    +
    + if [[ -f ${ROOT%/}/lib/modules/${kv}/source/Makefile ]]; then
    + KERNEL_DIR=$(readlink -f "${ROOT%/}/lib/modules/${kv}/source") + if [[ -f ${ROOT%/}/lib/modules/${kv}/build/Makefile ]]; then
    + KBUILD_OUTPUT=$(readlink -f "${ROOT%/}/lib/modules/${kv}/build")
    + fi
    + get_version && return 0
    fi
    +
    + KV_FULL=${kv}
    +
    + # This handles a variety of weird kernel versions. Make sure to update + # tests/linux-info_get_running_version.sh if you want to change this.
    + local kv_full=${KV_FULL//[-+_]*}
    + KV_MAJOR=$(ver_cut 1 ${kv_full})
    + KV_MINOR=$(ver_cut 2 ${kv_full})
    + KV_PATCH=$(ver_cut 3 ${kv_full})
    + KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}" + : ${KV_PATCH:=0}
    +
    return 0
    }



    --

    LGTM, everything I've tested looks good, will continue to run with this one also.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)