powertop thinks that select() != 0 means a character can be read. But
select() returns -1 on errors like EINTR. Check for -1 and continue if
it's EINTR, otherwise exit. Also don't rely on tv.tv_sec in that case,
as documented in select(3).

Resizing xterm sends SIGWINCH which used to cause powertop to
exit. This patch fixes it.

Signed-off-by: Per Olofsson <[email protected]>
---
 powertop.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/powertop.c b/powertop.c
index 848f33b..36468c3 100644
--- a/powertop.c
+++ b/powertop.c
@@ -37,6 +37,7 @@
 #include <time.h>
 #include <limits.h>
 #include <sys/stat.h>
+#include <errno.h>
 
 #include "powertop.h"
 
@@ -942,8 +943,12 @@ int main(int argc, char **argv)
 
                key = select(1, &rfds, NULL, NULL, &tv);
 
-               if (key && tv.tv_sec) ticktime = ticktime - tv.tv_sec - 
tv.tv_usec/1000000.0;
+               if (key > 0 && tv.tv_sec) ticktime = ticktime - tv.tv_sec - 
tv.tv_usec/1000000.0;
 
+               if (key == -1 && errno != EINTR) {
+                       perror("select");
+                       exit(EXIT_FAILURE);
+               }
 
                stop_timerstats();
                clear_lines();
@@ -1127,7 +1132,7 @@ int main(int argc, char **argv)
                else
                        ticktime = 45;
 
-               if (key) {
+               if (key > 0) {
                        char keychar;
                        int keystroke = fgetc(stdin);
                        if (keystroke == EOF)
-- 
1.6.5.3

_______________________________________________
Power mailing list
[email protected]
http://www.bughost.org/mailman/listinfo/power

Reply via email to