ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/freebsd/freebsd.c
(Generate patch)

Comparing projects/cms/source/host/ihost-perl/plugins/freebsd/freebsd.c (file contents):
Revision 1.4 by pajs, Thu Mar 28 17:42:05 2002 UTC vs.
Revision 1.6 by pajs, Thu Mar 28 18:16:21 2002 UTC

# Line 217 | Line 217 | void systemStats(){
217    }
218    
219    /* Lose are setgid'ness */
220  setegid(gid);
220  
221 +  if ((setegid(gid)) != 0){
222 +    errf("Failed to release permissions, refusing to keep setgid. (%m)");
223 +    die();
224 +  }
225 +
226 +
227    /* ok, just for proof of concept atm, ideally this will need to handle more
228       than one swap device */
229  
# Line 236 | Line 241 | void systemStats(){
241    
242   }
243  
244 + void processStats(){
245 +  int sleeping=-1;
246 +  int zombie=0;
247 +  int stopped=0;
248 +  int running=0;
249 +  char *line;
250 +  char *line_p;
251 +  
252 +  FILE *f;
253 +
254 +  if((f=popen("/bin/ps -ax" , "r")) == NULL) {
255 +    errf("Failed to get process stats (%m)");
256 +    die();
257 +  }
258 +
259 +  while((line=fpgetline(f)) != NULL) {
260 +    line_p=line;
261 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
262 +    line_p=strchr(line_p, ' ');
263 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
264 +    line_p=strchr(line_p, ' ');
265 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
266 +    if (line_p==NULL) abort();
267 +
268 +    if (*line_p=='S') sleeping++;
269 +    if (*line_p=='I') sleeping++;
270 +    if (*line_p=='R') running++;
271 +    if (*line_p=='D') running++;
272 +    if (*line_p=='Z') zombie++;
273 +    if (*line_p=='T') stopped++;
274 +    if (*line_p=='J') running++;
275 +
276 +  }
277 +
278 +  if((pclose(f)) != 0) {
279 +    errf("Failed to close process stats (%m)");
280 +    die();
281 +  }
282 +  
283 +  printf("packet.processes.sleeping %d\n",sleeping);
284 +  printf("packet.processes.cpu %d\n",running);
285 +  printf("packet.processes.zombie %d\n",zombie);
286 +  printf("packet.processes.stopped %d\n", stopped);
287 +  printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
288 +
289 +
290 + }
291 +
292 +
293   int main(){
294    uid=getuid();
295    euid=geteuid();
# Line 243 | Line 297 | int main(){
297    egid=getegid();
298  
299    /* We dont want to run with more permissions than we need, until we need em */
300 <  seteuid(uid);
301 <  setegid(gid);
300 >  if ((setegid(gid)) != 0){
301 >    errf("Failed to release permissions, refusing to keep setgid. (%m)");
302 >    die();
303 >  }
304  
305 + if ((seteuid(uid)) != 0){
306 +    errf("Failed to release permissions, refusing to keep setuid. (%m)");
307 +    die();
308 +  }
309 +
310    diskStats();
311    osStats();
312    loadStats();
313    userStats();
314    systemStats();
315 +  processStats();
316    exit(0);
317   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines