| 428 |
|
extern int optind; |
| 429 |
|
int c; |
| 430 |
|
|
| 431 |
+ |
time_t last_update = 0; |
| 432 |
+ |
|
| 433 |
|
WINDOW *window; |
| 434 |
|
|
| 435 |
|
extern int errno; |
| 436 |
|
|
| 437 |
|
int delay=2; |
| 438 |
< |
#ifdef ALLBSD |
| 437 |
< |
gid_t gid; |
| 438 |
< |
#endif |
| 438 |
> |
|
| 439 |
|
statgrab_init(); |
| 440 |
< |
#ifdef ALLBSD |
| 441 |
< |
if((setegid(getgid())) != 0){ |
| 442 |
< |
fprintf(stderr, "Failed to lose setgid'ness\n"); |
| 440 |
> |
if(statgrab_drop_privileges() != 0){ |
| 441 |
> |
fprintf(stderr, "Failed to drop setuid/setgid privileges\n"); |
| 442 |
|
return 1; |
| 443 |
|
} |
| 445 |
– |
#endif |
| 444 |
|
|
| 445 |
|
while ((c = getopt(argc, argv, "vhd:")) != -1){ |
| 446 |
|
switch (c){ |
| 450 |
|
fprintf(stderr, "Time must be 1 second or greater\n"); |
| 451 |
|
exit(1); |
| 452 |
|
} |
| 455 |
– |
delay--; |
| 453 |
|
break; |
| 454 |
|
case 'v': |
| 455 |
|
version_num(argv[0]); |
| 459 |
|
usage(argv[0]); |
| 460 |
|
return 1; |
| 461 |
|
break; |
| 465 |
– |
|
| 462 |
|
} |
| 463 |
|
} |
| 464 |
|
|
| 480 |
|
display_headings(); |
| 481 |
|
|
| 482 |
|
for(;;){ |
| 483 |
+ |
time_t now; |
| 484 |
|
int ch = getch(); |
| 485 |
+ |
|
| 486 |
|
if (ch == 'q'){ |
| 487 |
< |
endwin(); |
| 490 |
< |
return 0; |
| 487 |
> |
break; |
| 488 |
|
} |
| 489 |
|
|
| 490 |
< |
get_stats(); |
| 490 |
> |
/* To keep the numbers slightly accurate we do not want them |
| 491 |
> |
* updating more frequently than once a second. |
| 492 |
> |
*/ |
| 493 |
> |
now = time(NULL); |
| 494 |
> |
if ((now - last_update) >= 1) { |
| 495 |
> |
get_stats(); |
| 496 |
> |
} |
| 497 |
> |
last_update = now; |
| 498 |
|
|
| 499 |
|
display_data(); |
| 496 |
– |
|
| 497 |
– |
/* To keep the numbers slightly accurate we do not want them updating more |
| 498 |
– |
* frequently than once a second. |
| 499 |
– |
*/ |
| 500 |
– |
sleep(1); |
| 500 |
|
} |
| 501 |
|
|
| 502 |
|
endwin(); |