Signed-off-by: Daniel Lezcano <daniel.lezc...@free.fr> --- display.c | 28 ++++++++++++++++------------ display.h | 2 +- powerdebug.c | 10 ++++++++-- 3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/display.c b/display.c index cf1d5d7..aee5503 100644 --- a/display.c +++ b/display.c @@ -66,27 +66,31 @@ static void display_fini(void) endwin(); } -void display_init(void) +int display_init(void) { - initscr(); + if (!initscr()) + return -1; + start_color(); + use_default_colors(); + keypad(stdscr, TRUE); noecho(); cbreak(); curs_set(0); nonl(); - use_default_colors(); - - init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK); - init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED); - init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK); - init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW); - init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN); - init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK); - init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE); - init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED); - atexit(display_fini); + if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) || + init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) || + init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) || + init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) || + init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) || + init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) || + init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) || + init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED)) + return -1; + + return atexit(display_fini); } void create_windows(int selectedwindow) diff --git a/display.h b/display.h index d3c875a..044af6c 100644 --- a/display.h +++ b/display.h @@ -22,4 +22,4 @@ #define PT_COLOR_BRIGHT 7 #define PT_COLOR_BLUE 8 -extern void display_init(void); +extern int display_init(void); diff --git a/powerdebug.c b/powerdebug.c index 8244df2..215b0fe 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -261,8 +261,9 @@ int mainloop(struct powerdebug_options *options, struct timeval tval; fd_set readfds; - if (firsttime[0]) - display_init(); + if (firsttime[0] && display_init()) + return -1; + create_windows(options->selectedwindow); show_header(options->selectedwindow); @@ -395,6 +396,11 @@ int main(int argc, char **argv) return 0; } + if (display_init()) { + printf("failed to initialize display\n"); + return 1; + } + if (mainloop(options, regulators_info, numregulators)) return 1; -- 1.7.1 _______________________________________________ linaro-dev mailing list linaro-dev@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-dev