Merge branch 'SIGAR-151' into sigar-1.6

This commit is contained in:
Doug MacEachern 2009-06-06 08:38:30 -07:00
commit bb5fec3790
2 changed files with 65 additions and 0 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

@ -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 },