29 |
|
#include <sys/ioctl.h> |
30 |
|
#include <unistd.h> |
31 |
|
#include <stdlib.h> |
32 |
– |
#include <sys/termios.h> |
32 |
|
#include <signal.h> |
33 |
|
#include <errno.h> |
34 |
|
#include <statgrab.h> |
36 |
|
#include <limits.h> |
37 |
|
#include <time.h> |
38 |
|
#include <math.h> |
39 |
+ |
#ifdef AIX |
40 |
+ |
#include <termios.h> |
41 |
+ |
#else |
42 |
+ |
#include <sys/termios.h> |
43 |
+ |
#endif |
44 |
|
|
45 |
|
#ifdef HAVE_NCURSES_H |
46 |
< |
#include <ncurses.h> |
43 |
< |
#else |
44 |
< |
#include <curses.h> |
46 |
> |
#define COLOR_SUPPORT |
47 |
|
#endif |
48 |
+ |
#include CURSES_HEADER_FILE |
49 |
|
|
50 |
|
#define THRESHOLD_LOAD 1.0 |
51 |
|
|
63 |
|
#define THRESHOLD_WARN_DISK 75.0 |
64 |
|
#define THRESHOLD_ALERT_DISK 90.0 |
65 |
|
|
66 |
+ |
int sig_winch_flag = 0; |
67 |
+ |
|
68 |
|
typedef struct{ |
69 |
|
sg_cpu_percents *cpu_percents; |
70 |
|
sg_mem_stats *mem_stats; |
538 |
|
} |
539 |
|
|
540 |
|
void sig_winch_handler(int dummy){ |
541 |
< |
clear(); |
537 |
< |
display_headings(); |
538 |
< |
display_data(0); |
541 |
> |
sig_winch_flag = 1; |
542 |
|
signal(SIGWINCH, sig_winch_handler); |
543 |
|
} |
544 |
|
|
565 |
|
} |
566 |
|
|
567 |
|
void usage(char *progname){ |
568 |
+ |
#ifdef COLOR_SUPPORT |
569 |
|
fprintf(stderr, "Usage: %s [-d delay] [-c] [-v] [-h]\n\n", progname); |
570 |
+ |
#else |
571 |
+ |
fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname); |
572 |
+ |
#endif |
573 |
|
fprintf(stderr, " -d Sets the update time in seconds\n"); |
574 |
+ |
#ifdef COLOR_SUPPORT |
575 |
|
fprintf(stderr, " -c Enables coloured output\n"); |
576 |
+ |
#endif |
577 |
|
fprintf(stderr, " -v Prints version number\n"); |
578 |
|
fprintf(stderr, " -h Displays this help information.\n"); |
579 |
|
fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
599 |
|
return 1; |
600 |
|
} |
601 |
|
|
602 |
+ |
#ifdef COLOR_SUPPORT |
603 |
|
while ((c = getopt(argc, argv, "d:cvh")) != -1){ |
604 |
+ |
#else |
605 |
+ |
while ((c = getopt(argc, argv, "d:vh")) != -1){ |
606 |
+ |
#endif |
607 |
|
switch (c){ |
608 |
|
case 'd': |
609 |
|
delay = atoi(optarg); |
612 |
|
exit(1); |
613 |
|
} |
614 |
|
break; |
615 |
+ |
#ifdef COLOR_SUPPORT |
616 |
|
case 'c': |
617 |
|
colouron = 1; |
618 |
|
break; |
619 |
+ |
#endif |
620 |
|
case 'v': |
621 |
|
version_num(argv[0]); |
622 |
|
break; |
630 |
|
|
631 |
|
signal(SIGWINCH, sig_winch_handler); |
632 |
|
initscr(); |
633 |
+ |
#ifdef COLOR_SUPPORT |
634 |
|
/* turn on colour */ |
635 |
|
if (colouron) { |
636 |
|
if (has_colors()) { |
647 |
|
colouron = 0; |
648 |
|
} |
649 |
|
} |
650 |
+ |
#endif |
651 |
|
nonl(); |
652 |
+ |
curs_set(0); |
653 |
|
cbreak(); |
654 |
|
noecho(); |
655 |
|
timeout(delay * 1000); |
680 |
|
get_stats(); |
681 |
|
} |
682 |
|
last_update = now; |
683 |
+ |
|
684 |
+ |
if(sig_winch_flag) { |
685 |
+ |
clear(); |
686 |
+ |
display_headings(); |
687 |
+ |
sig_winch_flag = 0; |
688 |
+ |
} |
689 |
|
|
690 |
|
display_data(colouron); |
691 |
|
} |