--- projects/cms/source/ihost/libstatgrab/process_stats.c 2002/05/14 15:54:24 1.1 +++ projects/cms/source/ihost/libstatgrab/process_stats.c 2002/05/19 12:27:32 1.4 @@ -1,3 +1,22 @@ +/* + * i-scream central monitoring system + * 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 "ukcprog.h" #include @@ -99,19 +118,24 @@ char *get_process_stats(){ return NULL; } - while((line=fpgetline(f)) != NULL){ - if(strncasecmp(line,"State:",6)==0) break; - } + while((line=fpgetline(f)) != NULL){ + if(strncasecmp(line,"State:",6)==0) break; + } - line_p=line; - for(;*line_p++ != '\t';); + line_p=line; + for(;*line_p++ != '\t';); - if(*line_p=='R') running++; - if(*line_p=='S') sleeping++; - if(*line_p=='Z') zombie++; - if(*line_p=='T') stopped++; - if(*line_p=='D') stopped++; + if(*line_p=='R') running++; + if(*line_p=='S') sleeping++; + if(*line_p=='Z') zombie++; + if(*line_p=='T') stopped++; + if(*line_p=='D') stopped++; + + if ((fclose(f)) != 0) { + errf("Failed to close file (%m)"); + return NULL; + } } closedir(procdir); @@ -123,9 +147,4 @@ char *get_process_stats(){ return NULL; } return xml_ps_stats; -} - -int main(){ - printf("%s", get_process_stats()); - exit(0); }