Skip to content

Commit 926f91c

Browse files
committed
cephfs-top: fix exception on small sized windows
Fixes "exception: addwstr() returned ERR" when the window width is smaller than expected. Fixes: https://tracker.ceph.com/issues/67859 Signed-off-by: Jos Collin <[email protected]>
1 parent a59f007 commit 926f91c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/tools/cephfs/top/cephfs-top

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,15 @@ class FSTop(FSTopBase):
941941
self.header.addstr(5, 0, help, curses.A_DIM)
942942
return True
943943

944+
def handle_header(self, stats_json, help, screen_title, color_id=0):
945+
try:
946+
return self.create_header(stats_json, help, screen_title, color_id)
947+
except curses.error:
948+
curses.endwin()
949+
sys.stderr.write("Error creating header. Please increase the window width to use "
950+
"cephfs-top.\n")
951+
exit()
952+
944953
def run_display(self):
945954
# clear the pads to have a smooth refresh
946955
self.header.erase()
@@ -990,7 +999,7 @@ class FSTop(FSTopBase):
990999
current_states["limit"] = None
9911000
self.header.erase() # erase previous text
9921001
self.fsstats.erase()
993-
self.create_header(stats_json, help, screen_title, 3)
1002+
self.handle_header(stats_json, help, screen_title, 3)
9941003
else:
9951004
self.tablehead_y = 0
9961005
help = "COMMANDS: " + help_commands
@@ -1003,7 +1012,7 @@ class FSTop(FSTopBase):
10031012
else:
10041013
num_client = len(client_metadata)
10051014
vscrollEnd += num_client
1006-
if self.create_header(stats_json, help, screen_title, 3):
1015+
if self.handle_header(stats_json, help, screen_title, 3):
10071016
self.create_table_header()
10081017
self.create_clients(stats_json, fs)
10091018

@@ -1122,7 +1131,7 @@ class FSTop(FSTopBase):
11221131
current_states["limit"] = None
11231132
self.header.erase() # erase previous text
11241133
self.fsstats.erase()
1125-
self.create_header(stats_json, help, screen_title, 2)
1134+
self.handle_header(stats_json, help, screen_title, 2)
11261135
else:
11271136
self.tablehead_y = 0
11281137
num_client = 0
@@ -1138,7 +1147,7 @@ class FSTop(FSTopBase):
11381147
else:
11391148
num_client = len(client_metadata)
11401149
vscrollEnd += num_client
1141-
if self.create_header(stats_json, help, screen_title, 2):
1150+
if self.handle_header(stats_json, help, screen_title, 2):
11421151
if not index: # do it only for the first fs
11431152
self.create_table_header()
11441153
self.create_clients(stats_json, fs)

0 commit comments

Comments
 (0)