--- projects/cms/source/ihost/libstatgrab/load_stat.c 2002/05/12 19:10:55 1.1 +++ projects/cms/source/ihost/libstatgrab/load_stat.c 2002/05/29 19:41:59 1.8 @@ -1,24 +1,54 @@ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include +#ifdef SOLARIS +#include +#endif #include "ukcprog.h" -char* get_load_stats(){ +char *get_load_stats(){ double loadav[3]; char *xml_load_out; -#ifdef OLDLINUX +#ifndef HAVE_GETLOADAVG FILE *f; char *loadavg; char *load_p; #endif -#ifdef OLDLINUX +#ifndef HAVE_GETLOADAVG if ((f=fopen("/proc/loadavg", "r" ))==NULL) { errf("Failed to open load averages (%m)"); return NULL; } - fscanf(f,"%lf %lf %lf", &loadav[0], &loadav[1], &loadav[2]); + if((fscanf(f,"%lf %lf %lf", &loadav[0], &loadav[1], &loadav[2])) != 3){ + errf("Failed to read in sufficent loads"); + return NULL; + } if ((fclose(f)) != 0) { errf("Failed to close file (%m)."); @@ -30,7 +60,7 @@ char* get_load_stats(){ } #endif - xml_load_out=strf("%.2lf%.2lf%.2lf\n", loadav[0], loadav[1], loadav[2]); + xml_load_out=strf("%.2lf%.2lf%.2lf", loadav[0], loadav[1], loadav[2]); return xml_load_out; }