428 |
|
extern int optind; |
429 |
|
int c; |
430 |
|
|
431 |
+ |
time_t last_update = 0; |
432 |
+ |
|
433 |
|
WINDOW *window; |
434 |
|
|
433 |
– |
int stdin_fileno; |
434 |
– |
fd_set infds; |
435 |
– |
struct timeval timeout; |
436 |
– |
|
435 |
|
extern int errno; |
438 |
– |
char ch; |
436 |
|
|
437 |
|
int delay=2; |
438 |
|
#ifdef ALLBSD |
445 |
|
return 1; |
446 |
|
} |
447 |
|
#endif |
448 |
+ |
#ifdef SOLARIS |
449 |
+ |
if((seteuid(getuid())) != 0){ |
450 |
+ |
fprintf(stderr, "Failed to lose setuid'ness\n"); |
451 |
+ |
return 1; |
452 |
+ |
} |
453 |
+ |
#endif |
454 |
|
|
455 |
< |
while ((c = getopt(argc, argv, "vhd:")) != EOF){ |
455 |
> |
while ((c = getopt(argc, argv, "vhd:")) != -1){ |
456 |
|
switch (c){ |
457 |
|
case 'd': |
458 |
|
delay = atoi(optarg); |
460 |
|
fprintf(stderr, "Time must be 1 second or greater\n"); |
461 |
|
exit(1); |
462 |
|
} |
460 |
– |
delay--; |
463 |
|
break; |
464 |
|
case 'v': |
465 |
|
version_num(argv[0]); |
469 |
|
usage(argv[0]); |
470 |
|
return 1; |
471 |
|
break; |
470 |
– |
|
472 |
|
} |
473 |
|
} |
474 |
|
|
477 |
|
nonl(); |
478 |
|
cbreak(); |
479 |
|
noecho(); |
480 |
+ |
timeout(delay * 1000); |
481 |
|
window=newwin(0, 0, 0, 0); |
482 |
|
clear(); |
483 |
|
|
488 |
|
} |
489 |
|
|
490 |
|
display_headings(); |
489 |
– |
stdin_fileno=fileno(stdin); |
491 |
|
|
492 |
|
for(;;){ |
493 |
+ |
time_t now; |
494 |
+ |
int ch = getch(); |
495 |
|
|
496 |
< |
FD_ZERO(&infds); |
497 |
< |
FD_SET(stdin_fileno, &infds); |
495 |
< |
timeout.tv_sec = delay; |
496 |
< |
timeout.tv_usec = 0; |
497 |
< |
|
498 |
< |
if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){ |
499 |
< |
if(errno!=EINTR){ |
500 |
< |
perror("select failed"); |
501 |
< |
exit(1); |
502 |
< |
} |
496 |
> |
if (ch == 'q'){ |
497 |
> |
break; |
498 |
|
} |
499 |
|
|
500 |
< |
if(FD_ISSET(stdin_fileno, &infds)){ |
501 |
< |
ch=getch(); |
502 |
< |
if (ch == 'q'){ |
503 |
< |
endwin(); |
504 |
< |
return 0; |
505 |
< |
} |
500 |
> |
/* To keep the numbers slightly accurate we do not want them |
501 |
> |
* updating more frequently than once a second. |
502 |
> |
*/ |
503 |
> |
now = time(NULL); |
504 |
> |
if ((now - last_update) >= 1) { |
505 |
> |
get_stats(); |
506 |
|
} |
507 |
+ |
last_update = now; |
508 |
|
|
513 |
– |
get_stats(); |
514 |
– |
|
509 |
|
display_data(); |
516 |
– |
|
517 |
– |
/* To keep the numbers slightly accurate we do not want them updating more |
518 |
– |
* frequently than once a second. |
519 |
– |
*/ |
520 |
– |
sleep(1); |
510 |
|
} |
511 |
|
|
512 |
|
endwin(); |