]> git.proxmox.com Git - zfsonlinux.git/blob - zfs-patches/0021-Handle-invalid-options-in-arc_summary.patch
buildsys: upload to pmg as well
[zfsonlinux.git] / zfs-patches / 0021-Handle-invalid-options-in-arc_summary.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: LOLi <loli10K@users.noreply.github.com>
3 Date: Tue, 19 Dec 2017 22:02:40 +0100
4 Subject: [PATCH] Handle invalid options in arc_summary
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 If an invalid option is provided to arc_summary.py we handle any error
10 thrown from the getopt Python module and print the usage help message.
11
12 Reviewed-by: George Melikov <mail@gmelikov.ru>
13 Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
14 Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
15 Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
16 Closes #6983
17 (cherry picked from commit 9a6c57845a431f55fd617c38e180b26215f0ca6f)
18 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
19 ---
20 .../tests/functional/cli_user/misc/Makefile.am | 1 +
21 cmd/arc_summary/arc_summary.py | 16 ++++++---
22 tests/runfiles/linux.run | 2 +-
23 .../cli_user/misc/arc_summary_002_neg.ksh | 38 ++++++++++++++++++++++
24 4 files changed, 51 insertions(+), 6 deletions(-)
25 create mode 100755 tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_002_neg.ksh
26
27 diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am b/tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am
28 index cf7502c27..75a3d0886 100644
29 --- a/tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am
30 +++ b/tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am
31 @@ -46,4 +46,5 @@ dist_pkgdata_SCRIPTS = \
32 zpool_upgrade_001_neg.ksh \
33 arcstat_001_pos.ksh \
34 arc_summary_001_pos.ksh \
35 + arc_summary_002_neg.ksh \
36 dbufstat_001_pos.ksh
37 diff --git a/cmd/arc_summary/arc_summary.py b/cmd/arc_summary/arc_summary.py
38 index 5da81347c..2472f87ea 100755
39 --- a/cmd/arc_summary/arc_summary.py
40 +++ b/cmd/arc_summary/arc_summary.py
41 @@ -977,9 +977,15 @@ def main():
42 global show_tunable_descriptions
43 global alternate_tunable_layout
44
45 - opts, args = getopt.getopt(
46 - sys.argv[1:], "adp:h", ["alternate", "description", "page=", "help"]
47 - )
48 + try:
49 + opts, args = getopt.getopt(
50 + sys.argv[1:],
51 + "adp:h", ["alternate", "description", "page=", "help"]
52 + )
53 + except getopt.error as e:
54 + sys.stderr.write("Error: %s\n" % e.msg)
55 + usage()
56 + sys.exit(1)
57
58 args = {}
59 for opt, arg in opts:
60 @@ -991,7 +997,7 @@ def main():
61 args['p'] = arg
62 if opt in ('-h', '--help'):
63 usage()
64 - sys.exit()
65 + sys.exit(0)
66
67 Kstat = get_Kstat()
68
69 @@ -1006,7 +1012,7 @@ def main():
70 except IndexError:
71 sys.stderr.write('the argument to -p must be between 1 and ' +
72 str(len(unSub)) + '\n')
73 - sys.exit()
74 + sys.exit(1)
75 else:
76 pages = unSub
77
78 diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
79 index 10bd110a6..f872c0cbf 100644
80 --- a/tests/runfiles/linux.run
81 +++ b/tests/runfiles/linux.run
82 @@ -366,7 +366,7 @@ tests = ['zdb_001_neg', 'zfs_001_neg', 'zfs_allow_001_neg',
83 'zpool_offline_001_neg', 'zpool_online_001_neg', 'zpool_remove_001_neg',
84 'zpool_replace_001_neg', 'zpool_scrub_001_neg', 'zpool_set_001_neg',
85 'zpool_status_001_neg', 'zpool_upgrade_001_neg', 'arcstat_001_pos',
86 - 'arc_summary_001_pos', 'dbufstat_001_pos']
87 + 'arc_summary_001_pos', 'arc_summary_002_neg', 'dbufstat_001_pos']
88 user =
89 tags = ['functional', 'cli_user', 'misc']
90
91 diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_002_neg.ksh
92 new file mode 100755
93 index 000000000..e63552feb
94 --- /dev/null
95 +++ b/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_002_neg.ksh
96 @@ -0,0 +1,38 @@
97 +#!/bin/ksh -p
98 +#
99 +# CDDL HEADER START
100 +#
101 +# The contents of this file are subject to the terms of the
102 +# Common Development and Distribution License (the "License").
103 +# You may not use this file except in compliance with the License.
104 +#
105 +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
106 +# or http://www.opensolaris.org/os/licensing.
107 +# See the License for the specific language governing permissions
108 +# and limitations under the License.
109 +#
110 +# When distributing Covered Code, include this CDDL HEADER in each
111 +# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
112 +# If applicable, add the following below this CDDL HEADER, with the
113 +# fields enclosed by brackets "[]" replaced with your own identifying
114 +# information: Portions Copyright [yyyy] [name of copyright owner]
115 +#
116 +# CDDL HEADER END
117 +#
118 +
119 +#
120 +# Copyright (c) 2015 by Lawrence Livermore National Security, LLC.
121 +# All rights reserved.
122 +#
123 +
124 +. $STF_SUITE/include/libtest.shlib
125 +
126 +typeset args=("-x" "-r" "-5" "-p 7" "--err" "-@")
127 +
128 +log_assert "arc_summary.py generates an error code with invalid options"
129 +
130 +for arg in "${args[@]}"; do
131 + log_mustnot eval "arc_summary.py $arg > /dev/null"
132 +done
133 +
134 +log_pass "arc_summary.py generates an error code with invalid options"
135 --
136 2.14.2
137