]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
base/dracut-lib.sh: Dup stdout and stderr
authorHarald Hoyer <harald@redhat.com>
Mon, 10 Aug 2015 11:40:43 +0000 (13:40 +0200)
committerHarald Hoyer <harald@redhat.com>
Mon, 10 Aug 2015 11:40:43 +0000 (13:40 +0200)
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

index 5ec7b234702a375400aa64040a68ef4568aaaa32..200c26345e0b3bb9b99feee744992f4281a471a8 100755 (executable)
@@ -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