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

Comparing projects/cms/source/host/ihost-perl/plugins/linux/linux.c (file contents):
Revision 1.9 by pajs, Tue Apr 23 14:22:35 2002 UTC vs.
Revision 1.14 by tdb, Tue May 21 16:47:12 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * http://www.i-scream.org.uk
4 + * Copyright (C) 2000-2002 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.
10 + *
11 + * This program 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.
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.
19 + */
20 +
21   #include <stdio.h>
22   #include <stdlib.h>
23   #include "ukcprog.h"
# Line 8 | Line 28
28   #include <utmp.h>
29   #include <pwd.h>
30   #include <mntent.h>
31 + #include <dirent.h>
32 + #include <limits.h>
33  
34   int die() {
35      exit (1);
# Line 248 | Line 270 | void cpustats() {
270   }
271  
272   void processStats() {
273 <    int sleeping=-1;
273 >    int sleeping=0;
274      int zombie=0;
275      int stopped=0;
276      int running=0;
277      int nousers=0;
278      char *line;
279 <    char *line_p;
279 >    char *line_ptr;
280      struct utmp *entry;
281 <    
281 >    DIR *procdir;
282 >    struct dirent *procent;
283 >    char fname[_POSIX_PATH_MAX];
284      FILE *f;
285 <    
286 <    if((f=popen("/bin/ps -Al" , "r")) == NULL) {
287 <        errf("Failed to get process stats (%m)");
288 <        die();
285 >    
286 >    chdir("/proc");
287 >    if((procdir=opendir(".")) == NULL){
288 >      errf("Failed to open proc (%m)");
289 >      exit(1);
290      }
266    
267    while((line=fpgetline(f)) != NULL) {
291  
292 <      line_p=line;
293 <      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
294 <      line_p=strchr(line_p, ' ');
295 <      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
296 <      if (line_p==NULL) abort();
297 <      /* Ok, we should now be at the state :) .. */
298 <      if (*line_p=='S') sleeping++;
299 <      if (*line_p=='R') running++;
300 <      if (*line_p=='Z') zombie++;
301 <      if (*line_p=='T') stopped++;
292 >    while((procent = readdir(procdir)) != NULL){
293 >      if(atoi(procent->d_name) == 0) continue;
294 >      strncpy(fname, procent->d_name, _POSIX_PATH_MAX-7);
295 >      strcat(fname, "/status");
296 >
297 >      if((f=fopen(fname, "r")) == NULL){
298 >         errf("Failed to open process stat (%m)");
299 >         exit(1);
300 >      }
301 >    
302 >      while((line=fpgetline(f)) != NULL){
303 >         if(strncasecmp(line,"State:",6)==0) break;
304 >      }
305 >
306 >      line_ptr=line;
307 >      for(;*line_ptr++ != '\t';);
308 >    
309 >
310 >      if(*line_ptr=='R') running++;
311 >      if(*line_ptr=='S') sleeping++;
312 >      if(*line_ptr=='Z') zombie++;
313 >      if(*line_ptr=='T') stopped++;
314 >      if(*line_ptr=='D') stopped++;
315 >
316      }
317 <    
318 <    if((pclose(f)) == -1) {
282 <        errf("Failed to close process stats (%m)");
283 <        die();
284 <    }
285 <    
317 >    closedir(procdir);
318 >
319      printf("packet.users.list");
320      
321      while((entry=getutent()) != NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines