Blame 0084-lsinitrd-Suppress-cat-write-error-Broken-pipe.patch

bb31e7f
From 3ce142861d88c357864d3a3bef7ec453826d737d Mon Sep 17 00:00:00 2001
bb31e7f
From: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
bb31e7f
Date: Wed, 4 Nov 2015 11:31:10 +0900
bb31e7f
Subject: [PATCH] lsinitrd: Suppress "cat: write error: Broken pipe"
bb31e7f
bb31e7f
On systemd, SIGPIPE is ignored by default; see man 5 systemd.exec for
bb31e7f
IgnoreSIGPIPE=. As a result, lsinitrd.sh under a systemd service
bb31e7f
outputs "cat: write error: Broken pipe" in the processing of
bb31e7f
determining a compression format of a given initramfs file using cat
bb31e7f
command in the write part of a pipeline processing.
bb31e7f
bb31e7f
For example, this is a log message of kdump.service in RHEL7.1,
bb31e7f
bb31e7f
    -- Logs begin at Wed 2015-11-04 09:57:33 JST, end at Wed 2015-11-04 09:58:28 JST. --
bb31e7f
    Nov 04 09:57:33 localhost systemd[1]: Stopping Crash recovery kernel arming...
bb31e7f
    Nov 04 09:57:33 localhost kdumpctl[22545]: kexec: unloaded kdump kernel
bb31e7f
    Nov 04 09:57:33 localhost kdumpctl[22545]: Stopping kdump: [OK]
bb31e7f
    Nov 04 09:57:33 localhost systemd[1]: Starting Crash recovery kernel arming...
bb31e7f
    Nov 04 09:57:36 localhost kdumpctl[22553]: Detected change(s) in the following file(s):
bb31e7f
    Nov 04 09:57:36 localhost kdumpctl[22553]: /etc/kdump.conf
bb31e7f
    Nov 04 09:57:36 localhost kdumpctl[22553]: Rebuilding /boot/initramfs-3.10.0-229.el7.x86_64kdump.img
bb31e7f
    Nov 04 09:57:40 localhost dracut[24914]: Executing: /usr/sbin/dracut --hostonly --hostonly-cmdline -o "plymouth dash resume" -f /boot/initramfs-3.10.0-229.el7.x86_64kdump.img 3.10.0-229.el7.x86_64
bb31e7f
    ...<cut>...
bb31e7f
    Nov 04 09:58:12 localhost dracut[24914]: *** Creating image file done ***
bb31e7f
    Nov 04 09:58:12 localhost dracut[24914]: Image: /boot/initramfs-3.10.0-229.el7.x86_64kdump.img: 18M
bb31e7f
    Nov 04 09:58:12 localhost kdumpctl[22553]: cat: write error: Broken pipe
bb31e7f
    Nov 04 09:58:12 localhost dracut[24914]: ========================================================================
bb31e7f
    Nov 04 09:58:12 localhost dracut[24914]: Version: dracut-033-240.el7
bb31e7f
    Nov 04 09:58:12 localhost dracut[24914]:
bb31e7f
    Nov 04 09:58:12 localhost dracut[24914]: Arguments: --hostonly --hostonly-cmdline -o 'plymouth dash resume' -f
bb31e7f
    Nov 04 09:58:13 localhost dracut[24914]:
bb31e7f
    Nov 04 09:58:13 localhost dracut[24914]: dracut modules:
bb31e7f
    Nov 04 09:58:13 localhost dracut[24914]: bash
bb31e7f
bb31e7f
kdump.service builds and loads an initramfs for kdump kernel using
bb31e7f
kdumpctl command which uses dracut command and so lsinitrd command,
bb31e7f
too.
bb31e7f
bb31e7f
Although there's no actual harm except for the error message, there
bb31e7f
has been several inquiries from customers about this message so
bb31e7f
far. We should suppress this message to reduce needless
bb31e7f
communications.
bb31e7f
bb31e7f
To suppress the message, this commit cleans up the processing of
bb31e7f
reading the first 6 bytes of a given initramfs file without cat
bb31e7f
command.
bb31e7f
---
bb31e7f
 lsinitrd.sh | 59 ++++++++++++++++++++++++++++-------------------------------
bb31e7f
 1 file changed, 28 insertions(+), 31 deletions(-)
bb31e7f
bb31e7f
diff --git a/lsinitrd.sh b/lsinitrd.sh
bb31e7f
index d2ddd76..441fb92 100755
bb31e7f
--- a/lsinitrd.sh
bb31e7f
+++ b/lsinitrd.sh
bb31e7f
@@ -176,38 +176,35 @@ case $bin in
bb31e7f
         ;;
bb31e7f
 esac
bb31e7f
 
bb31e7f
-CAT=$({
bb31e7f
-        if [[ $SKIP ]]; then
bb31e7f
-            $SKIP "$image"
bb31e7f
+if [[ $SKIP ]] ; then
bb31e7f
+    bin="$($SKIP "$image" | { read -N 6 bin && echo "$bin" ; })"
bb31e7f
+else
bb31e7f
+    read -N 6 bin < "$image"
bb31e7f
+fi
bb31e7f
+case $bin in
bb31e7f
+    $'\x1f\x8b'*)
bb31e7f
+        CAT="zcat --"
bb31e7f
+        ;;
bb31e7f
+    BZh*)
bb31e7f
+        CAT="bzcat --"
bb31e7f
+        ;;
bb31e7f
+    $'\x71\xc7'*|070701)
bb31e7f
+        CAT="cat --"
bb31e7f
+        ;;
bb31e7f
+    $'\x02\x21'*)
bb31e7f
+        CAT="lz4 -d -c"
bb31e7f
+        ;;
bb31e7f
+    $'\x89'LZO$'\0'*)
bb31e7f
+        CAT="lzop -d -c"
bb31e7f
+        ;;
bb31e7f
+    *)
bb31e7f
+        if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then
bb31e7f
+            CAT="xzcat --single-stream --"
bb31e7f
         else
bb31e7f
-            cat "$image"
bb31e7f
-        fi } | {
bb31e7f
-        read -N 6 bin
bb31e7f
-        case $bin in
bb31e7f
-            $'\x1f\x8b'*)
bb31e7f
-                echo "zcat --"
bb31e7f
-                ;;
bb31e7f
-            BZh*)
bb31e7f
-                echo "bzcat --"
bb31e7f
-                ;;
bb31e7f
-            $'\x71\xc7'*|070701)
bb31e7f
-                echo "cat --"
bb31e7f
-                ;;
bb31e7f
-            $'\x02\x21'*)
bb31e7f
-                echo "lz4 -d -c"
bb31e7f
-                ;;
bb31e7f
-            $'\x89'LZO$'\0'*)
bb31e7f
-                echo "lzop -d -c"
bb31e7f
-                ;;
bb31e7f
-            *)
bb31e7f
-                if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then
bb31e7f
-                    echo "xzcat --single-stream --"
bb31e7f
-                else
bb31e7f
-                    echo "xzcat --"
bb31e7f
-                fi
bb31e7f
-                ;;
bb31e7f
-        esac
bb31e7f
-    })
bb31e7f
+            CAT="xzcat --"
bb31e7f
+        fi
bb31e7f
+        ;;
bb31e7f
+esac
bb31e7f
 
bb31e7f
 skipcpio()
bb31e7f
 {