From b608ddda22ac33195ba57311d42ac83facbd8695 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Thu, 16 Feb 2012 00:04:00 +0100 Subject: [PATCH 2/2] better error message Only suggest CONFIG_LATENCYTOP on ENOENT. Print the message after curses is cleaned up to make it visible. --- src/latencytop.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/latencytop.c b/src/latencytop.c index 0ffb7f3..3b62c5d 100644 --- a/src/latencytop.c +++ b/src/latencytop.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE +#include #include #include #include @@ -113,6 +114,17 @@ static void fixup_reason(struct latency_line *line, char *c) strncpy(line->reason, c2, 1024); } +static int die_errno; + +static void print_error_msg(void) { + if (!die_errno) + return; + + fprintf(stderr, "Failed to open /proc/latency_stats: %s\n", strerror(die_errno)); + if (die_errno == ENOENT) + fprintf(stderr, "Please enable the CONFIG_LATENCYTOP configuration in your kernel.\n"); +} + void parse_global_list(void) { FILE *file; @@ -120,8 +132,7 @@ void parse_global_list(void) size_t dummy; file = fopen("/proc/latency_stats","r+"); if (!file) { - fprintf(stderr, "Please enable the CONFIG_LATENCYTOP configuration in your kernel.\n"); - fprintf(stderr, "Exiting...\n"); + die_errno = errno; exit(EXIT_FAILURE); } /* wipe first line */ @@ -540,7 +551,8 @@ int main(int argc, char **argv) enable_sysctl(); atexit(cleanup_sysctl); - + /* needs to run after curses is gone */ + atexit(print_error_msg); #ifdef HAS_GTK_GUI if (preinitialize_gtk_ui(&argc, &argv)) use_gtk = 1; -- 1.7.7.6