*
*/
-#include "libbb.h"
-
-#if ! defined CONFIG_FEATURE_USE_DEVPS_PATCH
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/page.h>
+#include "libbb.h"
extern procps_status_t * procps_scan(int save_user_arg0)
{
if (!dir) {
dir = opendir("/proc");
if(!dir)
- error_msg_and_die("Can't open /proc");
+ bb_error_msg_and_die("Can't open /proc");
}
for(;;) {
if((entry = readdir(dir)) == NULL) {
pid = atoi(name);
curstatus.pid = pid;
+ sprintf(status, "/proc/%d", pid);
+ if(stat(status, &sb))
+ continue;
+ my_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
+
sprintf(status, "/proc/%d/stat", pid);
+
if((fp = fopen(status, "r")) == NULL)
continue;
- if(fstat(fileno(fp), &sb))
- continue;
- my_getpwuid(curstatus.user, sb.st_uid);
name = fgets(buf, sizeof(buf), fp);
fclose(fp);
if(name == NULL)
else
curstatus.state[2] = ' ';
+#ifdef PAGE_SHIFT
curstatus.rss <<= (PAGE_SHIFT - 10); /* 2**10 = 1kb */
+#else
+ curstatus.rss *= (getpagesize() >> 10); /* 2**10 = 1kb */
+#endif
- sprintf(status, "/proc/%d/cmdline", pid);
if(save_user_arg0) {
+ sprintf(status, "/proc/%d/cmdline", pid);
if((fp = fopen(status, "r")) == NULL)
continue;
- if(fgets(buf, sizeof(buf), fp) != NULL) {
- name = strchr(buf, '\n');
- if(name != NULL)
- *name = 0;
+ if((n=fread(buf, 1, sizeof(buf)-1, fp)) > 0) {
+ if(buf[n-1]=='\n')
+ buf[--n] = 0;
+ name = buf;
+ while(n) {
+ if(((unsigned char)*name) < ' ')
+ *name = ' ';
+ name++;
+ n--;
+ }
+ *name = 0;
if(buf[0])
curstatus.cmd = strdup(buf);
/* if NULL it work true also */
}
}
-#endif /* CONFIG_FEATURE_USE_DEVPS_PATCH. Else this file is empty */
-
/* END CODE */
/*
Local Variables: