You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/13 16:47:56 UTC
svn commit: r814323 - in /commons/sandbox/runtime/trunk/src: main/native/
main/native/include/ main/native/os/win32/ main/native/shared/
main/native/test/ test/org/apache/commons/runtime/
Author: mturk
Date: Sun Sep 13 14:47:56 2009
New Revision: 814323
URL: http://svn.apache.org/viewvc?rev=814323&view=rev
Log:
Add java.lang.System class support so we can call System.exit and stuff
Added:
commons/sandbox/runtime/trunk/src/main/native/include/acr_system.h (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/system.c (with props)
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSystem.java (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=814323&r1=814322&r2=814323&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Sun Sep 13 14:47:56 2009
@@ -109,6 +109,7 @@
$(SRCDIR)/shared/sema.$(OBJ) \
$(SRCDIR)/shared/shm.$(OBJ) \
$(SRCDIR)/shared/string.$(OBJ) \
+ $(SRCDIR)/shared/system.$(OBJ) \
$(SRCDIR)/shared/tables.$(OBJ) \
$(SRCDIR)/shared/xdr.$(OBJ) \
$(SRCDIR)/shared/zip.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=814323&r1=814322&r2=814323&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sun Sep 13 14:47:56 2009
@@ -99,6 +99,7 @@
$(SRCDIR)/shared/sema.$(OBJ) \
$(SRCDIR)/shared/shm.$(OBJ) \
$(SRCDIR)/shared/string.$(OBJ) \
+ $(SRCDIR)/shared/system.$(OBJ) \
$(SRCDIR)/shared/tables.$(OBJ) \
$(SRCDIR)/shared/xdr.$(OBJ) \
$(SRCDIR)/shared/zip.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h?rev=814323&r1=814322&r2=814323&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h Sun Sep 13 14:47:56 2009
@@ -130,9 +130,9 @@
wchar_t *_w##V = ACR_GetJavaStringW(_E, (V), _b##V); \
if (!_w##V && (V)) goto _cw##V;
-#define END_WITH_WSTR(V) \
- _cw##V : \
- if (_w##V && _w##V != _b##V) free (_w##V); \
+#define END_WITH_WSTR(V) \
+ _cw##V : \
+ if (_w##V && _w##V != _b##V) x_free (_w##V); \
} else ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL, 0)
#define WITH_CSTR(V) \
@@ -147,9 +147,9 @@
char *_c##V = ACR_GetJavaStringA(_E, (V), _b##V); \
if (!_c##V && (V)) goto _ca##V;
-#define END_WITH_CSTR(V) \
- _ca##V : \
- if (_c##V && _c##V != _b##V) free (_c##V); \
+#define END_WITH_CSTR(V) \
+ _ca##V : \
+ if (_c##V && _c##V != _b##V) x_free (_c##V); \
} else ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL, 0)
#define RETURN_UCSTR(V) \
@@ -334,7 +334,7 @@
if (_m##I##n.i == NULL) { \
_m##I##n.i = (*_E)->GetStaticMethodID(_E, _clazzn.i, _m##I##n.n, \
_m##I##n.s); \
- if ((*_E)->ExceptionCheck(_E) || _m##I##.i == NULL) { \
+ if ((*_E)->ExceptionCheck(_E) || _m##I##n.i == NULL) { \
return ACR_ESYMNOTFOUND; \
} \
} else (void)(0)
@@ -465,19 +465,19 @@
(*_E)->CallVoidMethod(_E, (O), _m##I##n.i); \
} else (void)(0)
-#define CALL_VMETHOD1(I, O, V) \
+#define CALL_VMETHOD1(I, O, A) \
if (_m##I##n.i) { \
- (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (V)); \
+ (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A)); \
} else (void)(0)
-#define CALL_VMETHOD2(I, O, V, X) \
+#define CALL_VMETHOD2(I, O, A1, A2) \
if (_m##I##n.i) { \
- (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (V), (X)); \
+ (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A1), (A2)); \
} else (void)(0)
-#define CALL_VMETHOD3(I, O, V, X, Y) \
+#define CALL_VMETHOD3(I, O, A1, A2, A3) \
if (_m##I##n.i) { \
- (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (V), (X), (Y)); \
+ (*_E)->CallVoidMethod(_E, (O), _m##I##n.i, (A1), (A2), (A3)); \
} else (void)(0)
#define CALL_METHOD0(T, I, O) \
@@ -489,6 +489,33 @@
#define CALL_METHOD2(T, I, O, A1, A2) \
(*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A1), (A2))
+#define CALL_METHOD3(T, I, O, A1, A2, A3) \
+ (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A1), (A2), (A3))
+
+#define CALL_MLOCAL0(T, I) \
+ (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i)
+
+#define CALL_MLOCAL1(T, I, A) \
+ (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i, (A))
+
+#define CALL_MLOCAL2(T, I, A1, A2) \
+ (*_E)->CallStatic##T##Method(_E, _clazzn.i, _m##I##n.i, (A1), (A2))
+
+#define CALL_VMLOCAL0(I) \
+ if (_m##I##n.i) { \
+ (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i); \
+ } else (void)(0)
+
+#define CALL_VMLOCAL1(I, A) \
+ if (_m##I##n.i) { \
+ (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i, (A)); \
+ } else (void)(0)
+
+#define CALL_VMLOCAL2(I, A1, A2) \
+ if (_m##I##n.i) { \
+ (*_E)->CallStaticVoidMethod(_E, _clazzn.i, _m##I##n.i, (A1), (A2)); \
+ } else (void)(0)
+
#define SET_SARRAY_A(A, I, V) \
if ((A) && (V)) { \
jstring _str = ACR_NewJavaStringA(_E, (V)); \
Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_system.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_system.h?rev=814323&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_system.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_system.h Sun Sep 13 14:47:56 2009
@@ -0,0 +1,56 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACR_SYSTEM_H
+#define _ACR_SYSTEM_H
+
+#include "acr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_system.h
+ * @brief
+ *
+ * ACR java.lang.System support.
+ *
+ */
+
+/**
+ * Run the System.exit.
+ * @param env Current JNI environment
+ * @param status exit status.
+ * @return ACR error code.
+ */
+ACR_DECLARE(int) ACR_SystemExit(JNIEnv *env, jint status);
+
+/**
+ * Run the System.getProperty.
+ * @param env Current JNI environment
+ * @param key the name of the system property.
+ * @return the string value of the system property, or null if
+ * there is no property with that key. Use ACR_Free when the returned
+ * string is no longer needed.
+ */
+ACR_DECLARE(char *) ACR_SystemGetProperty(JNIEnv *env, const char *key);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_SYSTEM_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_system.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=814323&r1=814322&r2=814323&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Sun Sep 13 14:47:56 2009
@@ -16,7 +16,10 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_arch.h"
#include "acr_error.h"
+#include "acr_port.h"
+#include "acr_signals.h"
#include "acr_tlsd.h"
#include "acr_vm.h"
@@ -245,9 +248,9 @@
event_key = x_malloc(strlen(domain) + 64);
if (!event_key)
return;
- lstrcpyA(event_key,
- "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
- lstrcatA(event_key, domain);
+ strcpy(event_key,
+ "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
+ strcat(event_key, domain);
if (!RegCreateKeyA(HKEY_LOCAL_MACHINE, event_key, &key)) {
RegSetValueExW(key, L"EventMessageFile", 0, REG_EXPAND_SZ,
(LPBYTE)&dll_file_name[0],
@@ -304,6 +307,11 @@
return (int)rc;
}
+ if ((rc = acr_SignalsInit())) {
+ /* Failed initializing signaling sub system
+ */
+ return (int)rc;
+ }
/* Up to here we can be called multiple times.
*/
if (initialized++)
@@ -311,16 +319,16 @@
while (sePrivileges[i]) {
if ((rc = ACR_EnablePrivilege(sePrivileges[i])) != ERROR_SUCCESS) {
- WCHAR buf[128];
-#if _MSC_VER >= 1300
- swprintf(buf, sizeof(buf),
-#else
- swprintf(buf,
-#endif
- L"Failed enabling %s", sePrivileges[i]);
+ wchar_t buf[128];
+ _snwprintf(buf, sizeof(buf), L"Failed enabling %s",
+ sePrivileges[i]);
/* Log that we couldn't set privilege */
acr_init_log_source(NULL);
do_syslog(ACR_LOG_WARN, buf, rc);
+#if defined(DEBUG)
+ fprintf(stderr, "[WARN] %S\n", buf);
+ fflush(stderr);
+#endif
}
i++;
}
@@ -356,8 +364,9 @@
em = SetErrorMode(0);
SetErrorMode(em | SEM_NOOPENFILEERRORBOX);
#if defined(DEBUG)
- fprintf(stdout, "Initialized ACR : %S\n", dll_file_name);
+ fprintf(stdout, "\nInitialized ACR : %S\n", dll_file_name);
fprintf(stdout, " : %S\n", dos_file_name);
+ fflush(stdout);
#endif
return 0;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c?rev=814323&r1=814322&r2=814323&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c Sun Sep 13 14:47:56 2009
@@ -34,6 +34,9 @@
#include "acr_descriptor.h"
#include "acr_crypto.h"
#include "acr_signals.h"
+#include "acr_system.h"
+#include "acr_tlsd.h"
+#include "acr_vm.h"
#if defined(NSIG)
#define ACR_NUMSIG NSIG
@@ -51,6 +54,8 @@
volatile LONG current_signal_queue;
volatile LONG current_signal_listeners;
+static SIG_PF signal_handlers[ACR_NUMSIG];
+
static void make_security_cookie(acr_sig_msg_t *msg, const wchar_t *salt,
DWORD sn, DWORD to)
{
@@ -92,6 +97,47 @@
return memcmp(digest, msg->cookie, 20);
}
+/* Default signal handler.
+ */
+static void default_signal_handler(int sig)
+{
+ JNIEnv *_E;
+ switch (sig) {
+ case SIGKILL:
+ /* Call the System.exit(9)
+ */
+ if (ACR_SystemExit(NULL, sig)) {
+ /* System.exit failed, calll the _exit so we
+ * skip all the atexit hooks.
+ */
+ _exit(sig);
+ }
+ break;
+ case SIGTERM:
+ break;
+ case SIGBUS:
+ case SIGSEGV:
+ _E = ACR_GetJNIEnv();
+ if (IS_VALID_HANDLE(_E)) {
+ (*_E)->FatalError(_E, strsignal(sig));
+ }
+ else {
+ fprintf(stderr, "[native] Fatal - %s\n", strsignal(sig));
+ fprintf(stderr, "[native] Terminating ...\n");
+ fflush(stderr);
+ ExitProcess(sig);
+ }
+ break;
+ default:
+ /* Do nothing */
+#if defined(DEBUG)
+ fprintf(stderr, "[native] Unhandled - %s\n", strsignal(sig));
+#endif
+ break;
+ }
+}
+
+
/*
* Make sure this handler is initialized again
* after JVM is loaded. JVM installs it's own ConsoleHandler
@@ -158,22 +204,51 @@
return handled;
}
+static volatile int signal_handlers_running;
+
+/* Main signal thread is responsible for handling the signal
+ * events.
+ * Once created it will remain running until application exit,
+ * so there is no need for any thread cleanup since we cannot
+ * leak single thread.
+ */
+static DWORD WINAPI main_signal_thread(LPVOID unused)
+{
+#if defined(DEBUG)
+ fprintf(stdout, "\n[native] Initialized signalig subsystem for %d\n",
+ GetCurrentProcessId());
+ fflush(stdout);
+#endif
+ while (signal_handlers_running) {
+
+ /* Until we implement the pupmp.
+ */
+ Sleep(1000);
+ }
+#if defined(DEBUG)
+ fprintf(stdout, "\n[native] Terminated signalig subsystem for %d\n",
+ GetCurrentProcessId());
+ fflush(stdout);
+#endif
+ return 0;
+}
int acr_SignalsInit()
{
- static int initialized = 0;
+ DWORD i;
/* Guard against multiple invocations.
* We might initialize twice; in daemon and in JVM again
*/
- if (initialized++) {
- if (initialized == 1) {
- /* Second invocation.
- * Put the ConsoleHandler routine on top of JVM handler routine.
- */
- if (!SetConsoleCtrlHandler(console_event_handler, TRUE))
- return ACR_GET_OS_ERROR();
- }
+ if (signal_handlers_running++) {
+ /* Second invocation.
+ * Remove any previous handlers to our callback.
+ */
+ SetConsoleCtrlHandler(console_event_handler, FALSE);
+ /* Put the ConsoleHandler routine on top of JVM handler routine.
+ */
+ if (!SetConsoleCtrlHandler(console_event_handler, TRUE))
+ return ACR_GET_OS_ERROR();
return 0;
}
if (!InitializeCriticalSectionAndSpinCount(&signal_lock, ACR_SPINCOUNT)) {
@@ -183,9 +258,29 @@
int rc = ACR_GET_OS_ERROR();
DeleteCriticalSection(&signal_lock);
- initialized = 0;
+ signal_handlers_running = 0;
return rc;
}
+ for (i = 0; i < ACR_NUMSIG; i++)
+ signal_handlers[i] = SIG_IGN;
+ signal_handlers[SIGBUS] = default_signal_handler;
+ signal_handlers[SIGSEGV] = default_signal_handler;
+ signal_handlers[SIGKILL] = default_signal_handler;
+ signal_handlers[SIGTERM] = default_signal_handler;
+
+ if (!CreateThread(NULL,
+ 0,
+ main_signal_thread,
+ NULL,
+ 0,
+ &i)) {
+ /* Failed creating thread.
+ * If we ever get here the system is
+ * unstable and will probably crash
+ * in the near future. Anyhow, return the error.
+ */
+ return ACR_GET_OS_ERROR();
+ }
return 0;
}
@@ -221,7 +316,7 @@
}
if ((mask = (current_signal_queue & ~current_signal_mask))) {
int i;
- for (i = 1; i < _NSIG, rc == ACR_EINTR; i++) {
+ for (i = 1; i < ACR_NUMSIG, rc == ACR_EINTR; i++) {
if (mask & sigmask(i)) {
switch (i) {
case SIGKILL:
@@ -233,6 +328,10 @@
rc = ACR_EINTR;
break;
}
+ if (signal_handlers[i-1] != SIG_IGN) {
+ /* TODO: Handle default signals */
+ (*signal_handlers[i-1])(i);
+ }
}
}
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=814323&r1=814322&r2=814323&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Sun Sep 13 14:47:56 2009
@@ -190,6 +190,7 @@
ACR_CLASS_LDEF(Observer);
ACR_CLASS_LDEF(Object);
ACR_CLASS_LDEF(String);
+ACR_CLASS_LDEF(System);
int ACR_InitCoreClasses(JNIEnv *_E)
{
@@ -225,6 +226,7 @@
ACR_CLASS_LRUN(Object);
ACR_CLASS_LRUN(Class);
ACR_CLASS_LRUN(String);
+ ACR_CLASS_LRUN(System);
ACR_CLASS_LRUN(Observer);
return ACR_SUCCESS;
Added: commons/sandbox/runtime/trunk/src/main/native/shared/system.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/system.c?rev=814323&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/system.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/system.c Sun Sep 13 14:47:56 2009
@@ -0,0 +1,105 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_clazz.h"
+#include "acr_error.h"
+#include "acr_memory.h"
+#include "acr_object.h"
+#include "acr_string.h"
+#include "acr_system.h"
+#include "acr_vm.h"
+
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ "java/lang/System"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "exit",
+ "(I)V"
+};
+
+J_DECLARE_M_ID(0001) = {
+ NULL,
+ "getProperty",
+ "(Ljava/lang/String;)Ljava/lang/String;"
+};
+
+ACR_CLASS_LDEF(System)
+{
+ int rv;
+
+ if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+ return rv;
+ J_LOAD_MLOCAL(0000);
+ J_LOAD_MLOCAL(0001);
+
+ return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(System)
+{
+ ACR_UnloadClass(_E, &_clazzn);
+}
+
+ACR_DECLARE(int) ACR_SystemExit(JNIEnv *_E, jint status)
+{
+ if (_E == NULL)
+ _E = ACR_GetJNIEnv();
+ if (IS_INVALID_HANDLE(_E))
+ return ACR_ENOJNIENV;
+ CALL_VMLOCAL1(0000, status);
+ if ((*_E)->ExceptionCheck(_E) == JNI_TRUE) {
+ (*_E)->ExceptionClear(_E);
+ /* System.exit() can throw only SecurityException
+ */
+ return ACR_EACCES;
+ }
+ return ACR_SUCCESS;
+}
+
+ACR_DECLARE(char *) ACR_SystemGetProperty(JNIEnv *_E, const char *key)
+{
+ char *val = NULL;
+ jstring skey;
+ jstring sval;
+ if (_E == NULL)
+ _E = ACR_GetJNIEnv();
+ if (IS_INVALID_HANDLE(_E)) {
+ ACR_SET_OS_ERROR(ACR_ENOJNIENV);
+ return NULL;
+ }
+ skey = ACR_NewJavaStringA(_E, key);
+ if (skey == NULL)
+ return NULL;
+ sval = (jstring)CALL_MLOCAL1(Object, 0001, skey);
+ (*_E)->DeleteLocalRef(_E, skey);
+ if (sval) {
+ val = ACR_GetJavaStringA(_E, sval, NULL);
+ (*_E)->DeleteLocalRef(_E, sval);
+ }
+ return val;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/system.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=814323&r1=814322&r2=814323&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Sun Sep 13 14:47:56 2009
@@ -34,6 +34,7 @@
#include "acr_semaphore.h"
#include "acr_callback.h"
#include "acr_observer.h"
+#include "acr_system.h"
#if defined (WIN32)
#include <io.h>
@@ -1055,3 +1056,20 @@
}
return 0;
}
+
+ACR_JNI_EXPORT_DECLARE(int, TestSystem, test00)(ACR_JNISTDARGS, jint status)
+{
+ return ACR_SystemExit(_E, status);
+}
+
+ACR_JNI_EXPORT_DECLARE(jstring, TestSystem, test01)(ACR_JNISTDARGS, jstring key)
+{
+ jstring val = NULL;
+ WITH_CSTR(key) {
+ char *rv = ACR_SystemGetProperty(_E, J2S(key));
+ if (rv)
+ val = ACR_NewJavaStringA(_E, rv);
+ ACR_Free(_E, THROW_NMARK, rv);
+ } END_WITH_CSTR(key);
+ return val;
+}
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java?rev=814323&r1=814322&r2=814323&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java Sun Sep 13 14:47:56 2009
@@ -49,6 +49,7 @@
suite.addTest(TestMemoryMap.suite());
suite.addTest(TestCallback.suite());
suite.addTest(TestObserver.suite());
+ suite.addTest(TestSystem.suite());
return suite;
}
Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSystem.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSystem.java?rev=814323&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSystem.java (added)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSystem.java Sun Sep 13 14:47:56 2009
@@ -0,0 +1,81 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import org.apache.commons.runtime.exception.*;
+import org.apache.commons.runtime.io.Status;
+import junit.framework.*;
+import java.security.Permission;
+
+/**
+ * System tests
+ */
+public class TestSystem extends TestCase
+{
+
+ private static native int test00(int s);
+ private static native String test01(String k);
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TestSystem.class);
+ return suite;
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ System.loadLibrary("acr");
+ }
+
+ class MySecurityManager extends SecurityManager {
+ @Override
+ public void checkPermission(Permission perm)
+ {
+ // Allow everyting
+ }
+ @Override
+ public void checkExit(int status)
+ {
+ // Don't allow System.exit
+ throw new SecurityException();
+ }
+ }
+ public void testSystemGetProperty()
+ throws Exception
+ {
+ String val;
+
+ val = test01("java.vendor");
+ assertEquals("Call result", System.getProperty("java.vendor"), val);
+ }
+
+ public void testSystemExit()
+ throws Exception
+ {
+ int rc = 0;
+ System.setSecurityManager(new MySecurityManager());
+ rc = test00(11);
+ /* Result is EACCES cause out tmp security manager
+ * throws the exception
+ */
+ assertEquals("Call result", Status.EACCES, rc);
+ System.setSecurityManager(null);
+ }
+
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSystem.java
------------------------------------------------------------------------------
svn:eol-style = native