kdump-lib.sh: fix incorrect usage with pipe as input for grep -q in is_pcs_fence_kdump()

For -q option, as man grep says:  Exit immediately with zero status if
any match is found, even if an error was detected.
So when matching, the read side of pipe is closed by "grep -q", while
the write side still try to write more data, which cause SIGPIPE to the
process, and the shell can not exit with 0. It depends on the kernel's
implementation of pipe to decide how much data written by the producer
can trigger the bug.

Bash test script:
  #!/bin/sh
  set -o pipefail
  dd if=/dev/zero of=text.file bs=1M count=1
  sed -i '1s/^/keyword /' text.file
  cat text.file | grep -q keyword
  echo $?

Notice the "set -o pipefail" is set by dracut, so
mkdumprd -> dracut -> dracut-module-setup.sh -> is_pcs_fence_kdump()
trigger the bug.

Signed-off-by: Pingfan Liu <piliu@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
Acked-by: Pratyush Anand <panand@redhat.com>
This commit is contained in:
Pingfan Liu 2017-02-10 10:20:57 +08:00 committed by Dave Young
parent ad404977eb
commit 14ec322b4b
1 changed files with 1 additions and 1 deletions

View File

@ -63,7 +63,7 @@ is_pcs_fence_kdump()
[ -x $FENCE_KDUMP_SEND ] || return 1
# fence kdump not configured?
(pcs cluster cib | grep -q 'type="fence_kdump"') &> /dev/null || return 1
(pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1
}
# Check if fence_kdump is configured using kdump options