Skip to contentSkip to conversation

ver_linux: Process input coming from procmaps that matches libc only

PATCH New Alexander Kapshuk 1 participant 2 messages May 31, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ver_linux: Process input coming from procmaps that matches libc only

Currently, input coming from /proc/self/maps is split into fields without checking whether or not it matches libc.so. This is not efficient. All text processing should only be performed on lines of input that match libc.so.

---
 scripts/ver_linux | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
scripts/ver_linux +7 -5
index 7227994ccf63..e1dc041f903f 100755
@@ -32,11 +32,13 @@ BEGIN {
 	printversion("Nfs-utils", version("showmount --version"))
 
 	while (getline <"/proc/self/maps" > 0) {
-		n = split($0, procmaps, "/")
-		if (/libc.*so$/ && match(procmaps[n], /[0-9]+([.]?[0-9]+)+/)) {
-			ver = substr(procmaps[n], RSTART, RLENGTH)
-			printversion("Linux C Library", ver)
-			break
+		if (/libc.*\.so$/) {
+			n = split($0, procmaps, "/")
+			if (match(procmaps[n], /[0-9]+([.]?[0-9]+)+/)) {
+				ver = substr(procmaps[n], RSTART, RLENGTH)
+				printversion("Linux C Library", ver)
+				break
+			}
 		}
 	}
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 ver_linux: Do not check for ver_linux pattern in version function

Checking whether output of commands matches the ver_linux pattern in the version function is original shell implementation legacy code. When the original implementation failed to locate a particular utility, it generated error output along the lines of:

ver_linux:line number: command not found.

The awk implementation, does not contain the name of the script within the body of the error message returned by the subshell when a given utility fails to be located. The error message returned is along the lines of:

sh: name of utility: command not found

Safeguarding against the ver_linux pattern being found in the output being parsed may thus be safely omitted.

---
 scripts/ver_linux | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/ver_linux +1 -1
index e1dc041f903f..a6c728db05ce 100755
@@ -70,7 +70,7 @@ BEGIN {
 function version(cmd,    ver) {
 	cmd = cmd " 2>&1"
 	while (cmd | getline > 0) {
-		if (!/ver_linux/ && match($0, /[0-9]+([.]?[0-9]+)+/)) {
+		if (match($0, /[0-9]+([.]?[0-9]+)+/)) {
 			ver = substr($0, RSTART, RLENGTH)
 			break
 		}
Signature · 1 line
2.17.1