Blob Blame History Raw
From e314c1fc4cbdf8d7172fb6f8b87b127b21dd26c0 Mon Sep 17 00:00:00 2001
From: John Reiser <jreiser@bitwagon.com>
Date: Tue, 5 Feb 2013 21:47:40 +0330
Subject: [PATCH 12/18] Factor out unnecessary logger calls (#875356)

Numerous invocations of logger bogged down os-prober on system with
large numbers of partitions. Refactored to reduce the total number of
unique invocations to increase speed.

Resolves: rhbz#875356
---
 common.sh         | 24 ++++++++++++++++--------
 linux-boot-prober | 11 +++++++++++
 os-prober         | 12 +++++++++++-
 3 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/common.sh b/common.sh
index 1dbf7a3..7fcae5a 100644
--- a/common.sh
+++ b/common.sh
@@ -62,10 +62,14 @@ cache_progname() {
   esac
 }
 
-log() {
-  cache_progname
-  logger -t "$progname" "$@"
-}
+# fd_logger: bind value now, possibly after assigning default. 
+eval '
+  log() {
+    cache_progname
+    echo "$progname: $@"  1>&'${fd_logger:=9}'
+  }
+'
+export fd_logger  # so subshells inherit current value by default
 
 error() {
   log "error: $@"
@@ -81,10 +85,14 @@ debug() {
   fi
 }
 
-result () {
-  log "result:" "$@"
-  echo "$@"
-}
+# fd_result: bind value now, possibly after assigning default.
+eval '
+  result() {
+    log "result:" "$@"
+    echo "$@"  1>&'${fd_result:=1}'
+  }
+'
+export fd_result  # so subshells inherit current value by default
 
 # shim to make it easier to use os-prober outside d-i
 if ! type mapdevfs >/dev/null 2>&1; then
diff --git a/linux-boot-prober b/linux-boot-prober
index 57bf245..3b89750 100755
--- a/linux-boot-prober
+++ b/linux-boot-prober
@@ -1,4 +1,12 @@
 #!/bin/sh
+
+# dash shell does not have "{varname}>&1" feature that bash shell has
+# for auto-assignment of new filedescriptors.
+# It is cumbersome to write the 'eval' to use our own variables in redirections.
+# Therefore use fixed numbers.
+export fd_result=3  # file descriptor for external results
+export fd_logger=9  # file descriptor for input to logger
+
 . /usr/share/os-prober/common.sh
 
 set -e
@@ -147,6 +155,7 @@ if ! mapped="$(mapdevfs "$partition")"; then
 	continue
 fi
 
+( (
 if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map"; then
 	for test in /usr/lib/linux-boot-probes/*; do
 		if [ -x $test ] && [ -f $test ]; then
@@ -186,3 +195,5 @@ else
 		fi
 	fi
 fi
+) 9>&1 | logger 1>&-  # fd_logger
+) 3>&1  # fd_result
diff --git a/os-prober b/os-prober
index f5052af..4b371d6 100755
--- a/os-prober
+++ b/os-prober
@@ -1,7 +1,14 @@
 #!/bin/sh
 set -e
 
-. /usr/share/os-prober/common.sh
+# dash shell does not have "{varname}>&1" feature that bash shell has
+# for auto-assignment of new filedescriptors.
+# It is cumbersome to write the 'eval' to use our own variables in redirections.
+# Therefore use fixed numbers.
+export fd_result=3  # file descriptor for external results
+export fd_logger=9  # file descriptor for input to logger
+
+ . /usr/share/os-prober/common.sh
 
 newns "$@"
 require_tmpdir
@@ -129,6 +136,7 @@ fi
 
 : >"$OS_PROBER_TMP/btrfs-vols"
 
+( (
 for partition in $(partitions); do
 	if ! mapped="$(mapdevfs "$partition")"; then
 		log "Device '$partition' does not exist; skipping"
@@ -193,3 +201,5 @@ for partition in $(partitions); do
 		fi
 	fi
 done
+) 9>&1 | logger 1>&-  # fd_logger
+) 3>&1  # fd_result
-- 
2.5.5