--- projects/cms/source/ihost/libstatgrab/user_stats.c 2002/05/13 16:07:53 1.1 +++ projects/cms/source/ihost/libstatgrab/user_stats.c 2002/05/21 16:47:12 1.7 @@ -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 "ukcprog.h" #include #include @@ -21,6 +41,7 @@ char *get_user_stats(){ #endif #if defined(LINUX) || defined(SOLARIS) + setutent(); while((entry=getutent()) != NULL) { if(entry->ut_type==USER_PROCESS) { user_tmp=user_list; @@ -33,6 +54,7 @@ char *get_user_stats(){ nousers++; } } + endutent(); #endif #ifdef FREEBSD @@ -52,9 +74,23 @@ char *get_user_stats(){ if(user_tmp!=NULL) free(user_tmp); nousers++; } + + if ((fclose(f)) != 0) { + errf("Failed to close file (%m)"); + return NULL; + } + #endif - if (user_list==NULL) user_list=strdup(""); - xml_user_data=strf("%s%d",user_list,nousers); - if (user_list==NULL) free(user_list); + if (user_list==NULL){ + if((user_list=strdup("")) == NULL){ + errf("strdup failed (%m)"); + return NULL; + } + } + if((xml_user_data=strf("%s%d",user_list,nousers)) == NULL){ + errf("strf failed (%m)"); + return NULL; + } + if (user_list!=NULL) free(user_list); return xml_user_data; }