*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
-
-//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP))
-
-//kbuild:lib-$(CONFIG_POWERTOP) += powertop.o
-
//config:config POWERTOP
//config: bool "powertop (9.1 kb)"
//config: default y
//config: help
-//config: Analyze power consumption on Intel-based laptops
+//config: Analyze power consumption on Intel-based laptops
//config:
//config:config FEATURE_POWERTOP_INTERACTIVE
//config: bool "Accept keyboard commands"
//config: default y
//config: depends on POWERTOP
//config: help
-//config: Without this, powertop will only refresh display every 10 seconds.
-//config: No keyboard commands will work, only ^C to terminate.
+//config: Without this, powertop will only refresh display every 10 seconds.
+//config: No keyboard commands will work, only ^C to terminate.
+
+//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_POWERTOP) += powertop.o
// XXX This should be configurable
#define ENABLE_FEATURE_POWERTOP_PROCIRQ 1
/* Max filename length of entry in /sys/devices subsystem */
#define BIG_SYSNAME_LEN 16
+#define ESC "\033"
+
typedef unsigned long long ullong;
struct line {
//usage: "Analyze power consumption on Intel-based laptops"
int powertop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
+int powertop_main(int argc UNUSED_PARAM, char UNUSED_PARAM **argv)
{
ullong cur_usage[MAX_CSTATE_COUNT];
ullong cur_duration[MAX_CSTATE_COUNT];
set_termios_to_raw(STDIN_FILENO, &G.init_settings, TERMIOS_CLEAR_ISIG);
bb_signals(BB_FATAL_SIGS, sig_handler);
/* So we don't forget to reset term settings */
- atexit(reset_term);
+ die_func = reset_term;
#endif
/* Collect initial data */
}
}
- /* Clear the screen */
- printf("\033[H\033[J");
+ /* Home; clear screen */
+ printf(ESC"[H" ESC"[J");
/* Clear C-state lines */
memset(&cstate_lines, 0, sizeof(cstate_lines));
} /* for (;;) */
bb_putchar('\n');
+#if ENABLE_FEATURE_POWERTOP_INTERACTIVE
+ reset_term();
+#endif
return EXIT_SUCCESS;
}