#include "util.h"
#include "internal.h"
#include "wrappers.h"
+#include "wrappers-dirent.h"
+#include "wrappers-vserver.h"
#include <stdio.h>
#include <stdlib.h>
struct ctx_list
{
- int ctx;
+ xid_t ctx;
int process_count;
int VmSize_total;
int VmRSS_total;
long start_time; // start time of process -- seconds since 1-1-70
long stime, utime; // kernel & user-mode CPU time accumulated by process
long cstime, cutime; // cumulative time of process and reaped children
- int s_context;
+ xid_t s_context;
};
char *process_name;
// increment the count number in the ctx record using ctx number
static void
-count_ctx(struct ctx_list *list, struct process_info *process)
+count_ctx(struct ctx_list **ptr, struct process_info *process)
{
- struct ctx_list *prev = list;
+ for (;;) {
+ if (*ptr==0 || (*ptr)->ctx > process->s_context) {
+ *ptr = insert_ctx(process->s_context, *ptr);
+ break;
+ }
- if (process == NULL) return;
+ if ((*ptr)->ctx == process->s_context)
+ break;
- // search
- while(list != NULL)
- {
- // find
- if (list->ctx == process->s_context)
- {
- add_ctx(list, process);
- return;
- }
- // insert between
- if (list->ctx > process->s_context)
- {
- prev->next = insert_ctx(process->s_context, list);
- add_ctx(prev->next, process);
- return;
- }
- // ++
- prev = list;
- list = list->next;
- }
- // add at the end
- prev->next = insert_ctx(process->s_context, NULL);
- add_ctx(prev->next, process);
+ ptr = &(*ptr)->next;
+ }
+
+ add_ctx(*ptr, process);
}
// free mem
// open the process's status file to get the ctx number, and other stat
struct process_info *get_process_info(char *pid)
{
- int fd;
- char buffer[1024];
- char *p;
- size_t idx, l=strlen(pid);
- static struct process_info process;
-
- process.s_context = vc_X_getctx(atoi(pid));
-
+ int fd;
+ char buffer[1024];
+ char *p;
+ size_t idx, l=strlen(pid);
+ static struct process_info process;
+
+ process.s_context = vc_get_task_xid(atoi(pid));
+
+ if (process.s_context==VC_NOCTX) {
+ int err=errno;
+ WRITE_MSG(2, "vc_get_task_xid(");
+ WRITE_STR(2, pid);
+ WRITE_MSG(2, "): ");
+ WRITE_STR(2, strerror(err));
+ WRITE_MSG(2, "\n");
+ }
memcpy(buffer, "/proc/", 6); idx = 6;
memcpy(buffer+idx, pid, l); idx += l;
WRITE_MSG(1, "CTX PROC VSZ RSS userTIME sysTIME UPTIME NAME\n");
while (list!=0) {
- char buf[512];
- char tmp[32];
+ char buf[sizeof(xid_t)*3 + 512];
+ char tmp[sizeof(int)*3 + 2];
size_t l;
memset(buf, ' ', sizeof(buf));
- l = utilvserver_fmt_ulong(buf, list->ctx);
- l = utilvserver_fmt_ulong(tmp, list->process_count);
+ l = utilvserver_fmt_long(buf, list->ctx);
+ l = utilvserver_fmt_long(tmp, list->process_count);
memcpy(buf+10-l, tmp, l);
shortenMem (buf+10, list->VmSize_total);
#if 1
// try to switch in context 1
- if (vc_new_s_context(1,0, 0) < 0)
- {
- perror("vc_new_s_context(#1,...)");
- return EXIT_FAILURE;
- }
+ if (vc_get_task_xid(0)!=1)
+ Evc_new_s_context(1, 0,0);
#endif
// create the fist...
// init with the default name for the context 0
strncpy(my_ctx_list->name, "root server", CTX_NAME_MAX_LEN);
- // open the /proc dir
- if ((proc_dir = opendir(PROC_DIR_NAME)) == NULL) {
- perror("opendir()");
- return EXIT_FAILURE;
- }
-
- chdir(PROC_DIR_NAME);
+
+ Echdir(PROC_DIR_NAME);
+ proc_dir = Eopendir(".");
while ((dir_entry = readdir(proc_dir)) != NULL)
{
// select only process file
continue;
if (atoi(dir_entry->d_name) != my_pid)
- count_ctx(my_ctx_list, get_process_info(dir_entry->d_name));
+ count_ctx(&my_ctx_list, get_process_info(dir_entry->d_name));
}
closedir(proc_dir);