[latencytop/f16] print the error message only after cleaning up curses
Michal Schmidt
michich at fedoraproject.org
Mon Feb 20 08:26:15 UTC 2012
commit 228c18b00566ab35fb1b5d772b7a0c062fbc9bd7
Author: Michal Schmidt <mschmidt at redhat.com>
Date: Sun Feb 19 22:19:40 2012 +0100
print the error message only after cleaning up curses
(cherry picked from commit 498804be9fff0c2f9c58c04ae8672d1cfd234b7e)
...p-better-error-message-if-run-as-non-root.patch | 36 -----------
latencytop-better-error-message.patch | 64 ++++++++++++++++++++
latencytop.spec | 7 ++-
3 files changed, 69 insertions(+), 38 deletions(-)
---
diff --git a/latencytop-better-error-message.patch b/latencytop-better-error-message.patch
new file mode 100644
index 0000000..d432de4
--- /dev/null
+++ b/latencytop-better-error-message.patch
@@ -0,0 +1,64 @@
+From b608ddda22ac33195ba57311d42ac83facbd8695 Mon Sep 17 00:00:00 2001
+From: Michal Schmidt <mschmidt at redhat.com>
+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 <errno.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+@@ -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
+
diff --git a/latencytop.spec b/latencytop.spec
index f3a10ab..f30fddf 100644
--- a/latencytop.spec
+++ b/latencytop.spec
@@ -1,6 +1,6 @@
Name: latencytop
Version: 0.5
-Release: 7%{?dist}
+Release: 8%{?dist}
Summary: System latency monitor (with GUI)
Group: Applications/System
@@ -10,7 +10,7 @@ Source0: http://www.latencytop.org/download/%{name}-%{version}.tar.gz
Patch0: latencytop-Makefile-fixes.patch
Patch1: latencytop-Makefile-default-to-no-gtk.patch
Patch2: latencytop-remove-the-fsync-view.patch
-Patch3: latencytop-better-error-message-if-run-as-non-root.patch
+Patch3: latencytop-better-error-message.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: ncurses-devel glib2-devel gtk2-devel pkgconfig
@@ -86,6 +86,9 @@ rm -rf %{buildroot}
%changelog
+* Sun Feb 19 2012 Michal Schmidt <mschmidt at redhat.com> - 0.5-8
+- Print the error message only after cleaning up curses.
+
* Thu Feb 16 2012 Michal Schmidt <mschmidt at redhat.com> - 0.5-7
- Remove the broken fsync view, stop using the obsolete 'tracing_enabled'.
- Better error message when run as non-root.
More information about the scm-commits
mailing list