--- projects/libstatgrab/src/saidar/saidar.c 2003/11/07 18:27:35 1.15 +++ projects/libstatgrab/src/saidar/saidar.c 2004/01/05 17:20:30 1.22 @@ -428,23 +428,21 @@ int main(int argc, char **argv){ extern int optind; int c; + time_t last_update = 0; + WINDOW *window; extern int errno; int delay=2; -#ifdef ALLBSD - gid_t gid; -#endif + statgrab_init(); -#ifdef ALLBSD - if((setegid(getgid())) != 0){ - fprintf(stderr, "Failed to lose setgid'ness\n"); + if(statgrab_drop_privileges() != 0){ + fprintf(stderr, "Failed to drop setuid/setgid privileges\n"); return 1; } -#endif - while ((c = getopt(argc, argv, "vhd:")) != EOF){ + while ((c = getopt(argc, argv, "vhd:")) != -1){ switch (c){ case 'd': delay = atoi(optarg); @@ -452,7 +450,6 @@ int main(int argc, char **argv){ fprintf(stderr, "Time must be 1 second or greater\n"); exit(1); } - delay--; break; case 'v': version_num(argv[0]); @@ -462,7 +459,6 @@ int main(int argc, char **argv){ usage(argv[0]); return 1; break; - } } @@ -484,20 +480,23 @@ int main(int argc, char **argv){ display_headings(); for(;;){ + time_t now; int ch = getch(); + if (ch == 'q'){ - endwin(); - return 0; + break; } - get_stats(); + /* To keep the numbers slightly accurate we do not want them + * updating more frequently than once a second. + */ + now = time(NULL); + if ((now - last_update) >= 1) { + get_stats(); + } + last_update = now; display_data(); - - /* To keep the numbers slightly accurate we do not want them updating more - * frequently than once a second. - */ - sleep(1); } endwin();