--- projects/cms/source/ihost/libstatgrab/disk_stat.c 2002/05/16 17:02:43 1.6 +++ projects/cms/source/ihost/libstatgrab/disk_stat.c 2002/05/21 16:47:12 1.11 @@ -1,3 +1,23 @@ +/* + * 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 + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include #include #include "ukcprog.h" @@ -97,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; } @@ -134,6 +154,12 @@ char *get_disk_stats(){ sd_ptr->next_disk=sd; sd=sd_ptr; } + + if ((endmntent(f)) != 0) { + errf("Failed to close file (%m)"); + return NULL; + } + #endif #ifdef FREEBSD nummnt=getmntinfo(&mp , MNT_LOCAL); @@ -174,7 +200,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)"); @@ -182,7 +208,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);