--- projects/cms/source/ihost/libstatgrab/disk_stat.c 2002/05/18 18:15:56 1.7 +++ projects/cms/source/ihost/libstatgrab/disk_stat.c 2002/05/22 08:54:53 1.12 @@ -1,5 +1,6 @@ /* * i-scream central monitoring system + * http://www.i-scream.org.uk * Copyright (C) 2000-2002 i-scream * * This program is free software; you can redistribute it and/or @@ -116,8 +117,8 @@ char *get_disk_stats(){ } #endif -#ifdef linux - if ((f=fopen("/etc/mtab", "r" ))==NULL){ +#ifdef LINUX + if ((f=setmntent("/etc/mtab", "r" ))==NULL){ errf("Failed to open mounts (%m)"); return NULL; } @@ -153,6 +154,9 @@ char *get_disk_stats(){ sd_ptr->next_disk=sd; sd=sd_ptr; } + + endmntent(f); + #endif #ifdef FREEBSD nummnt=getmntinfo(&mp , MNT_LOCAL); @@ -193,7 +197,7 @@ char *get_disk_stats(){ sd_ptr=sd; xml_disk_stats=strdup(""); - while(sd_ptr!=NULL){ + for(counter=0;sd_ptr!=NULL;counter++){ xml_disk_stats_ptr=xml_disk_stats; if((xml_disk_stats=strf("%s", xml_disk_stats, counter, sd_ptr->disk->device_name, sd_ptr->disk->mnt_point, sd_ptr->disk->size, sd_ptr->disk->used, sd_ptr->disk->avail, sd_ptr->disk->t_inodes, sd_ptr->disk->f_inodes, counter)) == NULL){ errf("strf failed (%m)"); @@ -201,7 +205,6 @@ char *get_disk_stats(){ } free(xml_disk_stats_ptr); sd_ptr=sd_ptr->next_disk; - counter++; } xml_disk_stats_ptr=xml_disk_stats; xml_disk_stats=strf("%s",xml_disk_stats);