Blob Blame History Raw
From e6a2555c7ddde2ed542b2aae01d78a5c9309bf80 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Mon, 10 Aug 2015 13:40:43 +0200
Subject: [PATCH] base/dracut-lib.sh: Dup stdout and stderr

Dup stdout and stderr, so that subshell redirection does not affect
logging.

Also gets rid of systemd printing info() to the console on "quiet".
---
 modules.d/99base/dracut-lib.sh | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index 5ec7b23..200c263 100755
--- a/modules.d/99base/dracut-lib.sh
+++ b/modules.d/99base/dracut-lib.sh
@@ -51,29 +51,45 @@ str_ends() {
     [ "${1%*"$2"}" != "$1" ]
 }
 
+# Dup stdout and stderr, so that subshell redirection does not affect logging.
+if [ -z "$DRACUT_STDOUT" ]; then
+    if [ -n "$BASH" ]; then
+        readonly DRACUT_STDOUT=98
+        readonly DRACUT_STDERR=98
+        exec 98>&1
+        exec 99>&2
+    else
+        readonly DRACUT_STDOUT=8
+        readonly DRACUT_STDERR=9
+        exec 8>&1
+        exec 9>&2
+    fi
+fi
+
+
 if [ -z "$DRACUT_SYSTEMD" ]; then
 
     warn() {
         check_quiet
         echo "<28>dracut Warning: $*" > /dev/kmsg
-        echo "dracut Warning: $*" >&2
+        echo "dracut Warning: $*" >&$DRACUT_STDERR
     }
 
     info() {
         check_quiet
         echo "<30>dracut: $*" > /dev/kmsg
         [ "$DRACUT_QUIET" != "yes" ] && \
-            echo "dracut: $*" >&2
+            echo "dracut: $*" >&$DRACUT_STDERR
     }
 
 else
 
     warn() {
-        echo "Warning: $*" >&2
+        echo "Warning: $*" >&$DRACUT_STDERR
     }
 
     info() {
-        echo "$*" >&2
+        echo "$*" >&$DRACUT_STDOUT
     }
 
 fi