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

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