All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ver_linux: Eliminate duplicate code in ldconfig processing logic
@ 2021-01-08 11:26 Alexander Kapshuk
  2021-01-22  7:18 ` Alexander Kapshuk
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Kapshuk @ 2021-01-08 11:26 UTC (permalink / raw
  To: linux-kernel; +Cc: gregkh, Alexander Kapshuk

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>
---
 scripts/ver_linux | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/scripts/ver_linux b/scripts/ver_linux
index 0968a3070eff..a92acc703f9b 100755
--- a/scripts/ver_linux
+++ b/scripts/ver_linux
@@ -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"))
--
2.30.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ver_linux: Eliminate duplicate code in ldconfig processing logic
  2021-01-08 11:26 [PATCH] ver_linux: Eliminate duplicate code in ldconfig processing logic Alexander Kapshuk
@ 2021-01-22  7:18 ` Alexander Kapshuk
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Kapshuk @ 2021-01-22  7:18 UTC (permalink / raw
  To: linux-kernel; +Cc: Greg KH

On Fri, Jan 8, 2021 at 1:26 PM Alexander Kapshuk
<alexander.kapshuk@gmail.com> wrote:
>
> 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>
> ---
>  scripts/ver_linux | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/scripts/ver_linux b/scripts/ver_linux
> index 0968a3070eff..a92acc703f9b 100755
> --- a/scripts/ver_linux
> +++ b/scripts/ver_linux
> @@ -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"))
> --
> 2.30.0
>

I'd appreciate getting some feedback on the patch in question at your
convenience.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-22  7:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-08 11:26 [PATCH] ver_linux: Eliminate duplicate code in ldconfig processing logic Alexander Kapshuk
2021-01-22  7:18 ` Alexander Kapshuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.