--- projects/libstatgrab/src/saidar/saidar.c 2003/10/09 16:24:19 1.4 +++ projects/libstatgrab/src/saidar/saidar.c 2003/10/20 15:25:48 1.10 @@ -205,9 +205,22 @@ void display_data(){ diskio_stat_t *diskio_stat_ptr; network_stat_t *network_stat_ptr; disk_stat_t *disk_stat_ptr; + /* Size before it will start overwriting "uptime" */ + char hostname[15]; + char *ptr; move(0,12); - printw("%s", stats.general_stats->hostname); + strncpy(hostname, stats.general_stats->hostname, (sizeof(hostname) - 1)); + /* strncpy does not NULL terminate.. If only strlcpy was on all platforms :) */ + hostname[14] = '\0'; + ptr=strchr(hostname, '.'); + /* Some hosts give back a FQDN for hostname. To avoid this, we'll + * just blank out everything after the first "." + */ + if (ptr != NULL){ + *ptr = '\0'; + } + printw("%s", hostname); move(0,36); printw("%s", hr_uptime(stats.general_stats->uptime)); epoc_time=time(NULL); @@ -247,7 +260,6 @@ void display_data(){ printw("%5d", stats.user_stats->num_entries); /* Mem */ - move(6, 12); printw("%7s", size_conv(stats.mem_stats->total)); move(7, 12); @@ -315,6 +327,7 @@ void display_data(){ network_stat_ptr++; } + /* Disk */ disk_stat_ptr = stats.disk_stats; for(counter=0;counteravail)); move(13+stats.network_entries+counter, 73); - printw("%5.2f%%", 100.00 * ((float)disk_stat_ptr->used / (float)disk_stat_ptr->size)); + printw("%5.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail))); disk_stat_ptr++; } @@ -353,7 +366,7 @@ int get_stats(){ } void version_num(char *progname){ - fprintf(stderr, "%s version %s\n", PACKAGE_VERSION); + fprintf(stderr, "%s version %s\n", progname, PACKAGE_VERSION); fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); exit(1); } @@ -384,7 +397,20 @@ int main(int argc, char **argv){ char ch; int delay=2; - +#ifdef ALLBSD + gid_t gid; +#endif + if(statgrab_init() != 0){ + fprintf(stderr, "statgrab_init failed. Please check the permissions\n"); + return 1; + } +#ifdef ALLBSD + if((setegid(getgid())) != 0){ + fprintf(stderr, "Failed to lose setgid'ness\n"); + return 1; + } +#endif + while ((c = getopt(argc, argv, "vhd:")) != EOF){ switch (c){ case 'd':