diff options
author | LOLi <[email protected]> | 2017-12-19 22:02:40 +0100 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-12-19 13:02:40 -0800 |
commit | c4ba46deade0a14d089228a56a5d0aa0ffd5fadd (patch) | |
tree | f0d6393b98cde0d2285569e7852dcea8f4217407 /cmd | |
parent | 2e7c1bb35a9858eff93feaf9132d3d89e756f6e0 (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-x | cmd/arc_summary/arc_summary.py | 16 |
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 |