From 6c6b0b799c54b21cf854030a9859d1af067cecc8 Mon Sep 17 00:00:00 2001 From: Mohamad Gebai Date: Tue, 10 Apr 2018 21:30:23 -0400 Subject: [PATCH] mgr/iostat: exit gracefully on SIGINT Signed-off-by: Mohamad Gebai --- src/ceph.in | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/ceph.in b/src/ceph.in index ab636fa61525c..b4a75b09ff9d9 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -534,23 +534,32 @@ def do_command(parsed_args, target, cmdargs, sigdict, inbuf, verbose): return -errno.EINVAL, '', 'invalid command' while True: - ret, outbuf, outs = json_command(cluster_handle, target=target, argdict=valid_dict, - inbuf=inbuf) - if 'poll' not in valid_dict or not valid_dict['poll']: - # Don't print here if it's not a polling command - break - if ret: - ret = abs(ret) - print('Error: {0} {1}'.format(ret, errno.errorcode.get(ret, 'Unknown')), - file=sys.stderr) - break - if outbuf: - print(outbuf.decode('utf-8')) - if outs: - print(outs, file=sys.stderr) - if parsed_args.period <= 0: - break - sleep(parsed_args.period) + try: + if next_header_print == 0: + valid_dict['print_header'] = True + next_header_print = Termsize().rows - 3 + next_header_print -= 1 + ret, outbuf, outs = json_command(cluster_handle, target=target, + argdict=valid_dict, inbuf=inbuf) + valid_dict['print_header'] = False + if 'poll' not in valid_dict or not valid_dict['poll']: + # Don't print here if it's not a polling command + break + if ret: + ret = abs(ret) + print('Error: {0} {1}'.format(ret, errno.errorcode.get(ret, 'Unknown')), + file=sys.stderr) + break + if outbuf: + print(outbuf.decode('utf-8')) + if outs: + print(outs, file=sys.stderr) + if parsed_args.period <= 0: + break + sleep(parsed_args.period) + except KeyboardInterrupt: + print('Interrupted') + return ret, '', '' return ret, outbuf, outs -- 2.39.5