| 1 |
|
#include <stdio.h> |
| 2 |
|
#include <stdlib.h> |
| 3 |
< |
#include "ukcprog.h" |
| 3 |
> |
#include <local/ukcprog.h> |
| 4 |
|
#include <string.h> |
| 5 |
|
#include <unistd.h> |
| 6 |
|
#include <sys/utsname.h> |
| 8 |
|
#include <utmp.h> |
| 9 |
|
#include <pwd.h> |
| 10 |
|
#include <mntent.h> |
| 11 |
+ |
#include <dirent.h> |
| 12 |
+ |
#include <limits.h> |
| 13 |
|
|
| 14 |
|
int die() { |
| 15 |
|
exit (1); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
void processStats() { |
| 253 |
< |
int sleeping=-1; |
| 253 |
> |
int sleeping=0; |
| 254 |
|
int zombie=0; |
| 255 |
|
int stopped=0; |
| 256 |
|
int running=0; |
| 257 |
|
int nousers=0; |
| 258 |
|
char *line; |
| 259 |
< |
char *line_p; |
| 259 |
> |
char *line_ptr; |
| 260 |
|
struct utmp *entry; |
| 261 |
< |
|
| 261 |
> |
DIR *procdir; |
| 262 |
> |
struct dirent *procent; |
| 263 |
> |
char fname[_POSIX_PATH_MAX]; |
| 264 |
|
FILE *f; |
| 265 |
< |
|
| 266 |
< |
if((f=popen("/bin/ps -Al" , "r")) == NULL) { |
| 267 |
< |
errf("Failed to get process stats (%m)"); |
| 268 |
< |
die(); |
| 265 |
> |
|
| 266 |
> |
chdir("/proc"); |
| 267 |
> |
if((procdir=opendir(".")) == NULL){ |
| 268 |
> |
errf("Failed to open proc (%m)"); |
| 269 |
> |
exit(1); |
| 270 |
|
} |
| 266 |
– |
|
| 267 |
– |
while((line=fpgetline(f)) != NULL) { |
| 271 |
|
|
| 272 |
< |
line_p=line; |
| 273 |
< |
for(; (*line_p == ' ') && (*line_p != '\0'); line_p++); |
| 274 |
< |
line_p=strchr(line_p, ' '); |
| 275 |
< |
for(; (*line_p == ' ') && (*line_p != '\0'); line_p++); |
| 276 |
< |
if (line_p==NULL) abort(); |
| 277 |
< |
/* Ok, we should now be at the state :) .. */ |
| 278 |
< |
if (*line_p=='S') sleeping++; |
| 279 |
< |
if (*line_p=='R') running++; |
| 280 |
< |
if (*line_p=='Z') zombie++; |
| 281 |
< |
if (*line_p=='T') stopped++; |
| 272 |
> |
while((procent = readdir(procdir)) != NULL){ |
| 273 |
> |
if(atoi(procent->d_name) == 0) continue; |
| 274 |
> |
strncpy(fname, procent->d_name, _POSIX_PATH_MAX-7); |
| 275 |
> |
strcat(fname, "/status"); |
| 276 |
> |
|
| 277 |
> |
if((f=fopen(fname, "r")) == NULL){ |
| 278 |
> |
errf("Failed to open process stat (%m)"); |
| 279 |
> |
exit(1); |
| 280 |
> |
} |
| 281 |
> |
|
| 282 |
> |
while((line=fpgetline(f)) != NULL){ |
| 283 |
> |
if(strncasecmp(line,"State:",6)==0) break; |
| 284 |
> |
} |
| 285 |
> |
|
| 286 |
> |
line_ptr=line; |
| 287 |
> |
for(;*line_ptr != ' ';line_ptr++); |
| 288 |
> |
line_ptr--; |
| 289 |
> |
|
| 290 |
> |
if(*line_ptr=='R') running++; |
| 291 |
> |
if(*line_ptr=='S') sleeping++; |
| 292 |
> |
if(*line_ptr=='Z') zombie++; |
| 293 |
> |
if(*line_ptr=='T') stopped++; |
| 294 |
> |
if(*line_ptr=='D') stopped++; |
| 295 |
> |
|
| 296 |
|
} |
| 297 |
< |
|
| 298 |
< |
if((pclose(f)) == -1) { |
| 282 |
< |
errf("Failed to close process stats (%m)"); |
| 283 |
< |
die(); |
| 284 |
< |
} |
| 285 |
< |
|
| 297 |
> |
closedir(procdir); |
| 298 |
> |
|
| 299 |
|
printf("packet.users.list"); |
| 300 |
|
|
| 301 |
|
while((entry=getutent()) != NULL) { |