summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLOLi <[email protected]>2017-12-19 22:02:40 +0100
committerTony Hutter <[email protected]>2018-01-30 10:27:31 -0600
commit9a6c57845a431f55fd617c38e180b26215f0ca6f (patch)
tree35eeedfeae0bda7833fdb7cf41527eb6895e2a64 /cmd
parentd27a40d28f96cfd9f7b32337306f64935ee749bc (diff)
Handle invalid options in arc_summary
If an invalid option is provided to arc_summary.py we handle any error thrown from the getopt Python module and print the usage help message. Reviewed-by: George Melikov <[email protected]> Reviewed-by: Giuseppe Di Natale <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: loli10K <[email protected]> Closes #6983
Diffstat (limited to 'cmd')
-rwxr-xr-xcmd/arc_summary/arc_summary.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/cmd/arc_summary/arc_summary.py b/cmd/arc_summary/arc_summary.py
index 5da81347c..2472f87ea 100755
--- a/cmd/arc_summary/arc_summary.py
+++ b/cmd/arc_summary/arc_summary.py
@@ -977,9 +977,15 @@ def main():
global show_tunable_descriptions
global alternate_tunable_layout
- opts, args = getopt.getopt(
- sys.argv[1:], "adp:h", ["alternate", "description", "page=", "help"]
- )
+ try:
+ opts, args = getopt.getopt(
+ sys.argv[1:],
+ "adp:h", ["alternate", "description", "page=", "help"]
+ )
+ except getopt.error as e:
+ sys.stderr.write("Error: %s\n" % e.msg)
+ usage()
+ sys.exit(1)
args = {}
for opt, arg in opts:
@@ -991,7 +997,7 @@ def main():
args['p'] = arg
if opt in ('-h', '--help'):
usage()
- sys.exit()
+ sys.exit(0)
Kstat = get_Kstat()
@@ -1006,7 +1012,7 @@ def main():
except IndexError:
sys.stderr.write('the argument to -p must be between 1 and ' +
str(len(unSub)) + '\n')
- sys.exit()
+ sys.exit(1)
else:
pages = unSub