Blame SOURCES/0012-Factor-out-unnecessary-logger-calls-875356.patch

2e96e6
From e314c1fc4cbdf8d7172fb6f8b87b127b21dd26c0 Mon Sep 17 00:00:00 2001
2e96e6
From: John Reiser <jreiser@bitwagon.com>
2e96e6
Date: Tue, 5 Feb 2013 21:47:40 +0330
2e96e6
Subject: [PATCH 12/18] Factor out unnecessary logger calls (#875356)
2e96e6
2e96e6
Numerous invocations of logger bogged down os-prober on system with
2e96e6
large numbers of partitions. Refactored to reduce the total number of
2e96e6
unique invocations to increase speed.
2e96e6
2e96e6
Resolves: rhbz#875356
2e96e6
---
2e96e6
 common.sh         | 24 ++++++++++++++++--------
2e96e6
 linux-boot-prober | 11 +++++++++++
2e96e6
 os-prober         | 12 +++++++++++-
2e96e6
 3 files changed, 38 insertions(+), 9 deletions(-)
2e96e6
2e96e6
diff --git a/common.sh b/common.sh
2e96e6
index 1dbf7a3..7fcae5a 100644
2e96e6
--- a/common.sh
2e96e6
+++ b/common.sh
2e96e6
@@ -62,10 +62,14 @@ cache_progname() {
2e96e6
   esac
2e96e6
 }
2e96e6
 
2e96e6
-log() {
2e96e6
-  cache_progname
2e96e6
-  logger -t "$progname" "$@"
2e96e6
-}
2e96e6
+# fd_logger: bind value now, possibly after assigning default. 
2e96e6
+eval '
2e96e6
+  log() {
2e96e6
+    cache_progname
2e96e6
+    echo "$progname: $@"  1>&'${fd_logger:=9}'
2e96e6
+  }
2e96e6
+'
2e96e6
+export fd_logger  # so subshells inherit current value by default
2e96e6
 
2e96e6
 error() {
2e96e6
   log "error: $@"
2e96e6
@@ -81,10 +85,14 @@ debug() {
2e96e6
   fi
2e96e6
 }
2e96e6
 
2e96e6
-result () {
2e96e6
-  log "result:" "$@"
2e96e6
-  echo "$@"
2e96e6
-}
2e96e6
+# fd_result: bind value now, possibly after assigning default.
2e96e6
+eval '
2e96e6
+  result() {
2e96e6
+    log "result:" "$@"
2e96e6
+    echo "$@"  1>&'${fd_result:=1}'
2e96e6
+  }
2e96e6
+'
2e96e6
+export fd_result  # so subshells inherit current value by default
2e96e6
 
2e96e6
 # shim to make it easier to use os-prober outside d-i
2e96e6
 if ! type mapdevfs >/dev/null 2>&1; then
2e96e6
diff --git a/linux-boot-prober b/linux-boot-prober
2e96e6
index 57bf245..3b89750 100755
2e96e6
--- a/linux-boot-prober
2e96e6
+++ b/linux-boot-prober
2e96e6
@@ -1,4 +1,12 @@
2e96e6
 #!/bin/sh
2e96e6
+
2e96e6
+# dash shell does not have "{varname}>&1" feature that bash shell has
2e96e6
+# for auto-assignment of new filedescriptors.
2e96e6
+# It is cumbersome to write the 'eval' to use our own variables in redirections.
2e96e6
+# Therefore use fixed numbers.
2e96e6
+export fd_result=3  # file descriptor for external results
2e96e6
+export fd_logger=9  # file descriptor for input to logger
2e96e6
+
2e96e6
 . /usr/share/os-prober/common.sh
2e96e6
 
2e96e6
 set -e
2e96e6
@@ -147,6 +155,7 @@ if ! mapped="$(mapdevfs "$partition")"; then
2e96e6
 	continue
2e96e6
 fi
2e96e6
 
2e96e6
+( (
2e96e6
 if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map"; then
2e96e6
 	for test in /usr/lib/linux-boot-probes/*; do
2e96e6
 		if [ -x $test ] && [ -f $test ]; then
2e96e6
@@ -186,3 +195,5 @@ else
2e96e6
 		fi
2e96e6
 	fi
2e96e6
 fi
2e96e6
+) 9>&1 | logger 1>&-  # fd_logger
2e96e6
+) 3>&1  # fd_result
2e96e6
diff --git a/os-prober b/os-prober
2e96e6
index f5052af..4b371d6 100755
2e96e6
--- a/os-prober
2e96e6
+++ b/os-prober
2e96e6
@@ -1,7 +1,14 @@
2e96e6
 #!/bin/sh
2e96e6
 set -e
2e96e6
 
2e96e6
-. /usr/share/os-prober/common.sh
2e96e6
+# dash shell does not have "{varname}>&1" feature that bash shell has
2e96e6
+# for auto-assignment of new filedescriptors.
2e96e6
+# It is cumbersome to write the 'eval' to use our own variables in redirections.
2e96e6
+# Therefore use fixed numbers.
2e96e6
+export fd_result=3  # file descriptor for external results
2e96e6
+export fd_logger=9  # file descriptor for input to logger
2e96e6
+
2e96e6
+ . /usr/share/os-prober/common.sh
2e96e6
 
2e96e6
 newns "$@"
2e96e6
 require_tmpdir
2e96e6
@@ -129,6 +136,7 @@ fi
2e96e6
 
2e96e6
 : >"$OS_PROBER_TMP/btrfs-vols"
2e96e6
 
2e96e6
+( (
2e96e6
 for partition in $(partitions); do
2e96e6
 	if ! mapped="$(mapdevfs "$partition")"; then
2e96e6
 		log "Device '$partition' does not exist; skipping"
2e96e6
@@ -193,3 +201,5 @@ for partition in $(partitions); do
2e96e6
 		fi
2e96e6
 	fi
2e96e6
 done
2e96e6
+) 9>&1 | logger 1>&-  # fd_logger
2e96e6
+) 3>&1  # fd_result
2e96e6
-- 
2e96e6
2.5.5
2e96e6