ver_linux: Eliminate duplicate code in ldconfig processing logic
authorAlexander Kapshuk <alexander.kapshuk@gmail.com>
Fri, 8 Jan 2021 11:26:26 +0000 (13:26 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 Jan 2021 13:54:42 +0000 (14:54 +0100)
The code that acquires the version strings for libc and libcpp is
identical, as is the printversion call. The only difference being the
name of the library being printed.

Refactor the code by unifying the bits that are common to both libraries.

Signed-off-by: Alexander Kapshuk <alexander.kapshuk@gmail.com>
Link: https://lore.kernel.org/r/20210108112626.8623-1-alexander.kapshuk@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
scripts/ver_linux

index 0968a3070eff39fcb86fd6b37c7eb32acc56cea3..a92acc703f9b1c4e0fa00cd01cccea31bd18c3f4 100755 (executable)
@@ -15,7 +15,7 @@ BEGIN {
 
        vernum = "[0-9]+([.]?[0-9]+)+"
        libc = "libc[.]so[.][0-9]+$"
-       libcpp = "(libg|stdc)[+]+[.]so[.][0-9]+$"
+       libcpp = "(libg|stdc)[+]+[.]so([.][0-9]+)+$"
 
        printversion("GNU C", version("gcc -dumpversion"))
        printversion("GNU Make", version("make --version"))
@@ -37,12 +37,10 @@ BEGIN {
        printversion("Bison", version("bison --version"))
        printversion("Flex", version("flex --version"))
 
-       while ("ldconfig -p 2>/dev/null" | getline > 0) {
-               if ($NF ~ libc && !seen[ver = version("readlink " $NF)]++)
-                       printversion("Linux C Library", ver)
-               else if ($NF ~ libcpp && !seen[ver = version("readlink " $NF)]++)
-                       printversion("Linux C++ Library", ver)
-       }
+       while ("ldconfig -p 2>/dev/null" | getline > 0)
+               if ($NF ~ libc || $NF ~ libcpp)
+                       if (!seen[ver = version("readlink " $NF)]++)
+                               printversion("Linux C" ($NF ~ libcpp? "++" : "") " Library", ver)
 
        printversion("Dynamic linker (ldd)", version("ldd --version"))
        printversion("Procps", version("ps --version"))