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.1
Committed: Mon May 13 16:07:53 2002 UTC (22 years, 4 months ago) by pajs
Content type: text/plain
Branch: MAIN
Log Message:
User stats, who's logged in and how many. Should work fine on everything ;)

File Contents

# User Rev Content
1 pajs 1.1 #include "ukcprog.h"
2     #include <stdlib.h>
3     #include <stdio.h>
4     #include <string.h>
5     #ifdef FREEBSD
6     #include <sys/types.h>
7     #endif
8     #include <utmp.h>
9    
10     char *get_user_stats(){
11     char *xml_user_data;
12     int nousers=0;
13     char *user_list=NULL;
14     char *user_tmp;
15     #if defined(LINUX) || defined(SOLARIS)
16     struct utmp *entry;
17     #endif
18     #ifdef FREEBSD
19     struct utmp entry;
20     FILE *f;
21     #endif
22    
23     #if defined(LINUX) || defined(SOLARIS)
24     while((entry=getutent()) != NULL) {
25     if(entry->ut_type==USER_PROCESS) {
26     user_tmp=user_list;
27     if(user_list==NULL){
28     user_list=strdup(entry->ut_user);
29     }else{
30     user_list=strf("%s %s", user_list, entry->ut_user);
31     }
32     if(user_tmp!=NULL) free(user_tmp);
33     nousers++;
34     }
35     }
36     #endif
37    
38     #ifdef FREEBSD
39     if ((f=fopen(_PATH_UTMP, "r")) == NULL){
40     errf("Failed to open UTMP file (%m)");
41     return NULL;
42     }
43    
44     while((fread(&entry, sizeof(entry),1,f)) != 0){
45     if (entry.ut_name[0] == '\0') continue;
46     user_tmp=user_list;
47     if(user_list==NULL){
48     user_list=strdup(entry.ut_name);
49     }else{
50     user_list=strf("%s %s", user_list, entry.ut_name);
51     }
52     if(user_tmp!=NULL) free(user_tmp);
53     nousers++;
54     }
55     #endif
56     if (user_list==NULL) user_list=strdup("");
57     xml_user_data=strf("<users><list>%s</list><count>%d</count></users>",user_list,nousers);
58     if (user_list==NULL) free(user_list);
59     return xml_user_data;
60     }