Author: mladen.turk(a)jboss.com
Date: 2007-10-03 02:19:24 -0400 (Wed, 03 Oct 2007)
New Revision: 1074
Modified:
trunk/sight/native/os/linux/process.c
Log:
Seal Linux process JNI calls
Modified: trunk/sight/native/os/linux/process.c
===================================================================
--- trunk/sight/native/os/linux/process.c 2007-10-02 20:29:19 UTC (rev 1073)
+++ trunk/sight/native/os/linux/process.c 2007-10-03 06:19:24 UTC (rev 1074)
@@ -249,27 +249,27 @@
UNREFERENCED_O;
- if ((rc = sight_create_pool(&pool, sight_temp_pool)) != APR_SUCCESS) {
- throwAprMemoryException(_E, THROW_FMARK, rc);
- return NULL;
+ SIGHT_GLOBAL_TRY {
+ if ((rc = sight_create_pool(&pool, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ SIGHT_GLOBAL_BRK();
+ return NULL;
- }
- if (!(parr = (jint *)apr_palloc(pool, siz))) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
- return NULL;
- }
- if ((rc = enum_pids(pool, parr, SIGHT_MAX_PROCESSES, &pnum)) != APR_SUCCESS) {
- throwAprException(_E, rc);
- goto cleanup;
- }
-
- if (!(rv = (*_E)->NewIntArray(_E, pnum)))
- goto cleanup;
- (*_E)->SetIntArrayRegion(_E, rv, 0, pnum, parr);
-cleanup:
- apr_pool_destroy(pool);
-
+ }
+ if (!(parr = (jint *)apr_palloc(pool, siz))) {
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ SIGHT_GLOBAL_BRK();
+ return NULL;
+ }
+ if ((rc = enum_pids(pool, parr, SIGHT_MAX_PROCESSES, &pnum)) == APR_SUCCESS)
{
+ if ((rv = (*_E)->NewIntArray(_E, pnum)))
+ (*_E)->SetIntArrayRegion(_E, rv, 0, pnum, parr);
+ }
+ else
+ throwAprException(_E, rc);
+ apr_pool_destroy(pool);
+ } SIGHT_GLOBAL_END();
return rv;
}
@@ -453,99 +453,101 @@
return APR_EINVAL;
sprintf(pname, "/proc/%d", pid);
- if ((rv = apr_stat(&i, pname,
- APR_FINFO_MIN | APR_FINFO_OWNER,
- no->pool)) != APR_SUCCESS)
- return rv;
+ SIGHT_LOCAL_TRY(no) {
+ if ((rv = apr_stat(&i, pname,
+ APR_FINFO_MIN | APR_FINFO_OWNER,
+ no->pool)) != APR_SUCCESS) {
+ SIGHT_LOCAL_BRK(no);
+ return rv;
+ }
+ sprintf(pname, "/proc/%d/cmdline", pid);
+ if ((s = sight_fread(pname))) {
+ SET_IFIELD_S(0001, thiz, s);
+ SET_IFIELD_O(0003, thiz, sight_mc_to_sa(_E, s));
+ free(s);
+ }
- sprintf(pname, "/proc/%d/cmdline", pid);
- if ((s = sight_fread(pname))) {
- SET_IFIELD_S(0001, thiz, s);
- SET_IFIELD_O(0003, thiz, sight_mc_to_sa(_E, s));
- free(s);
- }
+ sprintf(pname, "/proc/%d/environ", pid);
+ if ((s = sight_fread(pname))) {
+ SET_IFIELD_O(0004, thiz, sight_mc_to_sa(_E, s));
+ free(s);
+ }
+ sprintf(pname, "/proc/%d/cwd", pid);
+ if ((rc = readlink(pname, psname, SIGHT_HBUFFER_LEN)) > 0 ) {
+ psname[rc] = '\0';
+ SET_IFIELD_S(0018, thiz, psname);
+ }
+ sprintf(pname, "/proc/%d/stat", pid);
+ if ((s = sight_fread(pname))) {
+ int pspid, psppid, pspgid, nthreads;
+ char psstate;
+ unsigned long utime, stime;
+ unsigned long long starttime;
+ sight_procstate_e pstate;
- sprintf(pname, "/proc/%d/environ", pid);
- if ((s = sight_fread(pname))) {
- SET_IFIELD_O(0004, thiz, sight_mc_to_sa(_E, s));
- free(s);
- }
- sprintf(pname, "/proc/%d/cwd", pid);
- if ((rc = readlink(pname, psname, SIGHT_HBUFFER_LEN)) > 0 ) {
- psname[rc] = '\0';
- SET_IFIELD_S(0018, thiz, psname);
- }
- sprintf(pname, "/proc/%d/stat", pid);
- if ((s = sight_fread(pname))) {
- int pspid, psppid, pspgid, nthreads;
- char psstate;
- unsigned long utime, stime;
- unsigned long long starttime;
- sight_procstate_e pstate;
-
- /* fs/proc/array.c for 2.6 kernel (42 fields)
- rc = sscanf(s,
- "%d (%[^)]) %c %d %d %d %d %d %lu %lu "
- "%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu
%lu %lu %lu "
- "%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu %llu",
- fs/proc/array.c for 2.4 kernel (39 fields)
- rc = sscanf(s,
- "%d (%[^)]) %c %d %d %d %d %d %lu %lu "
- "%lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu
%lu %lu %lu "
- "%lu %lu %lu %lu %lu %lu %lu %lu %d %d",
- */
- rc = sscanf(s,
- "%d (%[^)]) %c %d %d %*d %*d %*d %*u %*u "
- "%*u %*u %*u %lu %lu %*d %*d %*d %*d %d "
- "%*d %llu",
- &pspid,
- psname,
- &psstate,
- &psppid,
- &pspgid,
- &utime,
- &stime,
- &nthreads,
- &starttime
- );
- SET_IFIELD_I(0000, thiz, psppid);
- SET_IFIELD_S(0002, thiz, psname);
- switch(psstate) {
- case 'R':
- pstate = SIGHT_PROC_R;
- break;
- case 'S':
- pstate = SIGHT_PROC_S;
- break;
- case 'D':
- pstate = SIGHT_PROC_D;
- break;
- case 'Z':
- pstate = SIGHT_PROC_Z;
- break;
- case 'T':
- pstate = SIGHT_PROC_T;
- break;
- case 'W':
- pstate = SIGHT_PROC_W;
- break;
- case 'X':
- pstate = SIGHT_PROC_X;
- break;
- default:
- pstate = SIGHT_PROC_U;
- break;
+ /* fs/proc/array.c for 2.6 kernel (42 fields)
+ rc = sscanf(s,
+ "%d (%[^)]) %c %d %d %d %d %d %lu %lu "
+ "%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu
%lu %lu %lu %lu "
+ "%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu %llu",
+ fs/proc/array.c for 2.4 kernel (39 fields)
+ rc = sscanf(s,
+ "%d (%[^)]) %c %d %d %d %d %d %lu %lu "
+ "%lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu
%lu %lu %lu %lu "
+ "%lu %lu %lu %lu %lu %lu %lu %lu %d %d",
+ */
+ rc = sscanf(s,
+ "%d (%[^)]) %c %d %d %*d %*d %*d %*u %*u "
+ "%*u %*u %*u %lu %lu %*d %*d %*d %*d %d "
+ "%*d %llu",
+ &pspid,
+ psname,
+ &psstate,
+ &psppid,
+ &pspgid,
+ &utime,
+ &stime,
+ &nthreads,
+ &starttime
+ );
+ SET_IFIELD_I(0000, thiz, psppid);
+ SET_IFIELD_S(0002, thiz, psname);
+ switch(psstate) {
+ case 'R':
+ pstate = SIGHT_PROC_R;
+ break;
+ case 'S':
+ pstate = SIGHT_PROC_S;
+ break;
+ case 'D':
+ pstate = SIGHT_PROC_D;
+ break;
+ case 'Z':
+ pstate = SIGHT_PROC_Z;
+ break;
+ case 'T':
+ pstate = SIGHT_PROC_T;
+ break;
+ case 'W':
+ pstate = SIGHT_PROC_W;
+ break;
+ case 'X':
+ pstate = SIGHT_PROC_X;
+ break;
+ default:
+ pstate = SIGHT_PROC_U;
+ break;
+ }
+ SET_IFIELD_I(0005, thiz, nthreads);
+ SET_IFIELD_J(0012, thiz, apr_time_as_msec(i.ctime));
+ SET_IFIELD_J(0014, thiz, TCK2MS(stime));
+ SET_IFIELD_J(0015, thiz, TCK2MS(utime));
+ SET_IFIELD_J(0016, thiz, P2J(i.user));
+ SET_IFIELD_J(0017, thiz, P2J(i.group));
+ CALL_METHOD1(0000, thiz, pstate);
+ free(s);
}
- SET_IFIELD_I(0005, thiz, nthreads);
- SET_IFIELD_J(0012, thiz, apr_time_as_msec(i.ctime));
- SET_IFIELD_J(0014, thiz, TCK2MS(stime));
- SET_IFIELD_J(0015, thiz, TCK2MS(utime));
- SET_IFIELD_J(0016, thiz, P2J(i.user));
- SET_IFIELD_J(0017, thiz, P2J(i.group));
- CALL_METHOD1(0000, thiz, pstate);
- free(s);
- }
-
+ } SIGHT_LOCAL_END(no);
return APR_SUCCESS;
}