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

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