From 337e7856935225617079900d763fd91060f2be87 Mon Sep 17 00:00:00 2001 From: Giuseppe Di Natale Date: Fri, 15 Dec 2017 13:26:43 -0800 Subject: [PATCH] Handle broken pipes in arc_summary Using a command similar to 'arc_summary.py | head' causes a broken pipe exception. Gracefully exit in the case of a broken pipe in arc_summary.py. Requires-Builders: none Signed-off-by: Giuseppe Di Natale --- TEST | 12 ++++++------ cmd/arc_summary/arc_summary.py | 13 +++++++++++++ .../cli_user/misc/arc_summary_001_pos.ksh | 3 +++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/TEST b/TEST index 4c593a457078..36059aa8b709 100644 --- a/TEST +++ b/TEST @@ -5,25 +5,25 @@ #TEST_PREPARE_SHARES="yes" ### SPLAT -#TEST_SPLAT_SKIP="yes" +TEST_SPLAT_SKIP="yes" #TEST_SPLAT_OPTIONS="-acvx" ### ztest -#TEST_ZTEST_SKIP="yes" +TEST_ZTEST_SKIP="yes" #TEST_ZTEST_TIMEOUT=1800 #TEST_ZTEST_DIR="/var/tmp/" #TEST_ZTEST_OPTIONS="-V" #TEST_ZTEST_CORE_DIR="/mnt/zloop" ### zimport -#TEST_ZIMPORT_SKIP="yes" +TEST_ZIMPORT_SKIP="yes" #TEST_ZIMPORT_DIR="/var/tmp/zimport" #TEST_ZIMPORT_VERSIONS="master installed" #TEST_ZIMPORT_POOLS="zol-0.6.1 zol-0.6.2 master installed" #TEST_ZIMPORT_OPTIONS="-c" ### xfstests -#TEST_XFSTESTS_SKIP="yes" +TEST_XFSTESTS_SKIP="yes" #TEST_XFSTESTS_URL="https://github.com/behlendorf/xfstests/archive/" #TEST_XFSTESTS_VER="zfs.tar.gz" #TEST_XFSTESTS_POOL="tank" @@ -39,10 +39,10 @@ #TEST_ZFSTESTS_ITERS="1" #TEST_ZFSTESTS_OPTIONS="-vx" #TEST_ZFSTESTS_RUNFILE="linux.run" -#TEST_ZFSTESTS_TAGS="functional" +TEST_ZFSTESTS_TAGS="misc" ### zfsstress -#TEST_ZFSSTRESS_SKIP="yes" +TEST_ZFSSTRESS_SKIP="yes" #TEST_ZFSSTRESS_URL="https://github.com/nedbass/zfsstress/archive/" #TEST_ZFSSTRESS_VER="master.tar.gz" #TEST_ZFSSTRESS_RUNTIME=300 diff --git a/cmd/arc_summary/arc_summary.py b/cmd/arc_summary/arc_summary.py index 5da81347cc29..d0867078a7b4 100755 --- a/cmd/arc_summary/arc_summary.py +++ b/cmd/arc_summary/arc_summary.py @@ -47,6 +47,7 @@ import os import sys import time +import errno from subprocess import Popen, PIPE from decimal import Decimal as D @@ -55,6 +56,18 @@ alternate_tunable_layout = False +def handle_Exception(ex_cls, ex, tb): + if ex is IOError: + if ex.errno == errno.EPIPE: + sys.exit() + + if ex is KeyboardInterrupt: + sys.exit() + + +sys.excepthook = handle_Exception + + def get_Kstat(): """Collect information on the ZFS subsystem from the /proc virtual file system. The name "kstat" is a holdover from the Solaris utility diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_001_pos.ksh index 67c11c8ab673..6653b9c1ad35 100755 --- a/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_001_pos.ksh @@ -37,4 +37,7 @@ while [[ $i -lt ${#args[*]} ]]; do ((i = i + 1)) done +log_must eval "arc_summary.py | head > /dev/null" +log_must eval "arc_summary.py | head -1 > /dev/null" + log_pass "arc_summary.py generates output and doesn't return an error code"