Merge branch 'sigar-1.6' of git@github.com:hyperic/sigar into sigar-1.6

This commit is contained in:
Doug MacEachern 2009-06-30 16:11:28 -07:00
commit 621f9ccb61
3 changed files with 95 additions and 2 deletions

View File

@ -61,6 +61,7 @@ public class TestPTQL extends SigarTestCase {
"Args.*.eq=org.apache.tools.ant.Main", //'*' == any arg "Args.*.eq=org.apache.tools.ant.Main", //'*' == any arg
"Args.*.ct=java", //'*' == any arg "Args.*.ct=java", //'*' == any arg
"Args.*.ew=sigar.jar", //'*' == any arg "Args.*.ew=sigar.jar", //'*' == any arg
"Modules.*.re=libc|kernel",
"Port.tcp.eq=80,Cred.Uid.eq=0", //root owned http port "Port.tcp.eq=80,Cred.Uid.eq=0", //root owned http port
"Port.udp.eq=161,Cred.Uid.eq=0", //root owned snmp port "Port.udp.eq=161,Cred.Uid.eq=0", //root owned snmp port
"Port.tcp.eq=8080,Cred.Uid.eq=1003", //dougm owned jboss port "Port.tcp.eq=8080,Cred.Uid.eq=1003", //dougm owned jboss port

View File

@ -39,6 +39,7 @@
#include <mach/thread_info.h> #include <mach/thread_info.h>
#include <mach/vm_map.h> #include <mach/vm_map.h>
#include <mach/shared_memory_server.h> #include <mach/shared_memory_server.h>
#include <mach-o/dyld.h>
#define __OPENTRANSPORTPROVIDERS__ #define __OPENTRANSPORTPROVIDERS__
#include <Gestalt.h> #include <Gestalt.h>
#include <CFString.h> #include <CFString.h>
@ -460,7 +461,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
return status; return status;
} }
mem->free = vmstat.free_count * sigar->pagesize; mem->free = vmstat.free_count;
mem->free *= sigar->pagesize;
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
if ((status = sigar_vmstat(sigar, &vmstat)) == SIGAR_OK) { if ((status = sigar_vmstat(sigar, &vmstat)) == SIGAR_OK) {
mem->free = vmstat.v_free_count; mem->free = vmstat.v_free_count;
@ -1884,10 +1886,36 @@ int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
#endif #endif
} }
#ifdef DARWIN
static int sigar_dlinfo_modules(sigar_t *sigar, sigar_proc_modules_t *procmods)
{
uint32_t i, count = _dyld_image_count();
for (i=0; i<count; i++) {
int status;
const char *name =
_dyld_get_image_name(i);
if (name == NULL) {
continue;
}
status =
procmods->module_getter(procmods->data,
(char *)name, strlen(name));
if (status != SIGAR_OK) {
/* not an error; just stop iterating */
break;
}
}
return SIGAR_OK;
}
#endif /* DARWIN */
int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid, int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_modules_t *procmods) sigar_proc_modules_t *procmods)
{ {
#ifdef SIGAR_HAS_DLINFO_MODULES #if defined(SIGAR_HAS_DLINFO_MODULES) || defined(DARWIN)
if (pid == sigar_pid_get(sigar)) { if (pid == sigar_pid_get(sigar)) {
return sigar_dlinfo_modules(sigar, procmods); return sigar_dlinfo_modules(sigar, procmods);
} }

View File

@ -1144,6 +1144,65 @@ static int SIGAPI ptql_args_match(sigar_t *sigar,
return matched ? SIGAR_OK : !SIGAR_OK; return matched ? SIGAR_OK : !SIGAR_OK;
} }
typedef struct {
sigar_t *sigar;
ptql_branch_t *branch;
sigar_uint32_t ix;
int matched;
} proc_modules_match_t;
static int proc_modules_match(void *data, char *name, int len)
{
proc_modules_match_t *matcher =
(proc_modules_match_t *)data;
ptql_branch_t *branch = matcher->branch;
if (branch->op_flags & PTQL_OP_FLAG_GLOB) { /* Modules.*.ct=libc */
matcher->matched =
ptql_str_match(matcher->sigar, branch, name);
if (matcher->matched) {
return !SIGAR_OK; /* stop iterating */
}
}
else {
if (matcher->ix++ == branch->data.ui32) { /* Modules.3.ct=libc */
matcher->matched =
ptql_str_match(matcher->sigar, branch, name);
return !SIGAR_OK; /* stop iterating */
}
}
return SIGAR_OK;
}
static int SIGAPI ptql_modules_match(sigar_t *sigar,
sigar_pid_t pid,
void *data)
{
ptql_branch_t *branch =
(ptql_branch_t *)data;
int status;
sigar_proc_modules_t procmods;
proc_modules_match_t matcher;
matcher.sigar = sigar;
matcher.branch = branch;
matcher.ix = 0;
matcher.matched = 0;
procmods.module_getter = proc_modules_match;
procmods.data = &matcher;
status = sigar_proc_modules_get(sigar, pid, &procmods);
if (status != SIGAR_OK) {
return status;
}
return matcher.matched ? SIGAR_OK : !SIGAR_OK;
}
typedef struct { typedef struct {
const char *key; const char *key;
int klen; int klen;
@ -1316,6 +1375,10 @@ static ptql_lookup_t PTQL_Args[] = {
{ NULL, ptql_args_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_args_branch_init } { NULL, ptql_args_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_args_branch_init }
}; };
static ptql_lookup_t PTQL_Modules[] = {
{ NULL, ptql_modules_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_args_branch_init }
};
static ptql_lookup_t PTQL_Env[] = { static ptql_lookup_t PTQL_Env[] = {
{ NULL, ptql_env_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_branch_init_any } { NULL, ptql_env_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_branch_init_any }
}; };
@ -1342,6 +1405,7 @@ static ptql_entry_t ptql_map[] = {
{ "State", PTQL_State }, { "State", PTQL_State },
{ "Fd", PTQL_Fd }, { "Fd", PTQL_Fd },
{ "Args", PTQL_Args }, { "Args", PTQL_Args },
{ "Modules", PTQL_Modules },
{ "Env", PTQL_Env }, { "Env", PTQL_Env },
{ "Port", PTQL_Port }, { "Port", PTQL_Port },
{ "Pid", PTQL_Pid }, { "Pid", PTQL_Pid },