commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1097546 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ java/org/apache/commons/runtime/platform/unix/ java/org/apache/commons/runtime/platform/windows/ native/os/unix/ native/os/win32/
Date Thu, 28 Apr 2011 16:56:09 GMT
Author: mturk
Date: Thu Apr 28 16:56:09 2011
New Revision: 1097546

URL: http://svn.apache.org/viewvc?rev=1097546&view=rev
Log:
Init system shell with exec implementation

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java?rev=1097546&r1=1097545&r2=1097546&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java Thu
Apr 28 16:56:09 2011
@@ -32,6 +32,7 @@ public abstract class ExecImpl
         impl = init0();
     }
 
+    protected String shell;
     protected ExecImpl()
     {
         // No Instance
@@ -47,5 +48,9 @@ public abstract class ExecImpl
 
     public abstract Exec newInstance();
 
+    public final String getShell()
+    {
+        return shell;
+    }
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java?rev=1097546&r1=1097545&r2=1097546&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
Thu Apr 28 16:56:09 2011
@@ -47,6 +47,7 @@ final class PosixExec extends Exec
                                     ByteArrayOutputStream out,
                                     ByteArrayOutputStream err,
                                     int timeout);
+    @Override
     public int run(List<String> args)
     {
         String[] argv = args.toArray(new String[0]);

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java?rev=1097546&r1=1097545&r2=1097546&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java
Thu Apr 28 16:56:09 2011
@@ -28,11 +28,16 @@ import org.apache.commons.runtime.ExecIm
 final class PosixExecImpl extends ExecImpl
 {
 
-    public PosixExecImpl()
+    private PosixExecImpl()
     {
         // No Instance
     }
 
+    public PosixExecImpl(String shell)
+    {
+        this.shell = shell;
+    }
+
     @Override
     public Exec newInstance()
     {

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java?rev=1097546&r1=1097545&r2=1097546&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java
Thu Apr 28 16:56:09 2011
@@ -47,6 +47,7 @@ final class WindowsExec extends Exec
                                     ByteArrayOutputStream out,
                                     ByteArrayOutputStream err,
                                     int timeout);
+    @Override
     public int run(List<String> argv)
     {
         String executable = null;

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java?rev=1097546&r1=1097545&r2=1097546&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java
Thu Apr 28 16:56:09 2011
@@ -28,11 +28,16 @@ import org.apache.commons.runtime.ExecIm
 final class WindowsExecImpl extends ExecImpl
 {
 
-    public WindowsExecImpl()
+    private WindowsExecImpl()
     {
         // No Instance
     }
 
+    public WindowsExecImpl(String shell)
+    {
+        this.shell = shell;
+    }
+
     public Exec newInstance()
     {
         return new WindowsExec();

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c?rev=1097546&r1=1097545&r2=1097546&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c Thu Apr 28 16:56:09 2011
@@ -56,7 +56,7 @@ J_DECLARE_CLAZZ = {
 J_DECLARE_M_ID(0000) = {
     0,
     "<init>",
-    "()V"
+    "(Ljava/lang/String;)V"
 };
 
 static int _fdwalker(void *data , int fd)
@@ -584,7 +584,7 @@ ACR_JNI_EXPORT(jobject, ExecImpl, init0)
         return 0;
     R_LOAD_METHOD(0000, 0);
     _clazzn.u = 1;
-    return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
+    return (*env)->NewObject(env, _clazzn.i, J4MID(0000), AcrNewJavaStringW(env, SHELL_PATH));
 }
 
 ACR_UNX_EXPORT(jlong, PosixExec, run0)(JNI_STDARGS, jstring executable,

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c?rev=1097546&r1=1097545&r2=1097546&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c Thu Apr 28 16:56:09 2011
@@ -37,7 +37,6 @@
 #define SIGKILL             9
 
 static CRITICAL_SECTION _procmgr_lock;
-static wchar_t         *SHELL_PATH;
 
 J_DECLARE_CLAZZ = {
     INVALID_FIELD_OFFSET,
@@ -50,25 +49,26 @@ J_DECLARE_CLAZZ = {
 J_DECLARE_M_ID(0000) = {
     0,
     "<init>",
-    "()V"
+    "(Ljava/lang/String;)V"
 };
 
-static int _procmgr_init(void)
+static jstring _procmgr_init(JNI_STDENV)
 {
+    wchar_t  b[PATH_MAX];
+    wchar_t *shell;
     InitializeCriticalSection(&_procmgr_lock);
 
-    SHELL_PATH = _wgetenv(L"COMSPEC");
-    if (SHELL_PATH == 0) {
-        wchar_t b[PATH_MAX];
+    shell = _wgetenv(L"COMSPEC");
+    if (shell == 0) {
         UINT r;
         r = GetSystemDirectoryW(b, PATH_MAX - 10);
         if (r == 0 || r > (PATH_MAX - 10))
             wcscpy(b, L"C:\\Windows\\System32\\cmd.exe");
         else
             wcscat(b, L"\\cmd.exe");
-        SHELL_PATH = wcsdup(b);
+        shell = b;
     }
-    return 0;
+    return AcrNewJavaStringW(env, shell);
 }
 
 static int _run_exec(const wchar_t *executable,
@@ -85,7 +85,7 @@ static int _run_exec(const wchar_t *exec
     STARTUPINFOW        si;
     BOOL   rs;
     int    i, rc   = 0;
-    int    exitwhy = 0;
+    int    exitwhy = ACR_PARENT_ERROR;
     int    exitval = 0;
     HANDLE pipes[PIPE_COUNT] = { 0, 0, 0, 0, 0, 0 };
     HANDLE waithandle[3]     = { 0, 0, 0 };
@@ -511,19 +511,22 @@ cleanup:
         SAFE_CLOSE_HANDLE(overlap[i].o.hEvent);
     }
     *retval = rc;
-    return ACR_PARENT_ERROR;
+    if (ACR_STATUS_IS_ENOENT(rc))
+        exitwhy = ACR_CHILD_ERROR;
+    return exitwhy;
 }
 
 ACR_JNI_EXPORT(jobject, ExecImpl, init0)(JNI_STDARGS)
 {
+    jstring shell;
     if (_clazzn.u == 1)
         return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
     if (AcrLoadClass(env, &_clazzn, 0) != 0)
         return 0;
     R_LOAD_METHOD(0000, 0);
     _clazzn.u = 1;
-    _procmgr_init();
-    return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
+    shell = _procmgr_init(env);
+    return (*env)->NewObject(env, _clazzn.i, J4MID(0000), shell);
 }
 
 ACR_WIN_EXPORT(jlong, WindowsExec, run0)(JNI_STDARGS, jstring executable,



Mime
View raw message