Merge branch 'sigar-1.6'

This commit is contained in:
Doug MacEachern 2010-04-21 15:44:48 -07:00
commit 6a806d1724
8 changed files with 50 additions and 13 deletions

View File

@ -36,7 +36,7 @@ public class Humidor {
private Object LOCK = new Object();
private InvocationHandler _handler;
private SigarProxy _sigar;
private Sigar _impl;
private Sigar _impl, _inst;
private Humidor() {}
@ -69,7 +69,7 @@ public class Humidor {
synchronized(LOCK) {
if (_sigar == null) {
if (_impl == null) {
_impl = new Sigar();
_inst = _impl = new Sigar();
}
_handler = new MyHandler(_impl);
_sigar = (SigarProxy)
@ -84,4 +84,13 @@ public class Humidor {
public static Humidor getInstance() {
return INSTANCE;
}
//close the Sigar instance if getSigar() created it
public void close() {
if (_inst != null) {
_inst.close();
_impl = _inst = null;
}
_sigar = null;
}
}

View File

@ -204,9 +204,18 @@ public class Shell extends ShellBase {
public void shutdown() {
this.sigar.close();
//avoid possible Class Not Found: junit/framework/TestCase
if (System.getProperty("jni.dmalloc") != null) {
//org.hyperic.sigar.test.SigarTestCase.closeSigar(); //shutup dmalloc
//cleanup for dmalloc
//using reflection incase junit.jar is not present
try {
//SigarTestCase.closeSigar();
Class.forName("org.hyperic.sigar.test.SigarTestCase").
getMethod("closeSigar", new Class[0]).invoke(null, new Object[0]);
} catch (ClassNotFoundException e) {
//SigarTestCase.java not compiled w/o junit.jar
} catch (Exception e) {
e.printStackTrace();
} catch (NoClassDefFoundError e) {
//avoiding possible Class Not Found: junit/framework/TestCase
}
super.shutdown();
}

View File

@ -27,7 +27,9 @@ import java.util.Properties;
import junit.framework.TestCase;
import org.hyperic.sigar.Humidor;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.ptql.ProcessQueryFactory;
//helper to add optional tracing.
public abstract class SigarTestCase extends TestCase {
@ -80,6 +82,8 @@ public abstract class SigarTestCase extends TestCase {
sigar.close();
sigar = null;
}
ProcessQueryFactory.getInstance().clear();
Humidor.getInstance().close();
}
public Properties getProperties() {

View File

@ -116,9 +116,18 @@ public class TestPTQL extends SigarTestCase {
public TestPTQL(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
this.qf = new ProcessQueryFactory();
}
protected void tearDown() throws Exception {
super.tearDown();
this.qf.clear();
}
private int runQuery(Sigar sigar, String qs)
throws MalformedQueryException,
SigarException {
@ -174,7 +183,6 @@ public class TestPTQL extends SigarTestCase {
assertTrue(qs,
runQuery(sigar, qs) >= 0);
}
this.qf.clear();
}
public void testValidRegexQueries() throws Exception {
@ -183,7 +191,6 @@ public class TestPTQL extends SigarTestCase {
assertTrue(qs,
runQuery(getSigar(), qs) >= 0);
}
this.qf.clear();
}
public void testMalformedQueries() throws Exception {
@ -197,7 +204,6 @@ public class TestPTQL extends SigarTestCase {
assertTrue(qs + " Malformed", true);
}
}
this.qf.clear();
}
public void testSelf() throws Exception {

View File

@ -54,6 +54,7 @@ public class TestProcTime extends SigarTestCase {
double value = procTime.getPercent() * 100.0;
traceln("Percent=" + value);
assertTrue(value >= 0.0);
assertTrue(value <= 100.0);
int ncpu = sigar.getCpuList().length;
assertTrue(value <= (100.0 * ncpu)); //SIGAR-145 Irix mode
}
}

View File

@ -153,6 +153,9 @@ int sigar_os_open(sigar_t **sig)
int sigar_os_close(sigar_t *sigar)
{
kstat_close(sigar->kc);
if (sigar->mib2.sd != -1) {
close_mib2(&sigar->mib2);
}
if (sigar->ks.lcpu) {
free(sigar->ks.cpu);
@ -903,7 +906,7 @@ int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
pinfo = sigar->pinfo;
if (pinfo->pr_argc == 0) {
procargs->number = procargs->size = 0;
procargs->number = 0;
return SIGAR_OK;
}
else if (pinfo->pr_dmodel != PR_MODEL_NATIVE) {
@ -955,7 +958,6 @@ int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
if (argvp != argvb) {
free(argvp);
}
sigar_proc_args_destroy(sigar, procargs);
return errno;
}

View File

@ -373,8 +373,13 @@ SIGAR_DECLARE(int) sigar_proc_args_get(sigar_t *sigar,
sigar_pid_t pid,
sigar_proc_args_t *procargs)
{
int status;
sigar_proc_args_create(procargs);
return sigar_os_proc_args_get(sigar, pid, procargs);
status = sigar_os_proc_args_get(sigar, pid, procargs);
if (status != SIGAR_OK) {
sigar_proc_args_destroy(sigar, procargs);
}
return status;
}
int sigar_file_system_list_create(sigar_file_system_list_t *fslist)

View File

@ -546,7 +546,8 @@ static int ptql_branch_list_destroy(ptql_branch_list_t *branches)
}
if (branch->lookup &&
(branch->lookup->type == PTQL_VALUE_TYPE_STR) &&
((branch->lookup->type == PTQL_VALUE_TYPE_STR) ||
(branch->lookup->type == PTQL_VALUE_TYPE_ANY)) &&
!(branch->op_flags & PTQL_OP_FLAG_REF))
{
if (branch->value.str) {