Blame 0058-base-dracut-lib.sh-Dup-stdout-and-stderr.patch

Harald Hoyer 368a0c
From e6a2555c7ddde2ed542b2aae01d78a5c9309bf80 Mon Sep 17 00:00:00 2001
Harald Hoyer 368a0c
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 368a0c
Date: Mon, 10 Aug 2015 13:40:43 +0200
Harald Hoyer 368a0c
Subject: [PATCH] base/dracut-lib.sh: Dup stdout and stderr
Harald Hoyer 368a0c
Harald Hoyer 368a0c
Dup stdout and stderr, so that subshell redirection does not affect
Harald Hoyer 368a0c
logging.
Harald Hoyer 368a0c
Harald Hoyer 368a0c
Also gets rid of systemd printing info() to the console on "quiet".
Harald Hoyer 368a0c
---
Harald Hoyer 368a0c
 modules.d/99base/dracut-lib.sh | 24 ++++++++++++++++++++----
Harald Hoyer 368a0c
 1 file changed, 20 insertions(+), 4 deletions(-)
Harald Hoyer 368a0c
Harald Hoyer 368a0c
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer 368a0c
index 5ec7b23..200c263 100755
Harald Hoyer 368a0c
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer 368a0c
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer 368a0c
@@ -51,29 +51,45 @@ str_ends() {
Harald Hoyer 368a0c
     [ "${1%*"$2"}" != "$1" ]
Harald Hoyer 368a0c
 }
Harald Hoyer 368a0c
 
Harald Hoyer 368a0c
+# Dup stdout and stderr, so that subshell redirection does not affect logging.
Harald Hoyer 368a0c
+if [ -z "$DRACUT_STDOUT" ]; then
Harald Hoyer 368a0c
+    if [ -n "$BASH" ]; then
Harald Hoyer 368a0c
+        readonly DRACUT_STDOUT=98
Harald Hoyer 368a0c
+        readonly DRACUT_STDERR=98
Harald Hoyer 368a0c
+        exec 98>&1
Harald Hoyer 368a0c
+        exec 99>&2
Harald Hoyer 368a0c
+    else
Harald Hoyer 368a0c
+        readonly DRACUT_STDOUT=8
Harald Hoyer 368a0c
+        readonly DRACUT_STDERR=9
Harald Hoyer 368a0c
+        exec 8>&1
Harald Hoyer 368a0c
+        exec 9>&2
Harald Hoyer 368a0c
+    fi
Harald Hoyer 368a0c
+fi
Harald Hoyer 368a0c
+
Harald Hoyer 368a0c
+
Harald Hoyer 368a0c
 if [ -z "$DRACUT_SYSTEMD" ]; then
Harald Hoyer 368a0c
 
Harald Hoyer 368a0c
     warn() {
Harald Hoyer 368a0c
         check_quiet
Harald Hoyer 368a0c
         echo "<28>dracut Warning: $*" > /dev/kmsg
Harald Hoyer 368a0c
-        echo "dracut Warning: $*" >&2
Harald Hoyer 368a0c
+        echo "dracut Warning: $*" >&$DRACUT_STDERR
Harald Hoyer 368a0c
     }
Harald Hoyer 368a0c
 
Harald Hoyer 368a0c
     info() {
Harald Hoyer 368a0c
         check_quiet
Harald Hoyer 368a0c
         echo "<30>dracut: $*" > /dev/kmsg
Harald Hoyer 368a0c
         [ "$DRACUT_QUIET" != "yes" ] && \
Harald Hoyer 368a0c
-            echo "dracut: $*" >&2
Harald Hoyer 368a0c
+            echo "dracut: $*" >&$DRACUT_STDERR
Harald Hoyer 368a0c
     }
Harald Hoyer 368a0c
 
Harald Hoyer 368a0c
 else
Harald Hoyer 368a0c
 
Harald Hoyer 368a0c
     warn() {
Harald Hoyer 368a0c
-        echo "Warning: $*" >&2
Harald Hoyer 368a0c
+        echo "Warning: $*" >&$DRACUT_STDERR
Harald Hoyer 368a0c
     }
Harald Hoyer 368a0c
 
Harald Hoyer 368a0c
     info() {
Harald Hoyer 368a0c
-        echo "$*" >&2
Harald Hoyer 368a0c
+        echo "$*" >&$DRACUT_STDOUT
Harald Hoyer 368a0c
     }
Harald Hoyer 368a0c
 
Harald Hoyer 368a0c
 fi