ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/ihost/libstatgrab/user_stats.c
Revision: 1.3
Committed: Sat May 18 18:15:56 2002 UTC (22 years, 6 months ago) by tdb
Content type: text/plain
Branch: MAIN
Changes since 1.2: +19 -0 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.3 /*
2     * i-scream central monitoring system
3     * Copyright (C) 2000-2002 i-scream
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19    
20 pajs 1.1 #include "ukcprog.h"
21     #include <stdlib.h>
22     #include <stdio.h>
23     #include <string.h>
24     #ifdef FREEBSD
25     #include <sys/types.h>
26     #endif
27     #include <utmp.h>
28    
29     char *get_user_stats(){
30     char *xml_user_data;
31     int nousers=0;
32     char *user_list=NULL;
33     char *user_tmp;
34     #if defined(LINUX) || defined(SOLARIS)
35     struct utmp *entry;
36     #endif
37     #ifdef FREEBSD
38     struct utmp entry;
39     FILE *f;
40     #endif
41    
42     #if defined(LINUX) || defined(SOLARIS)
43     while((entry=getutent()) != NULL) {
44     if(entry->ut_type==USER_PROCESS) {
45     user_tmp=user_list;
46     if(user_list==NULL){
47     user_list=strdup(entry->ut_user);
48     }else{
49     user_list=strf("%s %s", user_list, entry->ut_user);
50     }
51     if(user_tmp!=NULL) free(user_tmp);
52     nousers++;
53     }
54     }
55     #endif
56    
57     #ifdef FREEBSD
58     if ((f=fopen(_PATH_UTMP, "r")) == NULL){
59     errf("Failed to open UTMP file (%m)");
60     return NULL;
61     }
62    
63     while((fread(&entry, sizeof(entry),1,f)) != 0){
64     if (entry.ut_name[0] == '\0') continue;
65     user_tmp=user_list;
66     if(user_list==NULL){
67     user_list=strdup(entry.ut_name);
68     }else{
69     user_list=strf("%s %s", user_list, entry.ut_name);
70     }
71     if(user_tmp!=NULL) free(user_tmp);
72     nousers++;
73     }
74     #endif
75     if (user_list==NULL) user_list=strdup("");
76     xml_user_data=strf("<users><list>%s</list><count>%d</count></users>",user_list,nousers);
77 pajs 1.2 if (user_list!=NULL) free(user_list);
78 pajs 1.1 return xml_user_data;
79     }