On 12/24/2010 1:16 PM, Sergey Senozhatsky wrote:
Hello,
In init_display we call noecho, cbreak and friends. perf_event class has
several exit calls as a reaction to fatal errors, which leaves terminal
in incorrect state. This patch introduces reset_display function. Currently,
it called on perf_event fatal error and before return from main (sorry,
didn't
grep the whole project, If you like the idea - I'll do).
I prefer it to be separate function since it leaves us room to add something
sane (just in case) before exit.
(Sorry for resend, wasn't subsribed for this list).
I like the general idea, but have 2 minor nitpicks
---
display.cpp | 11 +++++++++++
display.h | 3 ++-
main.cpp | 3 +++
perf/perf.cpp | 2 ++
perf/perf.h | 4 +++-
5 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/display.cpp b/display.cpp
index b707984..75fb90c 100644
--- a/display.cpp
+++ b/display.cpp
@@ -72,6 +72,17 @@ void init_display(void)
display = 1;
}
+void reset_display(void)
+{
here we probably want to check the "display" variable to only do the
rest if ncurses was initialized
+ keypad(stdscr, FALSE);
+ echo();
+ nocbreak();
+
+ //resetty();
+ resetterm();
+}
+
+
WINDOW *tab_bar = NULL;
WINDOW *bottom_line = NULL;
diff --git a/display.h b/display.h
index fcf8077..43cdc66 100644
--- a/display.h
+++ b/display.h
@@ -33,6 +33,7 @@
using namespace std;
extern void init_display(void);
+extern void reset_display(void);
extern int ncurses_initialized(void);
extern void show_tab(unsigned int tab);
extern void show_next_tab(void);
@@ -67,4 +68,4 @@ WINDOW *get_ncurses_win(int nr);
void create_tab(string name, class tab_window *w = NULL);
-#endif
\ No newline at end of file
+#endif
diff --git a/main.cpp b/main.cpp
index 0cbda69..2ad19ef 100644
--- a/main.cpp
+++ b/main.cpp
@@ -263,6 +263,9 @@ int main(int argc, char **argv)
learn_parameters(500, 0);
save_parameters("/var/cache/powertop/saved_parameters.powertop");
end_pci_access();
+
+ reset_display();
+
return 0;
diff --git a/perf/perf.cpp b/perf/perf.cpp
index 0ec431e..b0724c1 100644
--- a/perf/perf.cpp
+++ b/perf/perf.cpp
@@ -115,12 +115,14 @@ void perf_event::create_perf_event(char *eventname, int
_cpu)
perf_fd = sys_perf_event_open(&attr, -1, _cpu, -1, 0);
if (perf_fd< 0) {
+ reset_display();
fprintf(stderr, "PowerTOP " POWERTOP_VERSION " needs the kernel to
support the 'perf' subsystem\n");
fprintf(stderr, "as well as support for trace points in the
kernel:\n");
fprintf(stderr,
"CONFIG_PERF_EVENTS=y\nCONFIG_PERF_COUNTERS=y\nCONFIG_TRACEPOINTS=y\nCONFIG_TRACING=y\n");
exit(EXIT_FAILURE);
}
if (read(perf_fd,&read_data, sizeof(read_data)) == -1) {
+ reset_display();
perror("Unable to read perf file descriptor\n");
exit(-1);
}
diff --git a/perf/perf.h b/perf/perf.h
index faeb6b3..e63cd3b 100644
--- a/perf/perf.h
+++ b/perf/perf.h
@@ -29,6 +29,8 @@
using namespace std;
+extern void reset_display(void);
I rather just include display.h than duplicating the prototype..
I can edit the patch to do these things if you want....
_______________________________________________
Discuss mailing list
Discuss@lesswatts.org
http://lists.lesswatts.org/listinfo/discuss