ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/saidar/saidar.c
(Generate patch)

Comparing projects/libstatgrab/src/saidar/saidar.c (file contents):
Revision 1.12 by tdb, Tue Oct 21 18:01:15 2003 UTC vs.
Revision 1.21 by ats, Mon Jan 5 16:47:43 2004 UTC

# Line 296 | Line 296 | void display_data(){
296          }
297  
298          /* VM */
299 <        if (stats.mem_stats != NULL) {  
299 >        if (stats.mem_stats != NULL && stats.mem_stats->total != 0) {  
300                  move(6, 54);
301                  printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total));
302          }
303 <        if (stats.swap_stats != NULL) {
303 >        if (stats.swap_stats != NULL && stats.swap_stats->total != 0) {
304                  move(7, 54);
305                  printw("%5.2f%%", (100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total));
306          }
307 <        if (stats.mem_stats != NULL && stats.swap_stats != NULL) {      
307 >        if (stats.mem_stats != NULL && stats.swap_stats != NULL &&
308 >            stats.mem_stats->total != 0 && stats.swap_stats->total != 0) {      
309                  move(8, 54);
310                  printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used+stats.swap_stats->used)/(stats.mem_stats->total+stats.swap_stats->total)));
311          }
# Line 427 | Line 428 | int main(int argc, char **argv){
428          extern int optind;
429          int c;
430  
431 +        time_t last_update = 0;
432 +
433          WINDOW *window;
434  
432        int stdin_fileno;
433        fd_set infds;
434        struct timeval timeout;
435
435          extern int errno;
437        char ch;
436  
437          int delay=2;
438 < #ifdef ALLBSD
441 <        gid_t gid;
442 < #endif
438 >
439          statgrab_init();
440   #ifdef ALLBSD
441          if((setegid(getgid())) != 0){
# Line 447 | Line 443 | int main(int argc, char **argv){
443                  return 1;
444          }
445   #endif
446 + #ifdef SOLARIS
447 +        if((seteuid(getuid())) != 0){
448 +                fprintf(stderr, "Failed to lose setuid'ness\n");
449 +                return 1;
450 +        }      
451 + #endif
452                  
453 <        while ((c = getopt(argc, argv, "vhd:")) != EOF){
453 >        while ((c = getopt(argc, argv, "vhd:")) != -1){
454                  switch (c){
455                          case 'd':
456                                  delay = atoi(optarg);
# Line 456 | Line 458 | int main(int argc, char **argv){
458                                          fprintf(stderr, "Time must be 1 second or greater\n");
459                                          exit(1);
460                                  }
459                                delay--;
461                                  break;
462                          case 'v':
463                                  version_num(argv[0]);  
# Line 466 | Line 467 | int main(int argc, char **argv){
467                                  usage(argv[0]);
468                                  return 1;
469                                  break;
469                                
470                  }
471          }
472  
# Line 475 | Line 475 | int main(int argc, char **argv){
475          nonl();
476          cbreak();
477          noecho();
478 +        timeout(delay * 1000);
479          window=newwin(0, 0, 0, 0);
480          clear();
481  
# Line 485 | Line 486 | int main(int argc, char **argv){
486          }
487  
488          display_headings();
488        stdin_fileno=fileno(stdin);
489  
490          for(;;){
491 +                time_t now;
492 +                int ch = getch();
493  
494 <                FD_ZERO(&infds);
495 <                FD_SET(stdin_fileno, &infds);
494 <                timeout.tv_sec = delay;
495 <                timeout.tv_usec = 0;
496 <                
497 <                if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){
498 <                        if(errno!=EINTR){
499 <                                perror("select failed");
500 <                                exit(1);
501 <                        }
494 >                if (ch == 'q'){
495 >                        break;
496                  }
497  
498 <                if(FD_ISSET(stdin_fileno, &infds)){
499 <                        ch=getch();
500 <                        if (ch == 'q'){
501 <                                endwin();
502 <                                return 0;
503 <                        }
498 >                /* To keep the numbers slightly accurate we do not want them
499 >                 * updating more frequently than once a second.
500 >                 */
501 >                now = time(NULL);
502 >                if ((now - last_update) >= 1) {
503 >                        get_stats();
504                  }
505 +                last_update = now;
506  
512                get_stats();
513
507                  display_data();
515
516                /* To keep the numbers slightly accurate we do not want them updating more
517                 * frequently than once a second.
518                 */
519                sleep(1);
508          }      
509  
510          endwin();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines