From 596bc2a522c307b7c59e2648a50cb015818d67e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kay=20R=C3=B6pke?= Date: Sun, 31 May 2009 14:10:58 +0200 Subject: [PATCH 1/5] fix Darwin side of SIGAR-47: integer multlipcation overflow on 32bit builds with more than 4GB available memory --- src/os/darwin/darwin_sigar.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index b32e726b..dce7ba6d 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -460,7 +460,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) return status; } - mem->free = vmstat.free_count * sigar->pagesize; + mem->free = vmstat.free_count; + mem->free =* sigar->pagesize; #elif defined(__FreeBSD__) if ((status = sigar_vmstat(sigar, &vmstat)) == SIGAR_OK) { mem->free = vmstat.v_free_count; From 91ba1a2c3ddfee812af81acdc6f5381a2ba9dedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kay=20R=C3=B6pke?= Date: Sun, 31 May 2009 14:32:12 +0200 Subject: [PATCH 2/5] i'm stupid, =* is not going to compile at all. --- src/os/darwin/darwin_sigar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index dce7ba6d..9d71c5ae 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -461,7 +461,7 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) } mem->free = vmstat.free_count; - mem->free =* sigar->pagesize; + mem->free *= sigar->pagesize; #elif defined(__FreeBSD__) if ((status = sigar_vmstat(sigar, &vmstat)) == SIGAR_OK) { mem->free = vmstat.v_free_count; From bace63f7101e064c9ee31095a64bd1340b004df7 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 1 Jun 2009 13:06:41 -0700 Subject: [PATCH 3/5] untabify --- src/os/darwin/darwin_sigar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 9d71c5ae..1007ffb2 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -460,8 +460,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) return status; } - mem->free = vmstat.free_count; - mem->free *= sigar->pagesize; + mem->free = vmstat.free_count; + mem->free *= sigar->pagesize; #elif defined(__FreeBSD__) if ((status = sigar_vmstat(sigar, &vmstat)) == SIGAR_OK) { mem->free = vmstat.v_free_count; From b3abdd5a53badae539ec30956e07e663d123bebb Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 6 Jun 2009 08:38:06 -0700 Subject: [PATCH 4/5] (SIGAR-151) Add Modules support to PTQL --- .../src/org/hyperic/sigar/test/TestPTQL.java | 1 + src/sigar_ptql.c | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java b/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java index 38cf63bc..7f504169 100644 --- a/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java +++ b/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java @@ -61,6 +61,7 @@ public class TestPTQL extends SigarTestCase { "Args.*.eq=org.apache.tools.ant.Main", //'*' == any arg "Args.*.ct=java", //'*' == 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.udp.eq=161,Cred.Uid.eq=0", //root owned snmp port "Port.tcp.eq=8080,Cred.Uid.eq=1003", //dougm owned jboss port diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index 834d6c11..4fc560d4 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -1144,6 +1144,65 @@ static int SIGAPI ptql_args_match(sigar_t *sigar, 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 { const char *key; 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 } }; +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[] = { { 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 }, { "Fd", PTQL_Fd }, { "Args", PTQL_Args }, + { "Modules", PTQL_Modules }, { "Env", PTQL_Env }, { "Port", PTQL_Port }, { "Pid", PTQL_Pid }, From af75428ab6afc65aa15b9f927c2e8ccc8a48f83d Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 17 Jun 2009 17:57:28 -0700 Subject: [PATCH 5/5] darwin sigar_dlinfo_modules impl --- src/os/darwin/darwin_sigar.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 1007ffb2..d18f317c 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -39,6 +39,7 @@ #include #include #include +#include #define __OPENTRANSPORTPROVIDERS__ #include #include @@ -1885,10 +1886,36 @@ int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid, #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; imodule_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, sigar_proc_modules_t *procmods) { -#ifdef SIGAR_HAS_DLINFO_MODULES +#if defined(SIGAR_HAS_DLINFO_MODULES) || defined(DARWIN) if (pid == sigar_pid_get(sigar)) { return sigar_dlinfo_modules(sigar, procmods); }