OpenVZ support, contributed by Sergey Lychko

This commit is contained in:
Hisham Muhammad 2007-08-10 05:07:14 +00:00
parent d357c67717
commit 4c51ad0e35
5 changed files with 70 additions and 3 deletions

View File

@ -1,3 +1,9 @@
What's new in version 0.6.7
* OpenVZ support, enabled at compile-time with
the --enable-openvz flag.
(thanks to Sergey Lychko)
What's new in version 0.6.6
* Add support of NLWP field

View File

@ -41,7 +41,11 @@ typedef enum ProcessField_ {
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, LAST_PROCESSFIELD
USER, TIME, NLWP,
#ifdef HAVE_OPENVZ
VEID, VPID,
#endif
LAST_PROCESSFIELD
} ProcessField;
struct ProcessList_;
@ -108,6 +112,10 @@ typedef struct Process_ {
float percent_cpu;
float percent_mem;
char* user;
#ifdef HAVE_OPENVZ
unsigned int veid;
unsigned int vpid;
#endif
} Process;
}*/
@ -119,7 +127,11 @@ char* PROCESS_CLASS = "Process";
#endif
char *Process_fieldNames[] = {
"", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION", "TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT", "UTIME", "STIME", "CUTIME", "CSTIME", "PRIORITY", "NICE", "ITREALVALUE", "STARTTIME", "VSIZE", "RSS", "RLIM", "STARTCODE", "ENDCODE", "STARTSTACK", "KSTKESP", "KSTKEIP", "SIGNAL", "BLOCKED", "SIGIGNORE", "SIGCATCH", "WCHAN", "NSWAP", "CNSWAP", "EXIT_SIGNAL", "PROCESSOR", "M_SIZE", "M_RESIDENT", "M_SHARE", "M_TRS", "M_DRS", "M_LRS", "M_DT", "ST_UID", "PERCENT_CPU", "PERCENT_MEM", "USER", "TIME", "NLWP", "*** report bug! ***"
"", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION", "TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT", "UTIME", "STIME", "CUTIME", "CSTIME", "PRIORITY", "NICE", "ITREALVALUE", "STARTTIME", "VSIZE", "RSS", "RLIM", "STARTCODE", "ENDCODE", "STARTSTACK", "KSTKESP", "KSTKEIP", "SIGNAL", "BLOCKED", "SIGIGNORE", "SIGCATCH", "WCHAN", "NSWAP", "CNSWAP", "EXIT_SIGNAL", "PROCESSOR", "M_SIZE", "M_RESIDENT", "M_SHARE", "M_TRS", "M_DRS", "M_LRS", "M_DT", "ST_UID", "PERCENT_CPU", "PERCENT_MEM", "USER", "TIME", "NLWP",
#ifdef HAVE_OPENVZ
"VEID", "VPID",
#endif
"*** report bug! ***"
};
static int Process_getuid = -1;
@ -363,6 +375,10 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
}
break;
}
#ifdef HAVE_OPENVZ
case VEID: snprintf(buffer, n, "%5u ", this->veid); break;
case VPID: snprintf(buffer, n, "%5u ", this->vpid); break;
#endif
default:
snprintf(buffer, n, "- ");
}
@ -427,6 +443,12 @@ int Process_compare(const void* v1, const void* v2) {
return strcmp(p1->comm, p2->comm);
case NLWP:
return (p1->nlwp - p2->nlwp);
#ifdef HAVE_OPENVZ
case VEID:
return (p1->veid - p2->veid);
case VPID:
return (p1->vpid - p2->vpid);
#endif
default:
return (p1->pid - p2->pid);
}
@ -461,6 +483,10 @@ char* Process_printField(ProcessField field) {
case PERCENT_MEM: return "MEM% ";
case PROCESSOR: return "CPU ";
case NLWP: return "NLWP ";
#ifdef HAVE_OPENVZ
case VEID: return " VEID ";
case VPID: return " VPID ";
#endif
default: return "- ";
}
}

View File

@ -43,7 +43,11 @@ typedef enum ProcessField_ {
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, LAST_PROCESSFIELD
USER, TIME, NLWP,
#ifdef HAVE_OPENVZ
VEID, VPID,
#endif
LAST_PROCESSFIELD
} ProcessField;
struct ProcessList_;
@ -110,6 +114,10 @@ typedef struct Process_ {
float percent_cpu;
float percent_mem;
char* user;
#ifdef HAVE_OPENVZ
unsigned int veid;
unsigned int vpid;
#endif
} Process;

View File

@ -580,6 +580,28 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
if(!existingProcess) {
process->user = UsersTable_getRef(this->usersTable, process->st_uid);
#ifdef HAVE_OPENVZ
if (access("/proc/vz", R_OK) != 0) {
process->vpid = process->pid;
process->veid = 0;
} else {
snprintf(statusfilename, MAX_NAME, "%s/%s/stat", dirname, name);
status = ProcessList_fopen(this, statusfilename, "r");
if (status == NULL)
goto errorReadingProcess;
num = ProcessList_fread(this, status,
"%*u %*s %*c %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u %*u "
"%*u %*u %*u %*u %*u %*u %*u "
"%u %u",
&process->vpid, &process->veid);
fclose(status);
}
#endif
snprintf(statusfilename, MAX_NAME, "%s/%s/cmdline", dirname, name);
status = ProcessList_fopen(this, statusfilename, "r");

View File

@ -58,6 +58,11 @@ AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc fi
fi,
AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem]))
AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
if test "x$enable_openvz" = xyes; then
AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.])
fi
AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find /proc/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find /proc/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))