]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/iostat: exit gracefully on SIGINT
authorMohamad Gebai <mgebai@suse.com>
Wed, 11 Apr 2018 01:30:23 +0000 (21:30 -0400)
committerMohamad Gebai <mgebai@suse.com>
Mon, 16 Apr 2018 13:57:30 +0000 (09:57 -0400)
Signed-off-by: Mohamad Gebai <mgebai@suse.com>
src/ceph.in

index ab636fa61525c56cf493f0f14a875f755ad4fe54..b4a75b09ff9d9a5f9fe492435ec910d32c1a0c70 100755 (executable)
@@ -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