1 |
< |
/* |
1 |
> |
/* |
2 |
|
* i-scream central monitoring system |
3 |
|
* http://www.i-scream.org |
4 |
< |
* Copyright (C) 2000-2003 i-scream |
4 |
> |
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
6 |
< |
* This program is free software; you can redistribute it and/or |
7 |
< |
* modify it under the terms of the GNU General Public License |
8 |
< |
* as published by the Free Software Foundation; either version 2 |
9 |
< |
* of the License, or (at your option) any later version. |
6 |
> |
* This library is free software; you can redistribute it and/or |
7 |
> |
* modify it under the terms of the GNU Lesser General Public |
8 |
> |
* License as published by the Free Software Foundation; either |
9 |
> |
* version 2.1 of the License, or (at your option) any later version. |
10 |
|
* |
11 |
< |
* This program is distributed in the hope that it will be useful, |
11 |
> |
* This library is distributed in the hope that it will be useful, |
12 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
< |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
< |
* GNU General Public License for more details. |
13 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
> |
* Lesser General Public License for more details. |
15 |
|
* |
16 |
< |
* You should have received a copy of the GNU General Public License |
17 |
< |
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
16 |
> |
* You should have received a copy of the GNU Lesser General Public |
17 |
> |
* License along with this library; if not, write to the Free Software |
18 |
> |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
> |
* 02111-1307 USA |
20 |
> |
* |
21 |
> |
* $Id$ |
22 |
|
*/ |
23 |
|
|
24 |
|
#ifdef HAVE_CONFIG_H |
34 |
|
#include <string.h> |
35 |
|
#endif |
36 |
|
|
37 |
+ |
#include "tools.h" |
38 |
|
#ifdef SOLARIS |
39 |
|
#include <procfs.h> |
40 |
|
#include <limits.h> |
42 |
|
#define MAX_FILE_LENGTH PATH_MAX |
43 |
|
#endif |
44 |
|
#ifdef LINUX |
45 |
< |
#include "tools.h" |
42 |
< |
#include <linux/limits.h> |
45 |
> |
#include <limits.h> |
46 |
|
#define PROC_LOCATION "/proc" |
47 |
|
#define MAX_FILE_LENGTH PATH_MAX |
48 |
|
#endif |
49 |
< |
#ifdef FREEBSD |
50 |
< |
#include <kvm.h> |
48 |
< |
#include <fcntl.h> |
49 |
> |
#ifdef ALLBSD |
50 |
> |
#include <stdlib.h> |
51 |
|
#include <sys/param.h> |
52 |
|
#include <sys/sysctl.h> |
53 |
+ |
#include <sys/proc.h> |
54 |
+ |
#endif |
55 |
+ |
#ifdef FREEBSD |
56 |
|
#include <sys/user.h> |
57 |
|
#endif |
58 |
|
|
72 |
|
#ifdef SOLARIS |
73 |
|
psinfo_t process_info; |
74 |
|
#endif |
75 |
< |
#ifdef FREEBSD |
75 |
> |
#ifdef ALLBSD |
76 |
> |
int mib[3]; |
77 |
> |
size_t size; |
78 |
|
struct kinfo_proc *kp_stats; |
79 |
< |
kvm_t *kvmd = NULL; |
73 |
< |
int procs; |
79 |
> |
int procs, i; |
80 |
|
#endif |
81 |
|
|
82 |
|
process_stat.sleeping=0; |
140 |
|
} |
141 |
|
closedir(proc_dir); |
142 |
|
#endif |
143 |
< |
#ifdef FREEBSD |
144 |
< |
if((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL){ |
143 |
> |
#ifdef ALLBSD |
144 |
> |
mib[0] = CTL_KERN; |
145 |
> |
mib[1] = KERN_PROC; |
146 |
> |
mib[2] = KERN_PROC_ALL; |
147 |
> |
|
148 |
> |
if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) { |
149 |
|
return NULL; |
150 |
|
} |
151 |
+ |
|
152 |
+ |
procs = size / sizeof(struct kinfo_proc); |
153 |
|
|
154 |
< |
kp_stats=kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &procs); |
154 |
> |
kp_stats = malloc(size); |
155 |
> |
if (kp_stats == NULL) { |
156 |
> |
return NULL; |
157 |
> |
} |
158 |
> |
|
159 |
> |
if (sysctl(mib, 3, kp_stats, &size, NULL, 0) < 0) { |
160 |
> |
return NULL; |
161 |
> |
} |
162 |
|
|
163 |
< |
while(procs--){ |
163 |
> |
for (i = 0; i < procs; i++) { |
164 |
|
#ifdef FREEBSD5 |
165 |
< |
if (kp_stats[procs].ki_stat == SSLEEP) process_stat.sleeping++; |
147 |
< |
if (kp_stats[procs].ki_stat == SRUN) process_stat.running++; |
148 |
< |
if (kp_stats[procs].ki_stat == SIDL) process_stat.running++; |
149 |
< |
if (kp_stats[procs].ki_stat == SZOMB) process_stat.zombie++; |
150 |
< |
if (kp_stats[procs].ki_stat == SSTOP) process_stat.stopped++; |
165 |
> |
switch (kp_stats[i].ki_stat) { |
166 |
|
#else |
167 |
< |
if (kp_stats[procs].kp_proc.p_stat == SSLEEP) process_stat.sleeping++; |
153 |
< |
if (kp_stats[procs].kp_proc.p_stat == SRUN) process_stat.running++; |
154 |
< |
if (kp_stats[procs].kp_proc.p_stat == SIDL) process_stat.running++; |
155 |
< |
if (kp_stats[procs].kp_proc.p_stat == SZOMB) process_stat.zombie++; |
156 |
< |
if (kp_stats[procs].kp_proc.p_stat == SSTOP) process_stat.stopped++; |
157 |
< |
process_stat.total++; |
167 |
> |
switch (kp_stats[i].kp_proc.p_stat) { |
168 |
|
#endif |
169 |
+ |
case SSLEEP: |
170 |
+ |
process_stat.sleeping++; |
171 |
+ |
break; |
172 |
+ |
case SRUN: |
173 |
+ |
case SIDL: |
174 |
+ |
process_stat.running++; |
175 |
+ |
break; |
176 |
+ |
case SZOMB: |
177 |
+ |
/*case SDEAD:*/ |
178 |
+ |
process_stat.zombie++; |
179 |
+ |
break; |
180 |
+ |
case SSTOP: |
181 |
+ |
process_stat.stopped++; |
182 |
+ |
break; |
183 |
+ |
} |
184 |
|
} |
185 |
+ |
#endif |
186 |
|
|
187 |
< |
kvm_close(kvmd); |
187 |
> |
free(kp_stats); |
188 |
> |
|
189 |
> |
#ifdef CYGWIN |
190 |
> |
return NULL; |
191 |
|
#endif |
192 |
|
|
164 |
– |
#ifndef FREEBSD5 |
193 |
|
process_stat.total=process_stat.sleeping+process_stat.running+process_stat.zombie+process_stat.stopped; |
166 |
– |
#endif |
194 |
|
|
195 |
|
return &process_stat; |
196 |
|
} |