JBoss Native SVN: r1070 - trunk/sight/native/os/windows.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-01 06:24:15 -0400 (Mon, 01 Oct 2007)
New Revision: 1070
Modified:
trunk/sight/native/os/windows/console.c
trunk/sight/native/os/windows/netadapter.c
trunk/sight/native/os/windows/tcpstat.c
trunk/sight/native/os/windows/udpstat.c
trunk/sight/native/os/windows/wmi.cpp
Log:
Use sight wrappers for malloc/calloc
Modified: trunk/sight/native/os/windows/console.c
===================================================================
--- trunk/sight/native/os/windows/console.c 2007-10-01 09:27:34 UTC (rev 1069)
+++ trunk/sight/native/os/windows/console.c 2007-10-01 10:24:15 UTC (rev 1070)
@@ -253,11 +253,12 @@
if (!con) {
return NULL;
}
- if (!(wBuf = calloc(1, MAX_CONSOLE_SIZE * sizeof(jchar)))) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
+ if (!(wBuf = (jchar *)sight_calloc(_E,
+ MAX_CONSOLE_SIZE * sizeof(jchar),
+ THROW_FMARK))) {
return NULL;
}
+
if (!ReadConsoleW(con->hConI,
wBuf,
MAX_CONSOLE_SIZE,
Modified: trunk/sight/native/os/windows/netadapter.c
===================================================================
--- trunk/sight/native/os/windows/netadapter.c 2007-10-01 09:27:34 UTC (rev 1069)
+++ trunk/sight/native/os/windows/netadapter.c 2007-10-01 10:24:15 UTC (rev 1070)
@@ -270,9 +270,8 @@
ULONG outBufLen = 0;
UNREFERENCED_O;
- if (!(e = (net_adapter_enum_t *)calloc(1, sizeof(net_adapter_enum_t)))) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
+ if (!(e = (net_adapter_enum_t *)sight_calloc(_E, sizeof(net_adapter_enum_t),
+ THROW_FMARK))) {
return 0;
}
@@ -283,10 +282,7 @@
throwAprException(_E, APR_FROM_OS_ERROR(rc));
goto cleanup;
}
- e->pInfo = (PIP_ADAPTER_INFO)malloc(outBufLen);
- if (!e->pInfo) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
+ if (!(e->pInfo = (PIP_ADAPTER_INFO)sight_malloc(_E, outBufLen, THROW_FMARK))) {
goto cleanup;
}
// Make a second call to GetAdapters Addresses to get the
@@ -372,7 +368,7 @@
}
else if (!e->pCurrent->IfIndex) {
sprintf(buf, "net%d", e->devCounters[5]++);
- SET_IFIELD_S(0000, thiz, buf);
+ SET_IFIELD_S(0000, thiz, buf);
}
else
SET_IFIELD_S(0000, thiz, e->pCurrent->AdapterName);
Modified: trunk/sight/native/os/windows/tcpstat.c
===================================================================
--- trunk/sight/native/os/windows/tcpstat.c 2007-10-01 09:27:34 UTC (rev 1069)
+++ trunk/sight/native/os/windows/tcpstat.c 2007-10-01 10:24:15 UTC (rev 1070)
@@ -241,9 +241,9 @@
type = 0;
}
- if (!(e = (tcpconn_enum_t *)calloc(1, sizeof(tcpconn_enum_t)))) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
+
+ if (!(e = (tcpconn_enum_t *)sight_calloc(_E, sizeof(tcpconn_enum_t),
+ THROW_FMARK))) {
return 0;
}
e->type = type;
@@ -380,7 +380,7 @@
strcpy(las, inet_ntoa(ial));
strcpy(ras, inet_ntoa(iar));
lp = ntohs((unsigned short)(0x0000FFFF & e->p4->table[index].dwLocalPort));
- rp = ntohs((unsigned short)(0x0000FFFF & e->p4->table[index].dwRemotePort));
+ rp = ntohs((unsigned short)(0x0000FFFF & e->p4->table[index].dwRemotePort));
state = e->p4->table[index].dwState;
pid = e->p4->table[index].dwOwningPid;
cts = litime_to_ms(&(e->p4->table[index].liCreateTimestamp));
Modified: trunk/sight/native/os/windows/udpstat.c
===================================================================
--- trunk/sight/native/os/windows/udpstat.c 2007-10-01 09:27:34 UTC (rev 1069)
+++ trunk/sight/native/os/windows/udpstat.c 2007-10-01 10:24:15 UTC (rev 1070)
@@ -170,9 +170,8 @@
type = 0;
}
- if (!(e = (udpconn_enum_t *)calloc(1, sizeof(udpconn_enum_t)))) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
+ if (!(e = (udpconn_enum_t *)sight_calloc(_E, sizeof(udpconn_enum_t),
+ THROW_FMARK))) {
return 0;
}
e->type = type;
Modified: trunk/sight/native/os/windows/wmi.cpp
===================================================================
--- trunk/sight/native/os/windows/wmi.cpp 2007-10-01 09:27:34 UTC (rev 1069)
+++ trunk/sight/native/os/windows/wmi.cpp 2007-10-01 10:24:15 UTC (rev 1070)
@@ -99,10 +99,8 @@
cosec_inited = 1;
}
- wd = (wmi_data_t *)calloc(1, sizeof(wmi_data_t));
- if (!wd) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
+ if (!(wd = (wmi_data_t *)sight_calloc(_E, sizeof(wmi_data_t),
+ THROW_FMARK))) {
return NULL;
}
hres = CoCreateInstance(
17 years, 2 months
JBoss Native SVN: r1069 - trunk/sight/native/os/windows.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-01 05:27:34 -0400 (Mon, 01 Oct 2007)
New Revision: 1069
Modified:
trunk/sight/native/os/windows/scm.c
trunk/sight/native/os/windows/service.c
Log:
Seal Windows service JNI calls
Modified: trunk/sight/native/os/windows/scm.c
===================================================================
--- trunk/sight/native/os/windows/scm.c 2007-10-01 08:54:47 UTC (rev 1068)
+++ trunk/sight/native/os/windows/scm.c 2007-10-01 09:27:34 UTC (rev 1069)
@@ -78,13 +78,15 @@
SIGHT_FREE_WSTRING(database);
return APR_EINVAL;
}
- if (no->native)
- CloseServiceHandle(no->native);
- no->native = OpenSCManagerW(NULL, J2C(database), mode);
- if (!no->native)
- rc = GetLastError();
- else
- no->clean = scm_cleanup;
+ SIGHT_LOCAL_TRY(no) {
+ if (no->native)
+ CloseServiceHandle(no->native);
+ no->native = OpenSCManagerW(NULL, J2C(database), mode);
+ if (!no->native)
+ rc = GetLastError();
+ else
+ no->clean = scm_cleanup;
+ } SIGHT_LOCAL_END(no);
SIGHT_FREE_WSTRING(database);
return APR_FROM_OS_ERROR(rc);
}
@@ -98,9 +100,11 @@
if (no && no->native) {
- CloseServiceHandle(no->native);
- no->native = NULL;
- no->clean = NULL;
+ SIGHT_LOCAL_TRY(no) {
+ CloseServiceHandle(no->native);
+ no->native = NULL;
+ no->clean = NULL;
+ } SIGHT_LOCAL_END(no);
}
}
@@ -123,78 +127,82 @@
void *lpBuffer = NULL;
svc_enum_t *head = NULL;
svc_enum_t *list = NULL;
+
if (!no || !no->pool || !no->native) {
return NULL;
}
if (drivers)
- dwServiceType = SERVICE_DRIVER;
+ dwServiceType = SERVICE_DRIVER;
else
- dwServiceType = SERVICE_WIN32;
+ dwServiceType = SERVICE_WIN32;
if (what == 1)
- dwServiceState = SERVICE_ACTIVE;
+ dwServiceState = SERVICE_ACTIVE;
else if (what == 2)
- dwServiceState = SERVICE_INACTIVE;
+ dwServiceState = SERVICE_INACTIVE;
+ SIGHT_LOCAL_TRY(no) {
+ do {
+ rt = EnumServicesStatusExA(no->native,
+ SC_ENUM_PROCESS_INFO,
+ dwServiceType,
+ dwServiceState,
+ (LPBYTE)lpBuffer,
+ dwSize,
+ &dwSize,
+ &dwNumServices,
+ &dwResumeHandle,
+ NULL);
+ if (!rt && ((rc = GetLastError()) != ERROR_MORE_DATA)) {
+ throwAprException(_E, APR_FROM_OS_ERROR(rc));
+ ea = NULL;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ if (dwNumServices > 0) {
- do {
- rt = EnumServicesStatusExA(no->native,
- SC_ENUM_PROCESS_INFO,
- dwServiceType,
- dwServiceState,
- (LPBYTE)lpBuffer,
- dwSize,
- &dwSize,
- &dwNumServices,
- &dwResumeHandle,
- NULL);
- if (!rt && ((rc = GetLastError()) != ERROR_MORE_DATA)) {
- throwAprException(_E, APR_FROM_OS_ERROR(rc));
+
+ }
+ if (!rt) {
+ if (!(list = (svc_enum_t *)sight_malloc(_E,
+ dwSize + sizeof(svc_enum_t),
+ THROW_FMARK))) {
+ ea = NULL;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ list->next = head;
+ lpBuffer = &list->data[0];
+ /* TODO: Make list ordered as its populated */
+ head = list;
+ }
+ list->size = dwNumServices;
+ cnt += list->size;
+ } while (!rt);
+
+ ea = sight_new_cc_array(_E, SIGHT_CC_STRING, cnt);
+ if (!ea || (*_E)->ExceptionCheck(_E)) {
ea = NULL;
+ SIGHT_LOCAL_BRK(no);
goto cleanup;
}
- if (dwNumServices > 0) {
-
-
- }
- if (!rt) {
- if (!(list = (svc_enum_t *)sight_malloc(_E,
- dwSize + sizeof(svc_enum_t),
- THROW_FMARK))) {
- ea = NULL;
- goto cleanup;
+ while (head) {
+ DWORD i;
+ lpService = (LPENUM_SERVICE_STATUS_PROCESSA)&head->data[0];
+ for (i = 0; i < head->size; i++) {
+ jstring s = (*_E)->NewStringUTF(_E, lpService[i].lpServiceName);
+ if (s)
+ (*_E)->SetObjectArrayElement(_E, ea, idx++, s);
+ else
+ break;
+ if ((*_E)->ExceptionCheck(_E)) {
+ ea = NULL;
+ break;
+ }
+ (*_E)->DeleteLocalRef(_E, s);
}
- list->next = head;
- lpBuffer = &list->data[0];
- /* TODO: Make list ordered as its populated */
- head = list;
+ head = head->next;
}
- list->size = dwNumServices;
- cnt += list->size;
- } while (!rt);
-
- ea = sight_new_cc_array(_E, SIGHT_CC_STRING, cnt);
- if (!ea || (*_E)->ExceptionCheck(_E)) {
- ea = NULL;
- goto cleanup;
- }
- while (head) {
- DWORD i;
- lpService = (LPENUM_SERVICE_STATUS_PROCESSA)&head->data[0];
- for (i = 0; i < head->size; i++) {
- jstring s = (*_E)->NewStringUTF(_E, lpService[i].lpServiceName);
- if (s)
- (*_E)->SetObjectArrayElement(_E, ea, idx++, s);
- else
- break;
- if ((*_E)->ExceptionCheck(_E)) {
- ea = NULL;
- break;
- }
- (*_E)->DeleteLocalRef(_E, s);
- }
- head = head->next;
- }
-
+ } SIGHT_LOCAL_END(no);
cleanup:
free_enum_list(head);
return ea;
Modified: trunk/sight/native/os/windows/service.c
===================================================================
--- trunk/sight/native/os/windows/service.c 2007-10-01 08:54:47 UTC (rev 1068)
+++ trunk/sight/native/os/windows/service.c 2007-10-01 09:27:34 UTC (rev 1069)
@@ -173,85 +173,95 @@
SIGHT_FREE_CSTRING(name);
return APR_EINVAL;
}
- hscm = ns->native;
- if (no->native) {
- CloseServiceHandle(no->native);
- no->native = NULL;
- }
- hsvc = OpenServiceA(hscm, J2S(name), (DWORD)access);
- if (IS_INVALID_HANDLE(hsvc)) {
- rc = GetLastError();
- goto cleanup;
- }
+ SIGHT_LOCAL_TRY(no) {
+ hscm = ns->native;
+ if (no->native) {
+ CloseServiceHandle(no->native);
+ no->native = NULL;
+ }
+ hsvc = OpenServiceA(hscm, J2S(name), (DWORD)access);
+ if (IS_INVALID_HANDLE(hsvc)) {
+ rc = GetLastError();
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
- if (!QueryServiceConfigW(hsvc, NULL,
- 0, &cbBytesNeeded)) {
- rc = GetLastError();
- if (rc == ERROR_INSUFFICIENT_BUFFER) {
+ if (!QueryServiceConfigW(hsvc, NULL,
+ 0, &cbBytesNeeded)) {
+ rc = GetLastError();
+ if (rc == ERROR_INSUFFICIENT_BUFFER) {
+ cbBufSize = cbBytesNeeded;
+ lpServiceConfig = (LPQUERY_SERVICE_CONFIGW)malloc(cbBufSize);
+ if (!lpServiceConfig) {
+ rc = ERROR_OUTOFMEMORY;
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ if (!QueryServiceConfigW(hsvc, lpServiceConfig,
+ cbBufSize, &cbBytesNeeded)) {
+ rc = GetLastError();
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ }
+ else {
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ }
+ SET_IFIELD_W(0001, thiz, lpServiceConfig->lpBinaryPathName);
+ SET_IFIELD_O(0002, thiz, sight_mw_to_sa(_E, lpServiceConfig->lpDependencies));
+ SET_IFIELD_W(0003, thiz, lpServiceConfig->lpServiceStartName);
+ SET_IFIELD_W(0004, thiz, lpServiceConfig->lpDisplayName);
+ SET_IFIELD_W(0006, thiz, lpServiceConfig->lpLoadOrderGroup);
+
+ if (!QueryServiceConfig2W(hsvc, SERVICE_CONFIG_DESCRIPTION,
+ NULL, 0, &cbBytesNeeded)) {
+ BYTE *lpBuffer;
+ if (rc != ERROR_INSUFFICIENT_BUFFER) {
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
cbBufSize = cbBytesNeeded;
- lpServiceConfig = (LPQUERY_SERVICE_CONFIGW)malloc(cbBufSize);
+ lpBuffer = (BYTE *)malloc(cbBufSize);
if (!lpServiceConfig) {
rc = ERROR_OUTOFMEMORY;
throwAprMemoryException(_E, THROW_FMARK,
apr_get_os_error());
+ SIGHT_LOCAL_BRK(no);
goto cleanup;
}
- if (!QueryServiceConfigW(hsvc, lpServiceConfig,
- cbBufSize, &cbBytesNeeded)) {
+ if (!QueryServiceConfig2W(hsvc, SERVICE_CONFIG_DESCRIPTION,
+ lpBuffer, cbBufSize, &cbBytesNeeded)) {
rc = GetLastError();
+ free(lpBuffer);
+ SIGHT_LOCAL_BRK(no);
goto cleanup;
}
+ else {
+ LPSERVICE_DESCRIPTIONW lpDesc = (LPSERVICE_DESCRIPTIONW)lpBuffer;
+ SET_IFIELD_W(0005, thiz, lpDesc->lpDescription);
+ }
+ free(lpBuffer);
}
- else {
- goto cleanup;
- }
- }
- SET_IFIELD_W(0001, thiz, lpServiceConfig->lpBinaryPathName);
- SET_IFIELD_O(0002, thiz, sight_mw_to_sa(_E, lpServiceConfig->lpDependencies));
- SET_IFIELD_W(0003, thiz, lpServiceConfig->lpServiceStartName);
- SET_IFIELD_W(0004, thiz, lpServiceConfig->lpDisplayName);
- SET_IFIELD_W(0006, thiz, lpServiceConfig->lpLoadOrderGroup);
-
- if (!QueryServiceConfig2W(hsvc, SERVICE_CONFIG_DESCRIPTION,
- NULL, 0, &cbBytesNeeded)) {
- BYTE *lpBuffer;
- if (rc != ERROR_INSUFFICIENT_BUFFER) {
- goto cleanup;
- }
- cbBufSize = cbBytesNeeded;
- lpBuffer = (BYTE *)malloc(cbBufSize);
- if (!lpServiceConfig) {
- rc = ERROR_OUTOFMEMORY;
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
- goto cleanup;
- }
- if (!QueryServiceConfig2W(hsvc, SERVICE_CONFIG_DESCRIPTION,
- lpBuffer, cbBufSize, &cbBytesNeeded)) {
+ if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
+ buf, sizeof(buf), &cbBytesNeeded)) {
rc = GetLastError();
- free(lpBuffer);
- goto cleanup;
}
else {
- LPSERVICE_DESCRIPTIONW lpDesc = (LPSERVICE_DESCRIPTIONW)lpBuffer;
- SET_IFIELD_W(0005, thiz, lpDesc->lpDescription);
+ lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
+ SET_IFIELD_I(0007, thiz, lpStatus->dwWin32ExitCode);
+ SET_IFIELD_I(0008, thiz, lpStatus->dwServiceSpecificExitCode);
+ SET_IFIELD_I(0009, thiz, lpStatus->dwProcessId);
+ CALL_METHOD1(0000, thiz, lpStatus->dwCurrentState);
+
+ no->native = hsvc;
+ no->clean = svc_cleanup;
+ rc = ERROR_SUCCESS;
}
- free(lpBuffer);
- }
- if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
- buf, sizeof(buf), &cbBytesNeeded)) {
- rc = GetLastError();
- goto cleanup;
- }
- lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
- SET_IFIELD_I(0007, thiz, lpStatus->dwWin32ExitCode);
- SET_IFIELD_I(0008, thiz, lpStatus->dwServiceSpecificExitCode);
- SET_IFIELD_I(0009, thiz, lpStatus->dwProcessId);
- CALL_METHOD1(0000, thiz, lpStatus->dwCurrentState);
-
- no->native = hsvc;
- no->clean = svc_cleanup;
- rc = ERROR_SUCCESS;
+ } SIGHT_LOCAL_END(no);
cleanup:
if (lpServiceConfig)
free(lpServiceConfig);
@@ -268,40 +278,43 @@
DWORD rc = ERROR_SUCCESS;
SERVICE_STATUS stStatus;
DWORD sc = cmd;
+
UNREFERENCED_O;
if (!no || !no->native || cmd < 0) {
return APR_EINVAL;
}
- hsvc = no->native;
+ SIGHT_LOCAL_TRY(no) {
+ hsvc = no->native;
- switch (cmd) {
- case 1:
- sc = SERVICE_CONTROL_STOP;
- break;
- case 2:
- sc = SERVICE_CONTROL_PAUSE;
- break;
- case 3:
- sc = SERVICE_CONTROL_CONTINUE;
- break;
- case 4:
- sc = SERVICE_CONTROL_INTERROGATE;
- break;
- case 5:
- return APR_EINVAL;
- break;
- case 6:
- sc = SERVICE_CONTROL_PARAMCHANGE;
- break;
- }
- if (cmd == 0) {
- if (!StartService(hsvc, 0, NULL))
- rc = GetLastError();
- }
- else {
- if (!ControlService(hsvc, sc, &stStatus))
- rc = GetLastError();
- }
+ switch (cmd) {
+ case 1:
+ sc = SERVICE_CONTROL_STOP;
+ break;
+ case 2:
+ sc = SERVICE_CONTROL_PAUSE;
+ break;
+ case 3:
+ sc = SERVICE_CONTROL_CONTINUE;
+ break;
+ case 4:
+ sc = SERVICE_CONTROL_INTERROGATE;
+ break;
+ case 5:
+ return APR_EINVAL;
+ break;
+ case 6:
+ sc = SERVICE_CONTROL_PARAMCHANGE;
+ break;
+ }
+ if (cmd == 0) {
+ if (!StartService(hsvc, 0, NULL))
+ rc = GetLastError();
+ }
+ else {
+ if (!ControlService(hsvc, sc, &stStatus))
+ rc = GetLastError();
+ }
+ } SIGHT_LOCAL_END(no);
return APR_FROM_OS_ERROR(rc);
}
@@ -320,20 +333,21 @@
if (!no || !no->native) {
return APR_EINVAL;
}
- hsvc = no->native;
+ SIGHT_LOCAL_TRY(no) {
+ hsvc = no->native;
- if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
- buf, sizeof(buf), &cbBytesNeeded)) {
- rc = GetLastError();
- goto cleanup;
- }
- lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
- SET_IFIELD_I(0007, thiz, lpStatus->dwWin32ExitCode);
- SET_IFIELD_I(0008, thiz, lpStatus->dwServiceSpecificExitCode);
- SET_IFIELD_I(0009, thiz, lpStatus->dwProcessId);
- CALL_METHOD1(0000, thiz, lpStatus->dwCurrentState);
-
-cleanup:
+ if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
+ buf, sizeof(buf), &cbBytesNeeded)) {
+ rc = GetLastError();
+ }
+ else {
+ lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
+ SET_IFIELD_I(0007, thiz, lpStatus->dwWin32ExitCode);
+ SET_IFIELD_I(0008, thiz, lpStatus->dwServiceSpecificExitCode);
+ SET_IFIELD_I(0009, thiz, lpStatus->dwProcessId);
+ CALL_METHOD1(0000, thiz, lpStatus->dwCurrentState);
+ }
+ } SIGHT_LOCAL_END(no);
return APR_FROM_OS_ERROR(rc);
}
@@ -355,47 +369,50 @@
if (!no || !no->native) {
return APR_EINVAL;
}
- hsvc = no->native;
- if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
- buf, sizeof(buf), &cbBytesNeeded)) {
- rc = GetLastError();
- goto cleanup;
- }
- lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
- if (lpStatus->dwCurrentState == (DWORD)state)
- goto setup;
- if (timeout > 0) {
- timeout_value = timeout * 1000L;
- timeout_interval = timeout_value / 64;
- }
- else {
- /* Defaults to 100 ms */
- timeout_interval = 100000L;
- }
- do {
- apr_sleep(timeout_interval);
+ SIGHT_LOCAL_TRY(no) {
+ hsvc = no->native;
if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
buf, sizeof(buf), &cbBytesNeeded)) {
rc = GetLastError();
+ SIGHT_LOCAL_BRK(no);
goto cleanup;
}
lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
+ if (lpStatus->dwCurrentState == (DWORD)state)
+ goto setup;
if (timeout > 0) {
- if (timeout_interval >= timeout_value) {
- rc = APR_TO_OS_ERROR(APR_TIMEUP);
- break;
+ timeout_value = timeout * 1000L;
+ timeout_interval = timeout_value / 64;
+ }
+ else {
+ /* Defaults to 100 ms */
+ timeout_interval = 100000L;
+ }
+ do {
+ apr_sleep(timeout_interval);
+ if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
+ buf, sizeof(buf), &cbBytesNeeded)) {
+ rc = GetLastError();
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
}
- timeout_interval *= 2;
- }
+ lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
+ if (timeout > 0) {
+ if (timeout_interval >= timeout_value) {
+ rc = APR_TO_OS_ERROR(APR_TIMEUP);
+ break;
+ }
+ timeout_interval *= 2;
+ }
- } while (lpStatus->dwCurrentState != (DWORD)state);
+ } while (lpStatus->dwCurrentState != (DWORD)state);
setup:
- lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
- SET_IFIELD_I(0007, thiz, lpStatus->dwWin32ExitCode);
- SET_IFIELD_I(0008, thiz, lpStatus->dwServiceSpecificExitCode);
- SET_IFIELD_I(0009, thiz, lpStatus->dwProcessId);
- CALL_METHOD1(0000, thiz, lpStatus->dwCurrentState);
-
+ lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
+ SET_IFIELD_I(0007, thiz, lpStatus->dwWin32ExitCode);
+ SET_IFIELD_I(0008, thiz, lpStatus->dwServiceSpecificExitCode);
+ SET_IFIELD_I(0009, thiz, lpStatus->dwProcessId);
+ CALL_METHOD1(0000, thiz, lpStatus->dwCurrentState);
+ } SIGHT_LOCAL_END(no);
cleanup:
return APR_FROM_OS_ERROR(rc);
}
@@ -423,73 +440,79 @@
if (!no || !no->native || !progress) {
return APR_EINVAL;
}
- hsvc = no->native;
+ SIGHT_LOCAL_TRY(no) {
+ hsvc = no->native;
- if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
- buf, sizeof(buf), &cbBytesNeeded)) {
- rc = GetLastError();
- goto cleanup;
- }
- lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
- if (lpStatus->dwCurrentState == (DWORD)state)
- goto setup;
- c = (*_E)->GetObjectClass(_E, progress);
- cb.name = "progress";
- cb.msig = "(I)I";
- cb.object = progress;
- cb.method = (*_E)->GetMethodID(_E, c, cb.name, cb.msig);
- if (!cb.method || (*_E)->ExceptionCheck(_E)) {
- rc = EINVAL;
- goto cleanup;
- }
- cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick, NULL);
- if ((*_E)->ExceptionCheck(_E)) {
- rc = EINTR;
- goto cleanup;
- }
- if (timeout > 0) {
- timeout_value = timeout * 1000L;
- timeout_interval = timeout_value / 100;
- }
- else {
- /* Defaults to 100 ms */
- timeout_interval = 100000L;
- }
- do {
- if (cres < 0) {
- /* Broken by the callback */
- break;
- }
- else if (cres > 0) {
- timeout_interval = cres * 1000L;
- }
- apr_sleep(timeout_interval);
if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
buf, sizeof(buf), &cbBytesNeeded)) {
rc = GetLastError();
+ SIGHT_LOCAL_BRK(no);
goto cleanup;
}
lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
- if (timeout > 0) {
- if (timeout_interval >= timeout_value) {
- rc = APR_TO_OS_ERROR(APR_TIMEUP);
- break;
- }
- timeout_value -= timeout_interval;
+ if (lpStatus->dwCurrentState == (DWORD)state)
+ goto setup;
+ c = (*_E)->GetObjectClass(_E, progress);
+ cb.name = "progress";
+ cb.msig = "(I)I";
+ cb.object = progress;
+ cb.method = (*_E)->GetMethodID(_E, c, cb.name, cb.msig);
+ if (!cb.method || (*_E)->ExceptionCheck(_E)) {
+ rc = EINVAL;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
}
- cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick++, NULL);
+ cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick, NULL);
if ((*_E)->ExceptionCheck(_E)) {
rc = EINTR;
+ SIGHT_LOCAL_BRK(no);
goto cleanup;
}
- } while (lpStatus->dwCurrentState != (DWORD)state);
-setup:
- lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
- SET_IFIELD_I(0007, thiz, lpStatus->dwWin32ExitCode);
- SET_IFIELD_I(0008, thiz, lpStatus->dwServiceSpecificExitCode);
- SET_IFIELD_I(0009, thiz, lpStatus->dwProcessId);
- CALL_METHOD1(0000, thiz, lpStatus->dwCurrentState);
-
+ if (timeout > 0) {
+ timeout_value = timeout * 1000L;
+ timeout_interval = timeout_value / 100;
+ }
+ else {
+ /* Defaults to 100 ms */
+ timeout_interval = 100000L;
+ }
+ do {
+ if (cres < 0) {
+ /* Broken by the callback */
+ break;
+ }
+ else if (cres > 0) {
+ timeout_interval = cres * 1000L;
+ }
+ apr_sleep(timeout_interval);
+ if (!QueryServiceStatusEx(hsvc, SC_STATUS_PROCESS_INFO,
+ buf, sizeof(buf), &cbBytesNeeded)) {
+ rc = GetLastError();
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
+ if (timeout > 0) {
+ if (timeout_interval >= timeout_value) {
+ rc = APR_TO_OS_ERROR(APR_TIMEUP);
+ break;
+ }
+ timeout_value -= timeout_interval;
+ }
+ cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick++, NULL);
+ if ((*_E)->ExceptionCheck(_E)) {
+ rc = EINTR;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ } while (lpStatus->dwCurrentState != (DWORD)state);
+ setup:
+ lpStatus = (LPSERVICE_STATUS_PROCESS)&buf[0];
+ SET_IFIELD_I(0007, thiz, lpStatus->dwWin32ExitCode);
+ SET_IFIELD_I(0008, thiz, lpStatus->dwServiceSpecificExitCode);
+ SET_IFIELD_I(0009, thiz, lpStatus->dwProcessId);
+ CALL_METHOD1(0000, thiz, lpStatus->dwCurrentState);
+ } SIGHT_LOCAL_END(no);
cleanup:
return APR_FROM_OS_ERROR(rc);
}
17 years, 2 months
JBoss Native SVN: r1068 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-01 04:54:47 -0400 (Mon, 01 Oct 2007)
New Revision: 1068
Modified:
trunk/sight/native/share/no.c
trunk/sight/native/share/shm.c
Log:
Seal shared memory JNI calls
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-01 08:44:34 UTC (rev 1067)
+++ trunk/sight/native/share/no.c 2007-10-01 08:54:47 UTC (rev 1068)
@@ -264,10 +264,11 @@
refcount = apr_atomic_read32(&no->refcount);
}
+ if (no->pool)
+ apr_pool_cleanup_kill(no->pool, no, native_object_cleanup);
+ if (no->clean)
+ (*no->clean)(POOL_CLEAR, no);
if (no->pool) {
- apr_pool_cleanup_kill(no->pool, no, native_object_cleanup);
- if (no->clean)
- (*no->clean)(POOL_CLEAR, no);
apr_pool_clear(no->pool);
apr_pool_cleanup_register(no->pool, (const void *)no,
native_object_cleanup,
Modified: trunk/sight/native/share/shm.c
===================================================================
--- trunk/sight/native/share/shm.c 2007-10-01 08:44:34 UTC (rev 1067)
+++ trunk/sight/native/share/shm.c 2007-10-01 08:54:47 UTC (rev 1068)
@@ -57,14 +57,15 @@
rv = APR_ENOPOOL;
goto cleanup;
}
+ SIGHT_LOCAL_TRY(no) {
+ rv = apr_shm_create(&shm, (apr_size_t)size, J2S(name), no->pool);
- rv = apr_shm_create(&shm, (apr_size_t)size, J2S(name), no->pool);
-
- if (rv == APR_SUCCESS) {
- no->clean = shm_cleanup;
- no->native = shm;
- no->opaque = NULL;
- }
+ if (rv == APR_SUCCESS) {
+ no->clean = shm_cleanup;
+ no->native = shm;
+ no->opaque = NULL;
+ }
+ } SIGHT_LOCAL_END(no);
cleanup:
SIGHT_FREE_CSTRING(name);
return rv;
@@ -87,13 +88,15 @@
goto cleanup;
}
- rv = apr_shm_attach(&shm, J2S(name), no->pool);
+ SIGHT_LOCAL_TRY(no) {
+ rv = apr_shm_attach(&shm, J2S(name), no->pool);
- if (rv == APR_SUCCESS) {
- no->clean = shm_cleanup;
- no->native = shm;
- no->opaque = shm;
- }
+ if (rv == APR_SUCCESS) {
+ no->clean = shm_cleanup;
+ no->native = shm;
+ no->opaque = shm;
+ }
+ } SIGHT_LOCAL_END(no);
cleanup:
SIGHT_FREE_CSTRING(name);
return rv;
@@ -118,15 +121,19 @@
UNREFERENCED_O;
if (no && no->native) {
- jbyte *base = (jbyte *)apr_shm_baseaddr_get(no->native);
- apr_size_t siz;
- if (asize < 0)
- siz = apr_shm_size_get(no->native);
- else
- siz = (apr_size_t)asize;
- if (siz > 0 && base) {
- return (*_E)->NewDirectByteBuffer(_E, base, siz);
- }
+ jobject rv = NULL;
+ SIGHT_LOCAL_TRY(no) {
+ jbyte *base = (jbyte *)apr_shm_baseaddr_get(no->native);
+ apr_size_t siz;
+ if (asize < 0)
+ siz = apr_shm_size_get(no->native);
+ else
+ siz = (apr_size_t)asize;
+ if (siz > 0 && base) {
+ rv = (*_E)->NewDirectByteBuffer(_E, base, siz);
+ }
+ } SIGHT_LOCAL_END(no);
+ return rv;
}
return NULL;
}
@@ -135,15 +142,16 @@
jstring name,
jlong pool)
{
- apr_status_t rv;
+ apr_status_t rv = APR_ENOPOOL;
apr_pool_t *p = J2P(pool, apr_pool_t *);
SIGHT_ALLOC_CSTRING(name);
+
UNREFERENCED_O;
if (p) {
- rv = apr_shm_remove(J2S(name), p);
+ SIGHT_GLOBAL_TRY {
+ rv = apr_shm_remove(J2S(name), p);
+ } SIGHT_GLOBAL_END();
}
- else
- rv = APR_ENOPOOL;
SIGHT_FREE_CSTRING(name);
return rv;
}
17 years, 2 months
JBoss Native SVN: r1067 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-01 04:44:34 -0400 (Mon, 01 Oct 2007)
New Revision: 1067
Modified:
trunk/sight/native/os/solaris/netadapter.c
Log:
Port Linix version to Solaris.
Modified: trunk/sight/native/os/solaris/netadapter.c
===================================================================
--- trunk/sight/native/os/solaris/netadapter.c 2007-10-01 08:17:46 UTC (rev 1066)
+++ trunk/sight/native/os/solaris/netadapter.c 2007-10-01 08:44:34 UTC (rev 1067)
@@ -30,6 +30,15 @@
#include "sight_types.h"
#include "sight_private.h"
+#include <unistd.h>
+#include <stropts.h>
+
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/route.h>
+#include <sys/ioctl.h>
+#include <sys/sockio.h>
+
/*
* Network adapter implementation
*/
@@ -137,33 +146,531 @@
sight_unload_class(_E, &_clazzn);
}
+#define PROC_INET6_FILE "/proc/net/if_inet6"
+#define PROC_NET_DEV "/proc/net/dev"
+#define PROC_NET_ROUTE4 "/proc/net/route"
+#define PROC_NET_ROUTE6 "/proc/net/ipv6_route"
+
+typedef struct net_ifc_addr_t {
+ char ip4a[64];
+ char ip6a[64];
+ char mask[64];
+ char badr[64];
+ int virt;
+ int route;
+} net_ifc_addr_t;
+
+typedef struct net_ifc_data_t {
+ int type;
+ int index;
+ int flags;
+ int mtu;
+ char maca[64];
+ cache_table_t *addr;
+} net_ifc_data_t;
+
+typedef struct net_adapter_enum_t {
+ int sd;
+ int idx;
+ cache_table_t *ifc;
+} net_adapter_enum_t;
+
+#define IFHWADDRLEN 6
+
+static void c_destroy(const char *key, void *data)
+{
+ net_ifc_data_t *d = (net_ifc_data_t *)data;
+ if (d) {
+ cache_free(d->addr, NULL);
+ free(d);
+ }
+}
+
+static char *hex_base = "0123456789abcdefx";
+
+static void make_mac(void *data, char *dest)
+{
+ int i, j = 0;
+ unsigned char buf[IFHWADDRLEN];
+ char *sp = dest;
+
+ memcpy(buf, data, IFHWADDRLEN);
+ *dest = '\0';
+ for (i = 0; i < IFHWADDRLEN; i++) {
+ if (buf[i]) {
+ j = 1;
+ break;
+ }
+ }
+ if (!j)
+ return;
+ for (i = 0; i < IFHWADDRLEN - 1; i++) {
+ *sp++ = hex_base[buf[i] >> 4];
+ *sp++ = hex_base[buf[i] & 0x0f];
+ *sp++ = ':';
+ }
+ *sp++ = hex_base[buf[i] >> 4];
+ *sp++ = hex_base[buf[i] & 0x0f];
+ *sp++ = '\0';
+}
+
+static void do_ifrec(net_ifc_data_t *id, net_ifc_addr_t *ca,
+ int sd, const char *name)
+{
+ struct ifreq ifi;
+ struct lifreq lifi;
+ struct sockaddr_in *sa;
+
+ memset(&ifi, 0, sizeof(struct ifreq));
+ strcpy(ifi.ifr_name, name);
+
+ if (!ca->virt) {
+ if (!ioctl(sd, SIOCGIFINDEX, (char *)&ifi))
+ id->index = ifi.ifr_index;
+ else
+ id->index = -1;
+ if (!ioctl(sd, SIOCGIFFLAGS, (char *)&ifi))
+ id->flags = ifi.ifr_flags;
+ /* XXX: This doesn't work on Solaris (needs root and something like mac_addr_dlpi.c */
+/*
+ if (!ioctl(sd, SIOCGENADDR, (char *)&ifi)) {
+ make_mac(ifi.ifr_enaddr, id->maca);
+ printf("SIOCGENADDR, %02x %02x %02x %02x\n", ifi.ifr_enaddr[0], ifi.ifr_enaddr[1], ifi.ifr_enaddr[2], ifi.ifr_enaddr[3]);
+ fflush(stdout);
+ } else {
+ perror("SIOCGENADDR, failed:");
+ fflush(stderr);
+ printf("%s SIOCGENADDR, failed\n", name);
+ fflush(stdout);
+ }
+ */
+ memset(&lifi, 0, sizeof(struct lifreq));
+ strcpy(lifi.lifr_name, name);
+ if (!ioctl(sd, SIOCGLIFMTU, (char *)&lifi))
+ id->mtu = lifi.lifr_mtu;
+ }
+
+ memset(&lifi, 0, sizeof(struct lifreq));
+ strcpy(lifi.lifr_name, name);
+ if (!ioctl(sd, SIOCGLIFNETMASK, (char *)&lifi)) {
+ sa = (struct sockaddr_in *)&lifi.lifr_subnet;
+ inet_ntop(AF_INET, &sa->sin_addr, ca->mask, 64);
+ }
+
+ if ((id->flags & IFF_BROADCAST) &&
+ !ioctl(sd, SIOCGIFBRDADDR, (char *)&ifi)) {
+ sa = (struct sockaddr_in *)&ifi.ifr_broadaddr;
+ inet_ntop(AF_INET, &sa->sin_addr, ca->badr, 64);
+ }
+}
+
+net_ifc_data_t *new_ifc_addr(JNIEnv *_E, const char *name,
+ net_ifc_addr_t **ca)
+{
+ net_ifc_data_t *id;
+ cache_entry_t *ie;
+
+ if (!(id = (net_ifc_data_t *)sight_calloc(_E,
+ sizeof(net_ifc_data_t),
+ THROW_FMARK))) {
+ return NULL;
+ }
+ if (!(id->addr = cache_new(4))) {
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ free(id);
+ return NULL;
+ }
+ ie = cache_add(id->addr, name);
+ if (!(*ca = (net_ifc_addr_t *)sight_calloc(_E,
+ sizeof(net_ifc_addr_t),
+ THROW_FMARK))) {
+ cache_free(id->addr, NULL);
+ return NULL;
+ }
+ ie->data = *ca;
+ return id;
+}
+
+net_ifc_addr_t *get_ifc_addr(JNIEnv *_E, const char *name,
+ net_ifc_data_t *id)
+{
+ cache_entry_t *ie;
+ net_ifc_addr_t *ca;
+
+ ie = cache_add(id->addr, name);
+ if (ie->data)
+ return ie->data;
+ if (!(ca = (net_ifc_addr_t *)sight_calloc(_E,
+ sizeof(net_ifc_addr_t),
+ THROW_FMARK))) {
+ return NULL;
+ }
+ ie->data = ca;
+ return ca;
+}
+
+static int get_ipv4_route(JNIEnv *_E, const char *name,
+ net_ifc_data_t *id)
+{
+ sight_arr_t *i4r;
+ net_ifc_addr_t *ca;
+ int i;
+
+ if (!id)
+ return 0; /* No rec, nothing to do */
+ if ((i4r = sight_arr_rload(PROC_NET_ROUTE4)) != NULL) {
+ for (i = 1; i < i4r->siz; i++) {
+ char iface[16], nname[64];
+ char gatea[128], neta[128], maska[128];
+ struct in_addr ipg, ipn, ipm;
+ int al, iflags, metric, refcnt, use, mss, window, irtt;
+
+ al = sscanf(i4r->arr[i],
+ "%16s %128s %128s %X %d %d %d %128s %d %d %d",
+ iface, neta, gatea, &iflags, &refcnt, &use, &metric,
+ maska, &mss, &window, &irtt);
+ if (al < 10 || !(iflags & RTF_GATEWAY))
+ continue;
+ if (strcmp(iface, name))
+ continue;
+ sprintf(nname, "%s.r4.%d", name, i);
+ /* TODO: Deal with RTF_HOST flags */
+ if (!(ca = get_ifc_addr(_E, nname, id))) {
+ sight_arr_free(i4r);
+ return 1;
+ }
+ if (ca->route)
+ continue;
+ ca->route = 1;
+
+ if (sscanf(gatea, "%X", &ipg.s_addr) != 1)
+ continue;
+ if (sscanf(neta, "%X", &ipn.s_addr) != 1)
+ continue;
+ if (sscanf(maska, "%X", &ipm.s_addr) != 1)
+ continue;
+ inet_ntop(AF_INET, &ipg, ca->ip4a, 64);
+ inet_ntop(AF_INET, &ipm, ca->mask, 64);
+ }
+ }
+ sight_arr_free(i4r);
+ return 0;
+}
+
+static int get_ipv6_route(JNIEnv *_E, const char *name,
+ net_ifc_data_t *id)
+{
+ sight_arr_t *i6r;
+ net_ifc_addr_t *ca;
+ int i;
+
+ if (!id)
+ return 0; /* No rec, nothing to do */
+ if ((i6r = sight_arr_rload(PROC_NET_ROUTE6)) != NULL) {
+ for (i = 0; i < i6r->siz; i++) {
+ char iface[16], nname[64];
+ char dsta[128], neta[128], hopa[128];
+ struct in6_addr ipd, ipn, iph;
+
+ int al, iflags, metric, refcnt, use, plen, slen;
+
+ al = sscanf(i6r->arr[i],
+ "%64s %02X %64s %02X %64s %08X %08X %08X %08X %s",
+ dsta, &plen, neta, &slen, hopa, &metric, &use,
+ &refcnt, &iflags, iface);
+ if (al < 10 || !(iflags & RTF_GATEWAY))
+ continue;
+ if (strcmp(iface, name))
+ continue;
+ sprintf(nname, "%s.r6.%d", name, i);
+ /* TODO: Deal with RTF_HOST flags */
+ if (!(ca = get_ifc_addr(_E, nname, id))) {
+ sight_arr_free(i6r);
+ return 1;
+ }
+ if (ca->route)
+ continue;
+ ca->route = 1;
+ /* XXX: Is it source network or next hop ? */
+ sight_hex2bin(neta, ipd.s6_addr, 16);
+ sight_inet_ntop6(ipd.s6_addr, ca->ip6a, 64);
+ }
+ }
+ sight_arr_free(i6r);
+ return 0;
+}
+
SIGHT_EXPORT_DECLARE(jlong, NetworkAdapter, enum0)(SIGHT_STDARGS,
jlong pool)
{
- UNREFERENCED_STDARGS;
+ net_adapter_enum_t *e;
+ int i, j;
+ struct ifconf ifc;
+ struct lifnum lifnum;
+ struct lifconf lifconf;
+ struct lifreq *lifcu_req;
+
+ net_ifc_data_t *id;
+
+ UNREFERENCED_O;
UNREFERENCED(pool);
+ if (!(e = (net_adapter_enum_t *)sight_calloc(_E,
+ sizeof(net_adapter_enum_t),
+ THROW_FMARK))) {
+ return 0;
+ }
+ if (!(e->ifc = cache_new(8))) {
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ free(e);
+ return 0;
+ }
+ if ((e->sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ throwAprException(_E, apr_get_os_error());
+ goto cleanup;
+ }
+
+ lifnum.lifn_family = AF_UNSPEC;
+ lifnum.lifn_flags = LIFC_NOXMIT;
+ if (ioctl(e->sd, SIOCGLIFNUM, (char *)&lifnum) < 0) {
+ throwAprException(_E, apr_get_os_error());
+ goto cleanup;
+ }
+ if (!(lifconf.lifc_buf = sight_calloc(_E, lifnum.lifn_count * sizeof(struct lifreq), THROW_FMARK))) {
+ goto cleanup;
+ }
+ lifconf.lifc_len = lifnum.lifn_count * sizeof(struct lifreq);
+ lifconf.lifc_family = AF_UNSPEC;
+ lifconf.lifc_flags = LIFC_NOXMIT;
+ if (ioctl(e->sd, SIOCGLIFCONF, (char *)&lifconf) < 0) {
+ throwAprException(_E, apr_get_os_error());
+ free(ifc.ifc_buf);
+ goto cleanup;
+ }
+ /* Add interfaces to the cache */
+ lifcu_req = lifconf.lifc_req;
+ for (i = 0; i < lifconf.lifc_len; i += sizeof(struct lifreq), lifcu_req++) {
+ cache_entry_t *ce;
+ char *p, las[128] = "";
+ char pname[IF_NAMESIZE];
+ struct sockaddr_in *sa;
+ int is_virtual = 0;
+
+ sa = (struct sockaddr_in *)&lifcu_req->lifr_addr;
+ inet_ntop(AF_INET, &sa->sin_addr, las, 64);
+ strcpy(pname, lifcu_req->lifr_name);
+ if ((p = strchr(pname, ':'))) {
+ /* This is an virtual adapter.
+ * Remove everything after colon
+ */
+ *p = '\0';
+ is_virtual = 1;
+ }
+ ce = cache_add(e->ifc, pname);
+ if (!(id = (net_ifc_data_t *)ce->data)) {
+ net_ifc_addr_t *ca;
+
+ if (!(id = new_ifc_addr(_E, lifcu_req->lifr_name, &ca))) {
+ free(ifc.ifc_buf);
+ goto cleanup;
+ }
+ ce->data = id;
+ id->type = AF_INET;
+ ca->virt = is_virtual;
+ strcpy(ca->ip4a, las);
+ do_ifrec(id, ca, e->sd, lifcu_req->lifr_name);
+ }
+ else {
+ net_ifc_addr_t *ca;
+
+ if (!(ca = get_ifc_addr(_E, lifcu_req->lifr_name, id))) {
+ free(ifc.ifc_buf);
+ goto cleanup;
+ }
+ ca->virt = is_virtual;
+ strcpy(ca->ip4a, las);
+ do_ifrec(id, ca, e->sd, lifcu_req->lifr_name);
+ }
+ get_ipv4_route(_E, lifcu_req->lifr_name, id);
+ }
+
+ free(ifc.ifc_buf);
+ return P2J(e);
+
+cleanup:
+ if (e->sd >= 0)
+ close(e->sd);
+ cache_free(e->ifc, c_destroy);
+ free(e);
return 0;
}
SIGHT_EXPORT_DECLARE(jint, NetworkAdapter, enum1)(SIGHT_STDARGS,
jlong handle)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(handle);
- return 0;
+ net_adapter_enum_t *e = J2P(handle, net_adapter_enum_t *);
+
+ UNREFERENCED_O;
+ if (!e)
+ return 0;
+ else {
+ e->idx = 0;
+ return e->ifc->siz;
+ }
}
SIGHT_EXPORT_DECLARE(void, NetworkAdapter, enum2)(SIGHT_STDARGS,
jobject thiz,
jlong handle)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(handle);
+ net_adapter_enum_t *e = J2P(handle, net_adapter_enum_t *);
+ net_ifc_data_t *id;
+ net_ifc_addr_t *ca;
+ jobject addr;
+ jobjectArray aarr;
+ jint len, idx;
+ int i;
+
+ UNREFERENCED_O;
+ if (!e || e->idx > e->ifc->siz)
+ return;
+ id = (net_ifc_data_t *)e->ifc->list[e->idx]->data;
+ SET_IFIELD_S(0000, thiz, e->ifc->list[e->idx]->key);
+ /* TODO: Figure out the Description */
+ SET_IFIELD_S(0001, thiz, e->ifc->list[e->idx]->key);
+ SET_IFIELD_S(0002, thiz, e->ifc->list[e->idx]->key);
+
+ if (id->maca[0]) {
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E))
+ return;
+ sight_netaddr_set_addr(_E, addr, id->maca);
+ sight_netaddr_set_family(_E, addr, AF_HARDWARE);
+ SET_IFIELD_O(0003, thiz, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ /* Set adapter type */
+ if (id->flags & IFF_LOOPBACK) {
+ CALL_METHOD1(0000, thiz, IF_TYPE_SOFTWARE_LOOPBACK);
+ }
+ else if (id->flags & IFF_POINTOPOINT) {
+ CALL_METHOD1(0000, thiz, IF_TYPE_PPP);
+ }
+ else {
+ CALL_METHOD1(0000, thiz, IF_TYPE_ETHERNET_CSMACD);
+ }
+ /* Set adapter status */
+ if (id->flags & IFF_UP) {
+ if (id->flags & IFF_RUNNING)
+ CALL_METHOD1(0001, thiz, SIGHT_IFO_UP);
+ else
+ CALL_METHOD1(0001, thiz, SIGHT_IFO_NOTPRESENT);
+ }
+ else {
+ CALL_METHOD1(0001, thiz, SIGHT_IFO_DOWN);
+ }
+ /* Set IP addresses */
+ len = 0;
+ idx = 0;
+ for (i = 0; i < id->addr->siz; i++) {
+ ca = (net_ifc_addr_t *)id->addr->list[i]->data;
+ if (ca->route)
+ continue;
+ if (ca->ip4a[0])
+ len++;
+ if (ca->ip6a[0])
+ len++;
+ }
+ if (len) {
+ aarr = sight_new_netaddr_array(_E, _O, len);
+ if (!aarr || (*_E)->ExceptionCheck(_E))
+ goto cleanup;
+ for (i = 0; i < id->addr->siz; i++) {
+ ca = (net_ifc_addr_t *)id->addr->list[i]->data;
+
+ if (ca->route)
+ continue;
+ if (ca->ip4a[0]) {
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E))
+ return;
+ sight_netaddr_set_addr(_E, addr, ca->ip4a);
+ sight_netaddr_set_family(_E, addr, AF_INET);
+ if (ca->mask[0])
+ sight_netaddr_set_mask(_E, addr, ca->mask);
+ (*_E)->SetObjectArrayElement(_E, aarr, idx++, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ if (ca->ip6a[0]) {
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E))
+ return;
+ sight_netaddr_set_addr(_E, addr, ca->ip6a);
+ sight_netaddr_set_family(_E, addr, AF_INET6);
+ (*_E)->SetObjectArrayElement(_E, aarr, idx++, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ }
+ SET_IFIELD_O(0006, thiz, aarr);
+ (*_E)->DeleteLocalRef(_E, aarr);
+ }
+ /* Set Gateway addresses */
+ len = 0;
+ idx = 0;
+ for (i = 0; i < id->addr->siz; i++) {
+ ca = (net_ifc_addr_t *)id->addr->list[i]->data;
+ if (!ca->route)
+ continue;
+ if (ca->ip4a[0])
+ len++;
+ else if (ca->ip6a[0])
+ len++;
+ }
+ if (len) {
+ aarr = sight_new_netaddr_array(_E, _O, len);
+ if (!aarr || (*_E)->ExceptionCheck(_E))
+ goto cleanup;
+ for (i = 0; i < id->addr->siz; i++) {
+ ca = (net_ifc_addr_t *)id->addr->list[i]->data;
+
+ if (!ca->route)
+ continue;
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E))
+ return;
+ if (ca->ip4a[0]) {
+ sight_netaddr_set_addr(_E, addr, ca->ip4a);
+ sight_netaddr_set_family(_E, addr, AF_INET);
+ if (ca->mask[0])
+ sight_netaddr_set_mask(_E, addr, ca->mask);
+ }
+ else if (ca->ip6a[0]) {
+ sight_netaddr_set_addr(_E, addr, ca->ip6a);
+ sight_netaddr_set_family(_E, addr, AF_INET6);
+ }
+ (*_E)->SetObjectArrayElement(_E, aarr, idx++, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ SET_IFIELD_O(0008, thiz, aarr);
+ (*_E)->DeleteLocalRef(_E, aarr);
+ }
+
+ SET_IFIELD_I(0009, thiz, id->mtu);
+
+cleanup:
+ e->idx++;
}
SIGHT_EXPORT_DECLARE(void, NetworkAdapter, enum3)(SIGHT_STDARGS,
jlong handle)
{
+ net_adapter_enum_t *e = J2P(handle, net_adapter_enum_t *);
+
UNREFERENCED_STDARGS;
- UNREFERENCED(handle);
+ if (e) {
+ close(e->sd);
+ cache_free(e->ifc, c_destroy);
+ free(e);
+ }
}
17 years, 2 months
JBoss Native SVN: r1066 - in trunk/sight/native: share and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-01 04:17:46 -0400 (Mon, 01 Oct 2007)
New Revision: 1066
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/include/sight_types.h
trunk/sight/native/share/dir.c
trunk/sight/native/share/no.c
trunk/sight/native/share/proc.c
Log:
Add interrupt for recursive JNI calls
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/include/sight_local.h 2007-10-01 08:17:46 UTC (rev 1066)
@@ -375,11 +375,6 @@
#ifndef SIGHT_DO_STATS
#define SIGHT_DO_STATS 1
#endif
-#define SIGHT_IS_VALID_GLOBAL() apr_atomic_inc32(sight_global_atomic)
-#define SIGHT_GLOBAL_CLEANUP() apr_atomic_dec32(sight_global_atomic)
-#else /* !DEBUG */
-#define SIGHT_IS_VALID_GLOBAL() apr_atomic_inc32(sight_global_atomic)
-#define SIGHT_GLOBAL_CLEANUP() apr_atomic_dec32(sight_global_atomic)
#endif
#define SIGHT_GLOBAL_TRY if (apr_atomic_inc32(sight_global_atomic))
@@ -393,6 +388,7 @@
#define SIGHT_LOCAL_END(N) apr_atomic_dec32(&(N)->refcount); } apr_atomic_dec32(sight_global_atomic)
#define SIGHT_LOCAL_BRK(N) apr_atomic_dec32(&(N)->refcount); apr_atomic_dec32(sight_global_atomic)
+#define SIGHT_LOCAL_IRQ(N) apr_atomic_read32(&(N)->interrupted)
/* Statistics counters */
extern volatile apr_uint64_t sight_cnt_native_alloc;
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/include/sight_types.h 2007-10-01 08:17:46 UTC (rev 1066)
@@ -111,6 +111,7 @@
/* org.jboss.sight.NativeObject instance */
struct sight_object_t {
volatile apr_uint32_t refcount;
+ volatile apr_uint32_t interrupted;
apr_pool_t *pool;
void *native;
void *opaque;
Modified: trunk/sight/native/share/dir.c
===================================================================
--- trunk/sight/native/share/dir.c 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/share/dir.c 2007-10-01 08:17:46 UTC (rev 1066)
@@ -176,7 +176,7 @@
return rv;
}
-static apr_off_t calc_size_r(apr_dir_t *dir, const char *base, apr_pool_t *pool)
+static apr_off_t calc_size_r(sight_object_t *no, apr_dir_t *dir, const char *base, apr_pool_t *pool)
{
apr_off_t nsize = 0;
@@ -204,25 +204,29 @@
continue;
subdir = apr_pstrcat(sp, base, "/", fi.name, NULL);
if (apr_dir_open(&sd, subdir, sp) == APR_SUCCESS)
- nsize += calc_size_r(sd, subdir, sp);
+ nsize += calc_size_r(no, sd, subdir, sp);
apr_pool_destroy(sp);
}
else {
nsize += fi.size;
}
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ return nsize;
+ }
+
} while (rc == APR_SUCCESS || APR_STATUS_IS_INCOMPLETE(rc));
return nsize;
}
-static apr_off_t calc_size_d(apr_dir_t *dir)
+static apr_off_t calc_size_d(sight_object_t *no)
{
apr_off_t nsize = 0;
apr_finfo_t fi;
apr_status_t rc;
-
+ apr_dir_t *dir = (apr_dir_t *)no->native;
do {
rc = apr_dir_read(&fi, APR_FINFO_SIZE | APR_FINFO_TYPE, dir);
if (rc == APR_SUCCESS) {
@@ -230,6 +234,9 @@
nsize += fi.size;
}
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ return nsize;
+ }
} while (rc == APR_SUCCESS || APR_STATUS_IS_INCOMPLETE(rc));
return nsize;
@@ -241,7 +248,6 @@
jstring path)
{
sight_object_t *no = J2P(instance, sight_object_t *);
- apr_dir_t *d;
apr_off_t len = 0;
SIGHT_ALLOC_CSTRING(path);
@@ -256,13 +262,11 @@
sight_strerror(SIGHT_ENOFILE));
goto cleanup;
}
- else
- d = (apr_dir_t *)no->native;
SIGHT_LOCAL_TRY(no) {
if (recursive)
- len = calc_size_r((apr_dir_t *)no->native, J2S(path), no->pool);
+ len = calc_size_r(no, (apr_dir_t *)no->native, J2S(path), no->pool);
else
- len = calc_size_d((apr_dir_t *)no->native);
+ len = calc_size_d(no);
} SIGHT_LOCAL_END(no);
cleanup:
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/share/no.c 2007-10-01 08:17:46 UTC (rev 1066)
@@ -259,6 +259,7 @@
SIGHT_GLOBAL_TRY {
refcount = apr_atomic_read32(&no->refcount);
while (refcount) {
+ apr_atomic_inc32(&no->interrupted);
apr_thread_yield();
refcount = apr_atomic_read32(&no->refcount);
}
Modified: trunk/sight/native/share/proc.c
===================================================================
--- trunk/sight/native/share/proc.c 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/share/proc.c 2007-10-01 08:17:46 UTC (rev 1066)
@@ -347,11 +347,27 @@
SIGHT_LOCAL_BRK(no);
return APR_EINVAL;
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_EINTR;
+ }
timeout_value = timeout * 1000L;
timeout_interval = timeout_value / 64;
do {
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
apr_sleep(timeout_interval);
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy, APR_NOWAIT);
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
if (timeout_interval >= timeout_value)
break;
timeout_interval *= 2;
@@ -384,6 +400,10 @@
SIGHT_LOCAL_BRK(no);
return rc;
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_EINTR;
+ }
c = (*_E)->GetObjectClass(_E, progress);
cb.name = "progress";
cb.msig = "(I)I";
@@ -415,8 +435,20 @@
else if (cres > 0) {
timeout_interval = cres * 1000L;
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
apr_sleep(timeout_interval);
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy, APR_NOWAIT);
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
if (timeout > 0) {
if (timeout_interval >= timeout_value)
break;
17 years, 2 months
JBoss Native SVN: r1065 - in trunk/sight: native/include and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-01 03:58:39 -0400 (Mon, 01 Oct 2007)
New Revision: 1065
Modified:
trunk/sight/java/org/jboss/sight/NativeObject.java
trunk/sight/java/org/jboss/sight/Process.java
trunk/sight/native/include/sight_local.h
trunk/sight/native/include/sight_types.h
trunk/sight/native/share/dir.c
trunk/sight/native/share/file.c
trunk/sight/native/share/finfo.c
trunk/sight/native/share/no.c
trunk/sight/native/share/pool.c
trunk/sight/native/share/proc.c
Log:
Use APR atomics in more consistent way so we can have paralel GC
Modified: trunk/sight/java/org/jboss/sight/NativeObject.java
===================================================================
--- trunk/sight/java/org/jboss/sight/NativeObject.java 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/java/org/jboss/sight/NativeObject.java 2007-10-01 07:58:39 UTC (rev 1065)
@@ -24,7 +24,6 @@
*/
package org.jboss.sight;
-import java.util.concurrent.locks.ReentrantLock;
/**
* Native Object abstract class
*
@@ -49,30 +48,16 @@
private static native void cbset0(long instance, Object cb)
throws OutOfMemoryError;
- private ReentrantLock jniMutex;
-
-
/**
* Create new NativeObject without APR pool
*/
public NativeObject()
throws OutOfMemoryError
{
- jniMutex = new ReentrantLock();
POOL = 0;
INSTANCE = alloc();
}
- protected void nativeLock()
- {
- jniMutex.lock();
- }
-
- protected void nativeUnlock()
- {
- jniMutex.unlock();
- }
-
/**
* Create new NativeObject
* @param parent The parent pool. If this is 0, the new pool is a root
@@ -83,7 +68,6 @@
protected NativeObject(long parent)
throws OutOfMemoryError
{
- jniMutex = new ReentrantLock();
POOL = 0;
INSTANCE = alloc();
init0(this, INSTANCE, parent);
@@ -94,15 +78,9 @@
*/
public void destroy()
{
- jniMutex.lock();
- try {
- free0(INSTANCE);
- }
- finally {
- INSTANCE = 0;
- POOL = 0;
- jniMutex.unlock();
- }
+ free0(INSTANCE);
+ INSTANCE = 0;
+ POOL = 0;
}
/**
Modified: trunk/sight/java/org/jboss/sight/Process.java
===================================================================
--- trunk/sight/java/org/jboss/sight/Process.java 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/java/org/jboss/sight/Process.java 2007-10-01 07:58:39 UTC (rev 1065)
@@ -436,13 +436,7 @@
*/
public int wait(WaitHow waithow)
{
- nativeLock();
- try {
- return wait0(INSTANCE, waithow.valueOf());
- }
- finally {
- nativeUnlock();
- }
+ return wait0(INSTANCE, waithow.valueOf());
}
/**
@@ -463,13 +457,7 @@
*/
public int waitFor()
{
- nativeLock();
- try {
- return wait0(INSTANCE, 0);
- }
- finally {
- nativeUnlock();
- }
+ return wait0(INSTANCE, 0);
}
/**
@@ -494,13 +482,7 @@
*/
public int waitFor(long timeout)
{
- nativeLock();
- try {
- return wait1(INSTANCE, 0, timeout);
- }
- finally {
- nativeUnlock();
- }
+ return wait1(INSTANCE, 0, timeout);
}
/**
@@ -525,13 +507,7 @@
*/
public int waitFor(IProgressNotificationCallback progress, long timeout)
{
- nativeLock();
- try {
- return wait2(INSTANCE, progress, timeout);
- }
- finally {
- nativeUnlock();
- }
+ return wait2(INSTANCE, progress, timeout);
}
/**
@@ -554,13 +530,7 @@
*/
public int waitFor(IProgressNotificationCallback progress)
{
- nativeLock();
- try {
- return wait2(INSTANCE, progress, 0);
- }
- finally {
- nativeUnlock();
- }
+ return wait2(INSTANCE, progress, 0);
}
@@ -631,20 +601,14 @@
public int exec(String progname, String [] args, String [] env)
throws NullPointerException, OperatingSystemException
{
- nativeLock();
- try {
- int rv = exec0(INSTANCE, progname, args, env);
- if (rv == Error.APR_SUCCESS) {
- Id = pid0(INSTANCE);
- redirIs = new File(POOL, getios0(INSTANCE, 0));
- redirOs = new File(POOL, getios0(INSTANCE, 1));
- redirEs = new File(POOL, getios0(INSTANCE, 2));
- }
- return rv;
+ int rv = exec0(INSTANCE, progname, args, env);
+ if (rv == Error.APR_SUCCESS) {
+ Id = pid0(INSTANCE);
+ redirIs = new File(POOL, getios0(INSTANCE, 0));
+ redirOs = new File(POOL, getios0(INSTANCE, 1));
+ redirEs = new File(POOL, getios0(INSTANCE, 2));
}
- finally {
- nativeUnlock();
- }
+ return rv;
}
/**
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/native/include/sight_local.h 2007-10-01 07:58:39 UTC (rev 1065)
@@ -382,7 +382,18 @@
#define SIGHT_GLOBAL_CLEANUP() apr_atomic_dec32(sight_global_atomic)
#endif
+#define SIGHT_GLOBAL_TRY if (apr_atomic_inc32(sight_global_atomic))
+#define SIGHT_GLOBAL_END() apr_atomic_dec32(sight_global_atomic)
+#define SIGHT_GLOBAL_BRK() apr_atomic_dec32(sight_global_atomic)
+#define SIGHT_LOCAL_TRY(N) { apr_uint32_t _SGATOM = apr_atomic_inc32(sight_global_atomic); \
+ if ((N)) apr_atomic_inc32(&(N)->refcount); \
+ if ((N))
+
+#define SIGHT_LOCAL_END(N) apr_atomic_dec32(&(N)->refcount); } apr_atomic_dec32(sight_global_atomic)
+#define SIGHT_LOCAL_BRK(N) apr_atomic_dec32(&(N)->refcount); apr_atomic_dec32(sight_global_atomic)
+
+
/* Statistics counters */
extern volatile apr_uint64_t sight_cnt_native_alloc;
extern volatile apr_uint64_t sight_cnt_native_create;
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/native/include/sight_types.h 2007-10-01 07:58:39 UTC (rev 1065)
@@ -110,6 +110,7 @@
/* org.jboss.sight.NativeObject instance */
struct sight_object_t {
+ volatile apr_uint32_t refcount;
apr_pool_t *pool;
void *native;
void *opaque;
Modified: trunk/sight/native/share/dir.c
===================================================================
--- trunk/sight/native/share/dir.c 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/native/share/dir.c 2007-10-01 07:58:39 UTC (rev 1065)
@@ -50,34 +50,29 @@
jstring name)
{
sight_object_t *no = J2P(instance, sight_object_t *);
- apr_status_t rv;
+ apr_status_t rv = APR_ENOPOOL;
apr_dir_t *d = NULL;
SIGHT_ALLOC_CSTRING(name);
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- rv = APR_ENOPOOL;
- goto cleanup;
- }
-
if (!no || !no->pool) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOPOOL));
rv = APR_ENOPOOL;
goto cleanup;
}
- if ((rv = apr_dir_open(&d, J2S(name), no->pool)) != APR_SUCCESS) {
- throwAprException(_E, rv);
- goto cleanup;
- }
- no->clean = dir_cleanup;
- no->native = d;
-
+ SIGHT_LOCAL_TRY(no) {
+ if ((rv = apr_dir_open(&d, J2S(name), no->pool)) != APR_SUCCESS) {
+ throwAprException(_E, rv);
+ }
+ else {
+ no->clean = dir_cleanup;
+ no->native = d;
+ }
+ } SIGHT_LOCAL_END(no);
cleanup:
SIGHT_FREE_CSTRING(name);
- SIGHT_GLOBAL_CLEANUP();
return rv;
}
@@ -121,40 +116,33 @@
jobject fi = NULL;
apr_status_t rc;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- SIGHT_GLOBAL_CLEANUP();
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- return NULL;
- }
if (!no || !no->pool) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOPOOL));
- SIGHT_GLOBAL_CLEANUP();
return NULL;
}
if (!no->native) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOFILE));
- SIGHT_GLOBAL_CLEANUP();
return NULL;
}
else
d = (apr_dir_t *)no->native;
- if (!(fi = sight_new_finfo_class(_E, _O))) {
- SIGHT_GLOBAL_CLEANUP();
- return NULL;
- }
- rc = apr_dir_read(&info, wanted, d);
- if (rc == APR_SUCCESS || APR_STATUS_IS_INCOMPLETE(rc)) {
- sight_finfo_fill(_E, fi, &info);
- }
- else {
- (*_E)->DeleteLocalRef(_E, fi);
- /* Do not throw exceptions */
- fi = NULL;
- }
-
- SIGHT_GLOBAL_CLEANUP();
+ SIGHT_LOCAL_TRY(no) {
+ if (!(fi = sight_new_finfo_class(_E, _O))) {
+ SIGHT_LOCAL_BRK(no);
+ return NULL;
+ }
+ rc = apr_dir_read(&info, wanted, d);
+ if (rc == APR_SUCCESS || APR_STATUS_IS_INCOMPLETE(rc)) {
+ sight_finfo_fill(_E, fi, &info);
+ }
+ else {
+ (*_E)->DeleteLocalRef(_E, fi);
+ /* Do not throw exceptions */
+ fi = NULL;
+ }
+ } SIGHT_LOCAL_END(no);
return fi;
}
@@ -163,33 +151,28 @@
jint perms,
jboolean recursive)
{
- apr_status_t rv;
+ apr_status_t rv = APR_ENOPOOL;
apr_pool_t *p = NULL;
apr_fileperms_t perm = (apr_fileperms_t)perms;
SIGHT_ALLOC_CSTRING(name);
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- rv = APR_ENOPOOL;
- goto cleanup;
- }
- if ((rv = sight_create_pool(&p, sight_temp_pool)) != APR_SUCCESS) {
- throwAprException(_E, rv);
- goto cleanup;
- }
-
- if (recursive)
- rv = apr_dir_make_recursive(J2S(name), perm, p);
- else
- rv = apr_dir_make(J2S(name), perm, p);
-
+ SIGHT_GLOBAL_TRY {
+ if ((rv = sight_create_pool(&p, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprException(_E, rv);
+ SIGHT_GLOBAL_BRK();
+ goto cleanup;
+ }
+ if (recursive)
+ rv = apr_dir_make_recursive(J2S(name), perm, p);
+ else
+ rv = apr_dir_make(J2S(name), perm, p);
+ if (p)
+ apr_pool_destroy(p);
+ } SIGHT_GLOBAL_END();
cleanup:
- if (p)
- apr_pool_destroy(p);
SIGHT_FREE_CSTRING(name);
- SIGHT_GLOBAL_CLEANUP();
return rv;
}
@@ -263,10 +246,6 @@
SIGHT_ALLOC_CSTRING(path);
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- goto cleanup;
- }
if (!no || !no->pool) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOPOOL));
@@ -279,32 +258,29 @@
}
else
d = (apr_dir_t *)no->native;
- if (recursive)
- len = calc_size_r((apr_dir_t *)no->native, J2S(path), no->pool);
- else
- len = calc_size_d((apr_dir_t *)no->native);
+ SIGHT_LOCAL_TRY(no) {
+ if (recursive)
+ len = calc_size_r((apr_dir_t *)no->native, J2S(path), no->pool);
+ else
+ len = calc_size_d((apr_dir_t *)no->native);
+ } SIGHT_LOCAL_END(no);
+
cleanup:
SIGHT_FREE_CSTRING(path);
- SIGHT_GLOBAL_CLEANUP();
return (jlong)len;
}
SIGHT_EXPORT_DECLARE(jint, Directory, remove0)(SIGHT_STDARGS,
jstring name)
{
- apr_status_t rv;
+ apr_status_t rv = APR_ENOPOOL;
SIGHT_ALLOC_CSTRING(name);
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- rv = APR_ENOPOOL;
- goto cleanup;
+ SIGHT_GLOBAL_TRY {
+ rv = apr_dir_remove(J2S(name), NULL);
}
- rv = apr_dir_remove(J2S(name), NULL);
-cleanup:
SIGHT_FREE_CSTRING(name);
- SIGHT_GLOBAL_CLEANUP();
return rv;
}
Modified: trunk/sight/native/share/file.c
===================================================================
--- trunk/sight/native/share/file.c 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/native/share/file.c 2007-10-01 07:58:39 UTC (rev 1065)
@@ -52,28 +52,24 @@
SIGHT_ALLOC_CSTRING(name);
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- SIGHT_GLOBAL_CLEANUP();
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- return APR_ENOPOOL;
- }
if (!no || !no->pool) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOPOOL));
rv = APR_ENOPOOL;
goto cleanup;
}
- if ((rv = apr_file_open(&f, J2S(name), fflag,
- (apr_fileperms_t)perm, no->pool)) != APR_SUCCESS) {
- throwAprException(_E, rv);
- goto cleanup;
- }
- no->clean = file_cleanup;
- no->native = f;
-
+ SIGHT_LOCAL_TRY(no) {
+ if ((rv = apr_file_open(&f, J2S(name), fflag,
+ (apr_fileperms_t)perm, no->pool)) != APR_SUCCESS) {
+ throwAprException(_E, rv);
+ }
+ else {
+ no->clean = file_cleanup;
+ no->native = f;
+ }
+ } SIGHT_LOCAL_END(no);
cleanup:
SIGHT_FREE_CSTRING(name);
- SIGHT_GLOBAL_CLEANUP();
return rv;
}
@@ -101,17 +97,12 @@
jint flag)
{
sight_object_t *no = J2P(instance, sight_object_t *);
- apr_status_t rv;
+ apr_status_t rv = APR_ENOPOOL;
apr_file_t *f = NULL;
apr_int32_t fflag = (apr_int32_t)flag | APR_FOPEN_NOCLEANUP;
char *ctempl = NULL;
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- SIGHT_GLOBAL_CLEANUP();
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- return APR_ENOPOOL;
- }
if (!no || !no->pool) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOPOOL));
@@ -122,17 +113,18 @@
rv = APR_ENOMEM;
goto cleanup;
}
- if ((rv = apr_file_mktemp(&f, ctempl,
- fflag, no->pool)) != APR_SUCCESS) {
- throwAprException(_E, rv);
- goto cleanup;
- }
- no->clean = file_cleanup;
- no->native = f;
-
+ SIGHT_LOCAL_TRY(no) {
+ if ((rv = apr_file_mktemp(&f, ctempl,
+ fflag, no->pool)) != APR_SUCCESS) {
+ throwAprException(_E, rv);
+ }
+ else {
+ no->clean = file_cleanup;
+ no->native = f;
+ }
+ } SIGHT_LOCAL_END(no);
cleanup:
SIGHT_FREE(ctempl);
- SIGHT_GLOBAL_CLEANUP();
return rv;
}
@@ -141,40 +133,35 @@
jint which)
{
sight_object_t *no = J2P(instance, sight_object_t *);
- apr_status_t rv;
+ apr_status_t rv = APR_ENOPOOL;
apr_file_t *f = NULL;
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- SIGHT_GLOBAL_CLEANUP();
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- return APR_ENOPOOL;
- }
if (!no || !no->pool) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOPOOL));
- SIGHT_GLOBAL_CLEANUP();
return APR_ENOPOOL;
}
- switch (which) {
- case 0:
- rv = apr_file_open_stdin(&f, no->pool);
- break;
- case 1:
- rv = apr_file_open_stdout(&f, no->pool);
- break;
- default:
- rv = apr_file_open_stderr(&f, no->pool);
- break;
+ SIGHT_LOCAL_TRY(no) {
+ switch (which) {
+ case 0:
+ rv = apr_file_open_stdin(&f, no->pool);
+ break;
+ case 1:
+ rv = apr_file_open_stdout(&f, no->pool);
+ break;
+ default:
+ rv = apr_file_open_stderr(&f, no->pool);
+ break;
- }
- if (rv == APR_SUCCESS) {
- no->clean = NULL;
- no->native = f;
- }
- else
- throwAprException(_E, rv);
- SIGHT_GLOBAL_CLEANUP();
+ }
+ if (rv == APR_SUCCESS) {
+ no->clean = NULL;
+ no->native = f;
+ }
+ else
+ throwAprException(_E, rv);
+ } SIGHT_LOCAL_END(no);
return rv;
}
@@ -193,22 +180,23 @@
throwIOException(_E, sight_strerror(SIGHT_ENOFILE));
return 0;
}
- switch (where) {
- case 1:
- w = APR_CUR;
- break;
- case 2:
- w = APR_END;
- break;
- default:
- w = APR_SET;
- break;
- }
-
- if ((rv = apr_file_seek((apr_file_t *)no->native,
- w, &pos)) != APR_SUCCESS) {
- throwAprIOException(_E, rv);
- }
+ SIGHT_LOCAL_TRY(no) {
+ switch (where) {
+ case 1:
+ w = APR_CUR;
+ break;
+ case 2:
+ w = APR_END;
+ break;
+ default:
+ w = APR_SET;
+ break;
+ }
+ if ((rv = apr_file_seek((apr_file_t *)no->native,
+ w, &pos)) != APR_SUCCESS) {
+ throwAprIOException(_E, rv);
+ }
+ } SIGHT_LOCAL_END(no);
return (jlong)pos;
}
@@ -554,40 +542,31 @@
jobject fi = NULL;
apr_status_t rc;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- SIGHT_GLOBAL_CLEANUP();
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- return NULL;
- }
if (!no || !no->pool) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOPOOL));
- SIGHT_GLOBAL_CLEANUP();
return NULL;
}
if (!no->native) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOFILE));
- SIGHT_GLOBAL_CLEANUP();
return NULL;
}
else
f = (apr_file_t *)no->native;
- if (!(fi = sight_new_finfo_class(_E, _O))) {
- SIGHT_GLOBAL_CLEANUP();
- return NULL;
- }
- rc = apr_file_info_get(&info, wanted, f);
- if (rc == APR_SUCCESS || APR_STATUS_IS_INCOMPLETE(rc)) {
- sight_finfo_fill(_E, fi, &info);
- }
- else {
- (*_E)->DeleteLocalRef(_E, fi);
- /* Do not throw exceptions */
- fi = NULL;
- throwAprException(_E, rc);
- }
-
- SIGHT_GLOBAL_CLEANUP();
+ SIGHT_LOCAL_TRY(no) {
+ if ((fi = sight_new_finfo_class(_E, _O))) {
+ rc = apr_file_info_get(&info, wanted, f);
+ if (rc == APR_SUCCESS || APR_STATUS_IS_INCOMPLETE(rc)) {
+ sight_finfo_fill(_E, fi, &info);
+ }
+ else {
+ (*_E)->DeleteLocalRef(_E, fi);
+ /* Do not throw exceptions */
+ fi = NULL;
+ throwAprException(_E, rc);
+ }
+ }
+ } SIGHT_LOCAL_END(no);
return fi;
}
Modified: trunk/sight/native/share/finfo.c
===================================================================
--- trunk/sight/native/share/finfo.c 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/native/share/finfo.c 2007-10-01 07:58:39 UTC (rev 1065)
@@ -201,31 +201,27 @@
jint wanted)
{
apr_pool_t *p = NULL;
- apr_status_t rv = APR_SUCCESS;
+ apr_status_t rv = APR_ENOPOOL;
apr_finfo_t info;
SIGHT_ALLOC_CSTRING(name);
- if (!SIGHT_IS_VALID_GLOBAL()) {
- SIGHT_GLOBAL_CLEANUP();
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- return APR_ENOPOOL;
- }
- if ((rv = sight_create_pool(&p, sight_temp_pool)) != APR_SUCCESS) {
- throwAprException(_E, rv);
- goto cleanup;
- }
- memset(&info, 0, sizeof(apr_finfo_t));
- rv = apr_stat(&info, J2S(name), wanted, p);
- if (rv == APR_SUCCESS || rv == APR_INCOMPLETE) {
- sight_finfo_fill(_E, thiz, &info);
- }
- else {
- throwAprException(_E, rv);
- }
-cleanup:
- if (p)
- apr_pool_destroy(p);
+ SIGHT_GLOBAL_TRY {
+ if ((rv = sight_create_pool(&p, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprException(_E, rv);
+ }
+ else {
+ memset(&info, 0, sizeof(apr_finfo_t));
+ rv = apr_stat(&info, J2S(name), wanted, p);
+ if (rv == APR_SUCCESS || rv == APR_INCOMPLETE) {
+ sight_finfo_fill(_E, thiz, &info);
+ }
+ else {
+ throwAprException(_E, rv);
+ }
+ apr_pool_destroy(p);
+ }
+ } SIGHT_GLOBAL_END();
+
SIGHT_FREE_CSTRING(name);
- SIGHT_GLOBAL_CLEANUP();
return rv;
}
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/native/share/no.c 2007-10-01 07:58:39 UTC (rev 1065)
@@ -146,30 +146,26 @@
#endif
if (!no)
return;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- SIGHT_GLOBAL_CLEANUP();
- return;
- }
+ SIGHT_GLOBAL_TRY {
+ if (!pp)
+ pp = sight_global_pool;
- if (!pp)
- pp = sight_global_pool;
+ if ((rc = sight_create_pool(&pool, pp)) != APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ SIGHT_GLOBAL_END();
+ return;
+ }
- if ((rc = sight_create_pool(&pool, pp)) != APR_SUCCESS) {
- throwAprMemoryException(_E, THROW_FMARK, rc);
- SIGHT_GLOBAL_CLEANUP();
- return;
- }
+ c = (*_E)->GetObjectClass(_E, thiz);
+ no->destroy = (*_E)->GetMethodID(_E, c, "onDestroy", "()V");
+ no->object = (*_E)->NewWeakGlobalRef(_E, thiz);
+ no->pool = pool;
+ apr_pool_cleanup_register(pool, (const void *)no,
+ native_object_cleanup,
+ apr_pool_cleanup_null);
+ SET_IFIELD_J(0001, no->object, P2J(pool));
- c = (*_E)->GetObjectClass(_E, thiz);
- no->destroy = (*_E)->GetMethodID(_E, c, "onDestroy", "()V");
- no->object = (*_E)->NewWeakGlobalRef(_E, thiz);
- no->pool = pool;
- apr_pool_cleanup_register(pool, (const void *)no,
- native_object_cleanup,
- apr_pool_cleanup_null);
- SET_IFIELD_J(0001, no->object, P2J(pool));
- SIGHT_GLOBAL_CLEANUP();
+ } SIGHT_GLOBAL_END();
}
SIGHT_EXPORT_DECLARE(void, NativeObject, cbset0)(SIGHT_STDARGS,
@@ -183,23 +179,19 @@
if (!no)
return;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- SIGHT_GLOBAL_CLEANUP();
- return;
- }
- if (no->cb.object) {
- (*_E)->DeleteGlobalRef(_E, no->cb.object);
- no->cb.object = NULL;
- no->cb.method = NULL;
- }
- if (callback) {
- c = (*_E)->GetObjectClass(_E, callback);
- no->cb.object = (*_E)->NewGlobalRef(_E, callback);
- no->cb.method = (*_E)->GetMethodID(_E, c, no->cb.name, no->cb.msig);
- DBPRINTF("NativeObject_cbset0: %s/%s", no->cb.name, no->cb.msig);
- }
- SIGHT_GLOBAL_CLEANUP();
+ SIGHT_GLOBAL_TRY {
+ if (no->cb.object) {
+ (*_E)->DeleteGlobalRef(_E, no->cb.object);
+ no->cb.object = NULL;
+ no->cb.method = NULL;
+ }
+ if (callback) {
+ c = (*_E)->GetObjectClass(_E, callback);
+ no->cb.object = (*_E)->NewGlobalRef(_E, callback);
+ no->cb.method = (*_E)->GetMethodID(_E, c, no->cb.name, no->cb.msig);
+ DBPRINTF("NativeObject_cbset0: %s/%s", no->cb.name, no->cb.msig);
+ }
+ } SIGHT_GLOBAL_END();
}
SIGHT_EXPORT_DECLARE(void, NativeObject, free0)(SIGHT_STDARGS,
@@ -207,6 +199,7 @@
{
sight_object_t *no = J2P(instance, sight_object_t *);
jobject object = NULL;
+ apr_uint32_t refcount;
UNREFERENCED_O;
@@ -215,13 +208,18 @@
#endif
if (!no)
return;
-
if (no->object) {
object = (*_E)->NewLocalRef(_E, no->object);
(*_E)->DeleteWeakGlobalRef(_E, no->object);
no->object = object;
}
- if (SIGHT_IS_VALID_GLOBAL()) {
+
+ SIGHT_GLOBAL_TRY {
+ refcount = apr_atomic_read32(&no->refcount);
+ while (refcount) {
+ apr_thread_yield();
+ refcount = apr_atomic_read32(&no->refcount);
+ }
if (no->pool)
apr_pool_cleanup_kill(no->pool, no, native_object_cleanup);
if (no->object) {
@@ -235,7 +233,7 @@
(*no->clean)(POOL_DESTROY, no);
if (no->pool)
apr_pool_destroy(no->pool);
- }
+ } SIGHT_GLOBAL_END();
if (object) {
(*_E)->DeleteLocalRef(_E, object);
}
@@ -243,34 +241,38 @@
(*_E)->DeleteGlobalRef(_E, no->cb.object);
}
free(no);
- SIGHT_GLOBAL_CLEANUP();
}
SIGHT_EXPORT_DECLARE(void, NativeObject, clear0)(SIGHT_STDARGS,
jlong instance)
{
sight_object_t *no = J2P(instance, sight_object_t *);
+ apr_uint32_t refcount;
UNREFERENCED_O;
#ifdef SIGHT_DO_STATS
sight_cnt_native_clear++;
#endif
- if (!SIGHT_IS_VALID_GLOBAL()) {
- SIGHT_GLOBAL_CLEANUP();
+ if (!no)
return;
- }
+ SIGHT_GLOBAL_TRY {
+ refcount = apr_atomic_read32(&no->refcount);
+ while (refcount) {
+ apr_thread_yield();
+ refcount = apr_atomic_read32(&no->refcount);
+ }
- if (no && no->pool) {
- apr_pool_cleanup_kill(no->pool, no, native_object_cleanup);
- if (no->clean)
- (*no->clean)(POOL_CLEAR, no);
- apr_pool_clear(no->pool);
- apr_pool_cleanup_register(no->pool, (const void *)no,
- native_object_cleanup,
- apr_pool_cleanup_null);
- no->opaque = NULL;
- no->native = NULL;
- }
- SIGHT_GLOBAL_CLEANUP();
+ if (no->pool) {
+ apr_pool_cleanup_kill(no->pool, no, native_object_cleanup);
+ if (no->clean)
+ (*no->clean)(POOL_CLEAR, no);
+ apr_pool_clear(no->pool);
+ apr_pool_cleanup_register(no->pool, (const void *)no,
+ native_object_cleanup,
+ apr_pool_cleanup_null);
+ no->opaque = NULL;
+ no->native = NULL;
+ }
+ } SIGHT_GLOBAL_END();
}
Modified: trunk/sight/native/share/pool.c
===================================================================
--- trunk/sight/native/share/pool.c 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/native/share/pool.c 2007-10-01 07:58:39 UTC (rev 1065)
@@ -61,7 +61,7 @@
jobject obj)
{
sight_object_t *no = J2P(instance, sight_object_t *);
- sight_callback_t *cb;
+ sight_callback_t *cb = NULL;
jclass c;
UNREFERENCED_O;
@@ -70,29 +70,22 @@
sight_strerror(SIGHT_ENOPOOL));
return 0;
}
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- SIGHT_GLOBAL_CLEANUP();
+ if (!(cb = (sight_callback_t *)sight_calloc(_E,
+ sizeof(sight_callback_t),
+ THROW_FMARK))) {
return 0;
}
- cb = (sight_callback_t *)calloc(1, sizeof(sight_callback_t));
- if (cb == NULL) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
- SIGHT_GLOBAL_CLEANUP();
- return 0;
- }
- c = (*_E)->GetObjectClass(_E, obj);
- cb->name = "cleanup";
- cb->msig = "()I";
- cb->object = (*_E)->NewGlobalRef(_E, obj);
- cb->method = (*_E)->GetMethodID(_E, c, cb->name, cb->msig);
+ SIGHT_LOCAL_TRY(no) {
+ c = (*_E)->GetObjectClass(_E, obj);
+ cb->name = "cleanup";
+ cb->msig = "()I";
+ cb->object = (*_E)->NewGlobalRef(_E, obj);
+ cb->method = (*_E)->GetMethodID(_E, c, cb->name, cb->msig);
- apr_pool_cleanup_register(no->pool, (const void *)cb,
- callback_object_cleanup,
- apr_pool_cleanup_null);
-
- SIGHT_GLOBAL_CLEANUP();
+ apr_pool_cleanup_register(no->pool, (const void *)cb,
+ callback_object_cleanup,
+ apr_pool_cleanup_null);
+ } SIGHT_LOCAL_END(no);
return P2J(cb);
}
@@ -114,10 +107,9 @@
sight_strerror(SIGHT_ENULL));
return;
}
- if (SIGHT_IS_VALID_GLOBAL()) {
+ SIGHT_LOCAL_TRY(no) {
apr_pool_cleanup_kill(no->pool, cb, callback_object_cleanup);
- SIGHT_GLOBAL_CLEANUP();
- }
+ } SIGHT_LOCAL_END(no);
if (cb->object)
(*_E)->DeleteGlobalRef(_E, cb->object);
free(cb);
Modified: trunk/sight/native/share/proc.c
===================================================================
--- trunk/sight/native/share/proc.c 2007-10-01 07:10:19 UTC (rev 1064)
+++ trunk/sight/native/share/proc.c 2007-10-01 07:58:39 UTC (rev 1065)
@@ -59,11 +59,6 @@
apr_status_t rv;
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- rv = APR_ENOPOOL;
- goto cleanup;
- }
if (!no || !no->pool) {
throwNullPointerException(_E, THROW_FMARK,
@@ -71,23 +66,26 @@
rv = APR_ENOPOOL;
goto cleanup;
}
- p = (sight_runproc_t *)sight_pcalloc(_E, no->pool, sizeof(sight_runproc_t),
- THROW_FMARK);
- if (p == NULL) {
- rv = APR_ENOMEM;
- goto cleanup;
- }
- if ((rv = apr_procattr_create(&p->attr, no->pool)) != APR_SUCCESS) {
- goto cleanup;
- }
- p->exitval = -1;
+ SIGHT_LOCAL_TRY(no) {
+ p = (sight_runproc_t *)sight_pcalloc(_E, no->pool, sizeof(sight_runproc_t),
+ THROW_FMARK);
+ if (p == NULL) {
+ rv = APR_ENOMEM;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ if ((rv = apr_procattr_create(&p->attr, no->pool)) != APR_SUCCESS) {
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ p->exitval = -1;
#ifdef SIGHT_DO_STATS
- no->clean = proc_cleanup;
+ no->clean = proc_cleanup;
#endif
- no->native = p;
- rv = APR_SUCCESS;
+ no->native = p;
+ rv = APR_SUCCESS;
+ } SIGHT_LOCAL_END(no);
cleanup:
- SIGHT_GLOBAL_CLEANUP();
return rv;
}
@@ -310,9 +308,11 @@
UNREFERENCED_STDARGS;
if (!no || !no->native)
return APR_EINVAL;
- p = (sight_runproc_t *)no->native;
- rv = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
- (apr_wait_how_e)waithow);
+ SIGHT_LOCAL_TRY(no) {
+ p = (sight_runproc_t *)no->native;
+ rv = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
+ (apr_wait_how_e)waithow);
+ } SIGHT_LOCAL_END(no);
return rv;
}
@@ -324,7 +324,7 @@
{
sight_object_t *no = J2P(instance, sight_object_t *);
sight_runproc_t *p;
- apr_status_t rc;
+ apr_status_t rc = APR_ENOPOOL;
apr_interval_time_t timeout_value, timeout_interval;
apr_wait_how_e how = (apr_wait_how_e)waithow;
@@ -332,26 +332,31 @@
if (!no || !no->native)
return APR_EINVAL;
- p = (sight_runproc_t *)no->native;
- if (timeout < 0)
- how = APR_WAIT;
- else
- how = APR_NOWAIT;
- if ((rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
- how)) != APR_CHILD_NOTDONE)
- return rc;
- if (timeout < 1)
- return APR_EINVAL;
- timeout_value = timeout * 1000L;
- timeout_interval = timeout_value / 64;
- do {
- apr_sleep(timeout_interval);
- rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy, APR_NOWAIT);
- if (timeout_interval >= timeout_value)
- break;
- timeout_interval *= 2;
- } while (rc == APR_CHILD_NOTDONE);
-
+ SIGHT_LOCAL_TRY(no) {
+ p = (sight_runproc_t *)no->native;
+ if (timeout < 0)
+ how = APR_WAIT;
+ else
+ how = APR_NOWAIT;
+ if ((rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
+ how)) != APR_CHILD_NOTDONE) {
+ SIGHT_LOCAL_BRK(no);
+ return rc;
+ }
+ if (timeout < 1) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_EINVAL;
+ }
+ timeout_value = timeout * 1000L;
+ timeout_interval = timeout_value / 64;
+ do {
+ apr_sleep(timeout_interval);
+ rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy, APR_NOWAIT);
+ if (timeout_interval >= timeout_value)
+ break;
+ timeout_interval *= 2;
+ } while (rc == APR_CHILD_NOTDONE);
+ } SIGHT_LOCAL_END(no);
return rc;
}
@@ -372,54 +377,59 @@
UNREFERENCED_O;
if (!no || !no->native || !progress)
return APR_EINVAL;
- p = (sight_runproc_t *)no->native;
- if ((rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
- APR_NOWAIT)) != APR_CHILD_NOTDONE)
- return rc;
-
- c = (*_E)->GetObjectClass(_E, progress);
- cb.name = "progress";
- cb.msig = "(I)I";
- cb.object = progress;
- cb.method = (*_E)->GetMethodID(_E, c, cb.name, cb.msig);
- if (!cb.method || (*_E)->ExceptionCheck(_E)) {
- return APR_EINVAL;
- }
- cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick, NULL);
- if ((*_E)->ExceptionCheck(_E)) {
- return APR_FROM_OS_ERROR(EINTR);
- }
-
- if (timeout > 0) {
- timeout_value = timeout * 1000L;
- timeout_interval = timeout_value / 100;
- }
- else {
- /* Defaults to 100 ms */
- timeout_interval = 100000L;
- }
- do {
- if (cres < 0) {
- /* Broken by the callback */
- break;
+ SIGHT_LOCAL_TRY(no) {
+ p = (sight_runproc_t *)no->native;
+ if ((rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
+ APR_NOWAIT)) != APR_CHILD_NOTDONE) {
+ SIGHT_LOCAL_BRK(no);
+ return rc;
}
- else if (cres > 0) {
- timeout_interval = cres * 1000L;
+ c = (*_E)->GetObjectClass(_E, progress);
+ cb.name = "progress";
+ cb.msig = "(I)I";
+ cb.object = progress;
+ cb.method = (*_E)->GetMethodID(_E, c, cb.name, cb.msig);
+ if (!cb.method || (*_E)->ExceptionCheck(_E)) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_EINVAL;
}
- apr_sleep(timeout_interval);
- rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy, APR_NOWAIT);
- if (timeout > 0) {
- if (timeout_interval >= timeout_value)
- break;
- timeout_value -= timeout_interval;
- }
- cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick++, NULL);
+ cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick, NULL);
if ((*_E)->ExceptionCheck(_E)) {
+ SIGHT_LOCAL_BRK(no);
return APR_FROM_OS_ERROR(EINTR);
}
- } while (rc == APR_CHILD_NOTDONE);
+ if (timeout > 0) {
+ timeout_value = timeout * 1000L;
+ timeout_interval = timeout_value / 100;
+ }
+ else {
+ /* Defaults to 100 ms */
+ timeout_interval = 100000L;
+ }
+ do {
+ if (cres < 0) {
+ /* Broken by the callback */
+ break;
+ }
+ else if (cres > 0) {
+ timeout_interval = cres * 1000L;
+ }
+ apr_sleep(timeout_interval);
+ rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy, APR_NOWAIT);
+ if (timeout > 0) {
+ if (timeout_interval >= timeout_value)
+ break;
+ timeout_value -= timeout_interval;
+ }
+ cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick++, NULL);
+ if ((*_E)->ExceptionCheck(_E)) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_FROM_OS_ERROR(EINTR);
+ }
+ } while (rc == APR_CHILD_NOTDONE);
+ } SIGHT_LOCAL_END(no);
return rc;
}
@@ -470,61 +480,59 @@
UNREFERENCED_O;
- if (!SIGHT_IS_VALID_GLOBAL()) {
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- rv = APR_ENOPOOL;
- goto cleanup;
- }
-
if (!no || !no->native) {
throwNullPointerException(_E, THROW_FMARK,
sight_strerror(SIGHT_ENOPROC));
rv = APR_ENOPOOL;
goto cleanup;
}
- if (args)
- largs = (*_E)->GetArrayLength(_E, args);
- if (env)
- lenv = (*_E)->GetArrayLength(_E, env);
- if (largs > MAX_ARGS_SIZE || lenv > MAX_ENV_SIZE) {
- rv = APR_EINVAL;
- goto cleanup;
- }
- if (largs) {
- for (i = 0; i < largs; i++) {
- jstring str = (*_E)->GetObjectArrayElement(_E, args, i);
- if (!str || (*_E)->ExceptionCheck(_E)) {
- rv = APR_EINVAL;
- goto cleanup;
- }
- sargs[i] = sight_pstrdupj(no->pool, _E, str);
- (*_E)->DeleteLocalRef(_E, str);
+ SIGHT_LOCAL_TRY(no) {
+ if (args)
+ largs = (*_E)->GetArrayLength(_E, args);
+ if (env)
+ lenv = (*_E)->GetArrayLength(_E, env);
+ if (largs > MAX_ARGS_SIZE || lenv > MAX_ENV_SIZE) {
+ rv = APR_EINVAL;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
}
- sargs[i] = NULL;
- pargs = (const char * const *)&sargs[0];
- }
- if (lenv) {
- for (i = 0; i < lenv; i++) {
- jstring str = (*_E)->GetObjectArrayElement(_E, env, i);
- if (!str || (*_E)->ExceptionCheck(_E)) {
- rv = APR_EINVAL;
- goto cleanup;
- }
- senv[i] = sight_pstrdupj(no->pool, _E, str);
- (*_E)->DeleteLocalRef(_E, str);
+ if (largs) {
+ for (i = 0; i < largs; i++) {
+ jstring str = (*_E)->GetObjectArrayElement(_E, args, i);
+ if (!str || (*_E)->ExceptionCheck(_E)) {
+ rv = APR_EINVAL;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ sargs[i] = sight_pstrdupj(no->pool, _E, str);
+ (*_E)->DeleteLocalRef(_E, str);
+ }
+ sargs[i] = NULL;
+ pargs = (const char * const *)&sargs[0];
}
- senv[i] = NULL;
- penv = (const char * const *)&senv[0];
- }
- p = (sight_runproc_t *)no->native;
- rv = apr_proc_create(&p->p, J2S(progname), pargs,
- penv, p->attr, no->pool);
- if (rv != APR_SUCCESS) {
- throwAprException(_E, rv);
- }
+ if (lenv) {
+ for (i = 0; i < lenv; i++) {
+ jstring str = (*_E)->GetObjectArrayElement(_E, env, i);
+ if (!str || (*_E)->ExceptionCheck(_E)) {
+ rv = APR_EINVAL;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
+ senv[i] = sight_pstrdupj(no->pool, _E, str);
+ (*_E)->DeleteLocalRef(_E, str);
+ }
+ senv[i] = NULL;
+ penv = (const char * const *)&senv[0];
+ }
+ p = (sight_runproc_t *)no->native;
+ rv = apr_proc_create(&p->p, J2S(progname), pargs,
+ penv, p->attr, no->pool);
+ if (rv != APR_SUCCESS) {
+ throwAprException(_E, rv);
+ }
+ } SIGHT_LOCAL_END(no);
cleanup:
SIGHT_FREE_CSTRING(progname);
- SIGHT_GLOBAL_CLEANUP();
return rv;
}
@@ -566,24 +574,27 @@
{
sight_object_t *no = J2P(instance, sight_object_t *);
sight_runproc_t *p;
+ apr_status_t rv = APR_EINVAL;
UNREFERENCED_O;
if (!no || !no->native) {
return APR_EINVAL;
}
- p = (sight_runproc_t *)no->native;
- switch (which) {
- case 0:
- return apr_file_pipe_timeout_set(p->p.in, timeout * 1000L);
- break;
- case 1:
- return apr_file_pipe_timeout_set(p->p.out, timeout * 1000L);
- break;
- case 2:
- return apr_file_pipe_timeout_set(p->p.err, timeout * 1000L);
- break;
- }
- return APR_EINVAL;
+ SIGHT_LOCAL_TRY(no) {
+ p = (sight_runproc_t *)no->native;
+ switch (which) {
+ case 0:
+ rv = apr_file_pipe_timeout_set(p->p.in, timeout * 1000L);
+ break;
+ case 1:
+ rv = apr_file_pipe_timeout_set(p->p.out, timeout * 1000L);
+ break;
+ case 2:
+ rv = apr_file_pipe_timeout_set(p->p.err, timeout * 1000L);
+ break;
+ }
+ } SIGHT_LOCAL_END(no);
+ return rv;
}
SIGHT_EXPORT_DECLARE(void, Process, notes0)(SIGHT_STDARGS,
17 years, 2 months
JBoss Native SVN: r1064 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-01 03:10:19 -0400 (Mon, 01 Oct 2007)
New Revision: 1064
Modified:
trunk/sight/native/os/solaris/network.c
Log:
That the same than the linux one.
Modified: trunk/sight/native/os/solaris/network.c
===================================================================
--- trunk/sight/native/os/solaris/network.c 2007-09-30 15:03:08 UTC (rev 1063)
+++ trunk/sight/native/os/solaris/network.c 2007-10-01 07:10:19 UTC (rev 1064)
@@ -30,6 +30,8 @@
#include "sight_types.h"
#include "sight_private.h"
+#include <unistd.h>
+
/*
* Network
*/
@@ -79,8 +81,63 @@
jlong pool)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(pool);
+ int i;
+ sight_arr_t *tdns;
+ char buf[SIGHT_SBUFFER_SIZ];
+ char *pd;
+ jsize len = 0, idx = 0;
+ UNREFERENCED_O;
+
+ if (gethostname(buf, SIGHT_SBUFFER_LEN)) {
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
+ if ((pd = strchr(buf, '.'))) {
+ *pd++ = '\0';
+ SET_IFIELD_S(0000, thiz, buf);
+ SET_IFIELD_S(0001, thiz, pd);
+ }
+ else {
+ /* Use domainname if hostname misses dot */
+ SET_IFIELD_S(0000, thiz, buf);
+ if (getdomainname(buf, SIGHT_SBUFFER_LEN)) {
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
+ SET_IFIELD_S(0001, thiz, buf);
+ }
+ if ((tdns = sight_arr_rload("/etc/resolv.conf"))) {
+ for (i = 0; i < tdns->siz; i++) {
+ if (strstr(tdns->arr[i], "nameserver")) {
+ len++;
+ }
+ }
+ if (len) {
+ jobject addr;
+ jobjectArray aaddr;
+ aaddr = sight_new_netaddr_array(_E, _O, len);
+ if (!aaddr || (*_E)->ExceptionCheck(_E)) {
+ goto cleanup;
+ }
+ for (i = 0; i < tdns->siz; i++) {
+ if ((pd = strstr(tdns->arr[i], "nameserver"))) {
+ pd += 10;
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E)) {
+ goto cleanup;
+ }
+ sight_netaddr_set_addr(_E, addr, sight_trim(pd));
+ sight_netaddr_set_family(_E, addr, AF_INET);
+ (*_E)->SetObjectArrayElement(_E, aaddr, idx++, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ }
+ SET_IFIELD_O(0002, thiz, aaddr);
+ (*_E)->DeleteLocalRef(_E, aaddr);
+ }
+ }
+cleanup:
+ if (tdns)
+ sight_arr_free(tdns);
}
17 years, 2 months