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.11 by ats, Mon Oct 20 22:35:14 2003 UTC vs.
Revision 1.25 by tdb, Wed Jan 21 10:27:46 2004 UTC

# Line 1 | Line 1
1   /*
2   * i-scream central monitoring system
3   * http://www.i-scream.org
4 < * Copyright (C) 2000-2002 i-scream
4 > * Copyright (C) 2000-2004 i-scream
5   *
6   * This program is free software; you can redistribute it and/or
7   * modify it under the terms of the GNU General Public License
# Line 16 | Line 16
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + *
20 + * $Id$
21   */
22  
23   #ifdef HAVE_CONFIG_H
# Line 295 | Line 297 | void display_data(){
297                  printw("%8s", size_conv(stats.swap_stats->free));
298          }
299  
300 <        if (stats.mem_stats != NULL && stats.swap_stats != NULL) {      
301 <                /* VM */
300 >        /* VM */
301 >        if (stats.mem_stats != NULL && stats.mem_stats->total != 0) {  
302                  move(6, 54);
303                  printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total));
304 +        }
305 +        if (stats.swap_stats != NULL && stats.swap_stats->total != 0) {
306                  move(7, 54);
307                  printw("%5.2f%%", (100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total));
308 +        }
309 +        if (stats.mem_stats != NULL && stats.swap_stats != NULL &&
310 +            stats.mem_stats->total != 0 && stats.swap_stats->total != 0) {      
311                  move(8, 54);
312                  printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used+stats.swap_stats->used)/(stats.mem_stats->total+stats.swap_stats->total)));
313          }
# Line 423 | Line 430 | int main(int argc, char **argv){
430          extern int optind;
431          int c;
432  
433 +        time_t last_update = 0;
434 +
435          WINDOW *window;
436  
428        int stdin_fileno;
429        fd_set infds;
430        struct timeval timeout;
431
437          extern int errno;
433        char ch;
438  
439          int delay=2;
440 < #ifdef ALLBSD
437 <        gid_t gid;
438 < #endif
440 >
441          statgrab_init();
442 < #ifdef ALLBSD
443 <        if((setegid(getgid())) != 0){
442 <                fprintf(stderr, "Failed to lose setgid'ness\n");
442 >        if(statgrab_drop_privileges() != 0){
443 >                fprintf(stderr, "Failed to drop setuid/setgid privileges\n");
444                  return 1;
445          }
445 #endif
446                  
447 <        while ((c = getopt(argc, argv, "vhd:")) != EOF){
447 >        while ((c = getopt(argc, argv, "vhd:")) != -1){
448                  switch (c){
449                          case 'd':
450                                  delay = atoi(optarg);
451 <                                if (delay == 0){
451 >                                if (delay < 1){
452                                          fprintf(stderr, "Time must be 1 second or greater\n");
453                                          exit(1);
454                                  }
455                                delay--;
455                                  break;
456                          case 'v':
457                                  version_num(argv[0]);  
# Line 462 | Line 461 | int main(int argc, char **argv){
461                                  usage(argv[0]);
462                                  return 1;
463                                  break;
465                                
464                  }
465          }
466  
# Line 471 | Line 469 | int main(int argc, char **argv){
469          nonl();
470          cbreak();
471          noecho();
472 +        timeout(delay * 1000);
473          window=newwin(0, 0, 0, 0);
474          clear();
475  
# Line 481 | Line 480 | int main(int argc, char **argv){
480          }
481  
482          display_headings();
484        stdin_fileno=fileno(stdin);
483  
484          for(;;){
485 +                time_t now;
486 +                int ch = getch();
487  
488 <                FD_ZERO(&infds);
489 <                FD_SET(stdin_fileno, &infds);
490 <                timeout.tv_sec = delay;
491 <                timeout.tv_usec = 0;
492 <                
493 <                if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){
494 <                        if(errno!=EINTR){
495 <                                perror("select failed");
496 <                                exit(1);
497 <                        }
488 >                if (ch == 'q'){
489 >                        break;
490                  }
491  
492 <                if(FD_ISSET(stdin_fileno, &infds)){
493 <                        ch=getch();
494 <                        if (ch == 'q'){
495 <                                endwin();
496 <                                return 0;
497 <                        }
492 >                /* To keep the numbers slightly accurate we do not want them
493 >                 * updating more frequently than once a second.
494 >                 */
495 >                now = time(NULL);
496 >                if ((now - last_update) >= 1) {
497 >                        get_stats();
498                  }
499 +                last_update = now;
500  
508                get_stats();
509
501                  display_data();
511
512                /* To keep the numbers slightly accurate we do not want them updating more
513                 * frequently than once a second.
514                 */
515                sleep(1);
502          }      
503  
504          endwin();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines