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 2011/04/28 06:31:30 UTC

svn commit: r1097316 - 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/ native/include/acr/ native/os/unix/ native/shar...

Author: mturk
Date: Thu Apr 28 04:31:29 2011
New Revision: 1097316

URL: http://svn.apache.org/viewvc?rev=1097316&view=rev
Log:
Implement posix exec

Added:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/baos.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/baos.c   (with props)
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemoryImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/MutexImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.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/WindowsExecImpl.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java Thu Apr 28 04:31:29 2011
@@ -15,6 +15,11 @@
  */
 package org.apache.commons.runtime;
 
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.File;
+import java.util.List;
+
 /**
  * Exec class.
  * <p>
@@ -33,19 +38,96 @@ public abstract class Exec
     private static final  ExecImpl impl;
 
     static {
-        impl = ExecImpl.get();
+        impl = ExecImpl.getInstance();
     }
 
-    protected String  name;
-    protected boolean owner;
+    protected byte[]                    inp = null;
+    protected ByteArrayOutputStream     err = null;
+    protected ByteArrayOutputStream     out = null;
+
+    protected String                    cwd = null;
+    protected String[]                  env = null;
 
-    public static Exec create()
+    public static Exec newInstance()
         throws OperationNotImplementedException,
                SystemException
     {
         if (impl == null)
             throw new OperationNotImplementedException();
-        return impl.create();
+        return impl.newInstance();
+    }
+
+    public abstract int run(List<String> args);
+
+    public void setInput(byte[] buf)
+    {
+        inp = buf;
+    }
+
+    public void setErrorStream(ByteArrayOutputStream stream)
+    {
+        err = stream;
+    }
+
+    public void setOutputStream(ByteArrayOutputStream stream)
+    {
+        out = stream;
+    }
+
+    public void setWorkingDirectory(File directory)
+    {
+        cwd = directory.getPath();
+    }
+
+    public void setEnvironment(List<String> envp)
+    {
+        env = envp.toArray(new String[0]);
+    }
+    
+    public OutputStream getOutputStream()
+    {
+        return out;
+    }
+    
+    public OutputStream getErrorStream()
+    {
+        return err;
+    }
+
+    public boolean redirectOutputStream()
+    {
+        return out != null;
+    }
+    
+    public boolean redirectErrorStream()
+    {
+        if (err == null || err == out)
+            return false;
+        else
+            return true;
+    }
+
+    public Exec redirectOutputStream(boolean redirect)
+    {
+        if (redirect) {
+            if (out == null)
+                out = new ByteArrayOutputStream();
+        }
+        else {
+            out = null;
+        }
+        return this;
     }
 
+    public Exec redirectErrorStream(boolean redirect)
+    {
+        if (redirect) {
+            if (err == null || err == out)
+                err = new ByteArrayOutputStream();
+        }
+        else {
+            err = null;
+        }
+        return this;
+    }
 }

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=1097316&r1=1097315&r2=1097316&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 04:31:29 2011
@@ -37,7 +37,7 @@ public abstract class ExecImpl
         // No Instance
     }
 
-    public static final ExecImpl get()
+    public static final ExecImpl getInstance()
         throws OperationNotImplementedException
     {
         if (impl == null)
@@ -45,7 +45,7 @@ public abstract class ExecImpl
         return impl;
     }
 
-    public abstract Exec create();
+    public abstract Exec newInstance();
 
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemory.java Thu Apr 28 04:31:29 2011
@@ -27,7 +27,7 @@ public final class ExecutableMemory
     private static final ExecutableMemoryImpl impl;
 
     static {
-        impl = ExecutableMemoryImpl.get();
+        impl = ExecutableMemoryImpl.getInstance();
     }
 
     private ExecutableMemory()

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemoryImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemoryImpl.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemoryImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecutableMemoryImpl.java Thu Apr 28 04:31:29 2011
@@ -37,7 +37,7 @@ public abstract class ExecutableMemoryIm
         // No Instance
     }
 
-    public static final ExecutableMemoryImpl get()
+    public static final ExecutableMemoryImpl getInstance()
         throws OperationNotImplementedException
     {
         if (impl == null)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java Thu Apr 28 04:31:29 2011
@@ -33,17 +33,12 @@ public abstract class Mutex
     private static final  MutexImpl impl;
 
     static {
-        impl = MutexImpl.get();
+        impl = MutexImpl.getInstance();
     }
 
     protected String  name;
     protected boolean owner;
 
-    public static final MutexImpl getImpl()
-    {
-        return impl;
-    }
-
     public static Mutex create(MutexType type, String name)
         throws AccessDeniedException,
                InvalidArgumentException,

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/MutexImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/MutexImpl.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/MutexImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/MutexImpl.java Thu Apr 28 04:31:29 2011
@@ -38,7 +38,7 @@ public abstract class MutexImpl
         // No Instance
     }
 
-    public static final MutexImpl get()
+    public static final MutexImpl getInstance()
     {
         return impl;
     }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OsType.java Thu Apr 28 04:31:29 2011
@@ -122,4 +122,5 @@ public enum OsType
         }
         return set;
     }
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java Thu Apr 28 04:31:29 2011
@@ -33,7 +33,7 @@ public abstract class Semaphore
     private static final  SemaphoreImpl impl;
 
     static {
-        impl = SemaphoreImpl.get();
+        impl = SemaphoreImpl.getInstance();
     }
 
     protected String  name;

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java Thu Apr 28 04:31:29 2011
@@ -37,7 +37,7 @@ public abstract class SemaphoreImpl
         // No Instance
     }
 
-    public static final SemaphoreImpl get()
+    public static final SemaphoreImpl getInstance()
         throws OperationNotImplementedException
     {
         if (impl == null)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java Thu Apr 28 04:31:29 2011
@@ -35,7 +35,7 @@ public abstract class Shm implements Syn
     private static final  ShmImpl impl;
 
     static {
-        impl = ShmImpl.get();
+        impl = ShmImpl.getInstance();
     }
 
     protected String  name;

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java Thu Apr 28 04:31:29 2011
@@ -37,7 +37,7 @@ public abstract class ShmImpl
         // No Instance
     }
 
-    public static final ShmImpl get()
+    public static final ShmImpl getInstance()
         throws UnsupportedOperationException
     {
         if (impl == null)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java Thu Apr 28 04:31:29 2011
@@ -124,6 +124,11 @@ public final class Status
     public static final int ENOTIMPL                = OS_START_STATUS + 23;
     public static final int EMISMATCH               = OS_START_STATUS + 24;
 
+    public static final int CHILD_SIGNAL            = OS_START_STATUS + 50;
+    public static final int CHILD_SIGNAL_CORE       = OS_START_STATUS + 51;
+    public static final int CHILD_ERROR             = OS_START_STATUS + 52;
+    public static final int PARENT_ERROR            = OS_START_STATUS + 53;
+    
     public static boolean IS_STATUS(int s)
     {
         return ((s > OS_START_STATUS) && (s < OS_START_STATUS + OS_ERRSPACE_SIZE));

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=1097316&r1=1097315&r2=1097316&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 04:31:29 2011
@@ -20,6 +20,9 @@ import org.apache.commons.runtime.Errno;
 import org.apache.commons.runtime.Status;
 import org.apache.commons.runtime.InvalidArgumentException;
 import org.apache.commons.runtime.SystemException;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.List;
 
 /**
  * PosixExec class.
@@ -36,4 +39,19 @@ final class PosixExec extends Exec
 
     }
 
+    private static native long run0(String executable,
+                                    String[] args,
+                                    String[] envp,
+                                    String cwd,
+                                    byte[] inp,
+                                    ByteArrayOutputStream out,
+                                    ByteArrayOutputStream err,
+                                    int timeout);
+    public int run(List<String> args)
+    {
+        String[] argv = args.toArray(new String[0]);
+        long retval = run0(argv[0], argv, env, cwd, inp, out, err, -1);
+
+        return (int)(retval >>> 32);
+    }
 }

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=1097316&r1=1097315&r2=1097316&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 04:31:29 2011
@@ -33,7 +33,8 @@ final class PosixExecImpl extends ExecIm
         // No Instance
     }
 
-    public Exec create()
+    @Override
+    public Exec newInstance()
     {
         return new PosixExec();
     }

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=1097316&r1=1097315&r2=1097316&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 04:31:29 2011
@@ -33,7 +33,7 @@ final class WindowsExecImpl extends Exec
         // No Instance
     }
 
-    public Exec create()
+    public Exec newInstance()
     {
         return new WindowsExec();
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Thu Apr 28 04:31:29 2011
@@ -96,6 +96,7 @@ LIBSOURCES=\
 	$(TOPDIR)/port/bsdstring.c \
 	$(TOPDIR)/port/bsdsys.c \
 	$(TOPDIR)/shared/array.c \
+	$(TOPDIR)/shared/baos.c \
 	$(TOPDIR)/shared/bzip2.c \
 	$(TOPDIR)/shared/callback.c \
 	$(TOPDIR)/shared/clazz.c \

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/baos.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/baos.h?rev=1097316&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/baos.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/baos.h Thu Apr 28 04:31:29 2011
@@ -0,0 +1,38 @@
+/* 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_BAOS_H
+#define _ACR_BAOS_H
+
+#include "acr/jnitypes.h"
+#include "acr/error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ACR_CLASS_CTOR(OutputStream);
+ACR_CLASS_DTOR(OutputStream);
+
+int
+AcrWriteToOutputStream(JNI_STDARGS, const char *data, int len);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_BAOS_H */

Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/baos.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h Thu Apr 28 04:31:29 2011
@@ -35,7 +35,7 @@
 /** @return acr_time_t msec portion of a time */
 #define AcrTimeMsec(time)       (((time) / 1000) % 1000)
 /** @return milliseconds as an acr_time_t */
-#define AcrTimefromMsec(msec)   ((acr_time_t)(msec) * 1000)
+#define AcrTimeFromMsec(msec)   ((acr_time_t)(msec) * 1000)
 /** @return seconds as an acr_time_t */
 #define AcrTimeFromSec(sec)     ((acr_time_t)(sec) * ACR_USEC_PER_SEC)
 /** @return a second and usec combination as an acr_time_t */

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=1097316&r1=1097315&r2=1097316&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 04:31:29 2011
@@ -16,10 +16,11 @@
 
 #include "acr/error.h"
 #include "acr/clazz.h"
-#include "acr/memory.h"
+#include "acr/baos.h"
 #include "acr/iodefs.h"
 #include "acr/port.h"
 #include "acr/sbuf.h"
+#include "acr/string.h"
 #include "acr/time.h"
 #include "arch_opts.h"
 #include <poll.h>
@@ -44,31 +45,6 @@
 #define PIPE_SIGPID_WRS     9
 #define PIPE_COUNT         10
 
-typedef struct acr_limit_t {
-    /** Process timeout in miliseconds
-     */
-    int             timeout;
-    struct rlimit  *cpu;
-    struct rlimit  *mem;
-    struct rlimit  *nproc;
-    struct rlimit  *nfile;
-} acr_limit_t;
-
-typedef struct acr_proc_t {
-    /** Process timeout in miliseconds
-     */
-    acr_limit_t     limit;
-    pid_t           pid;
-    int             flags;
-    int             exitwhy;
-    int             exitval;
-    uid_t           uid;
-    gid_t           gid;
-    mode_t          mask;
-    acr_buf_t       out;
-    acr_buf_t       err;
-} acr_proc_t;
-
 J_DECLARE_CLAZZ = {
     INVALID_FIELD_OFFSET,
     0,
@@ -83,43 +59,6 @@ J_DECLARE_M_ID(0000) = {
     "()V"
 };
 
-static int _setplimit(acr_limit_t *limit)
-{
-    if (limit == 0)
-        return 0;
-#if HAVE_SETRLIMIT
-#ifdef RLIMIT_CPU
-    if (limit->cpu != 0 &&
-        setrlimit(RLIMIT_CPU, limit->cpu) != 0)
-            return errno;
-#endif
-#ifdef RLIMIT_NPROC
-    if (limit->nproc != 0 &&
-        setrlimit(RLIMIT_NPROC, limit->nproc) != 0)
-        return errno;
-#endif
-#ifdef RLIMIT_NOFILE
-    if (limit->nfile != 0 &&
-        setrlimit(RLIMIT_NOFILE,limit->nfile) != 0)
-        return errno;
-#endif
-#if defined(RLIMIT_AS)
-    if (limit->mem != 0 &&
-        setrlimit(RLIMIT_AS, limit->mem) != 0)
-        return errno;
-#elif defined(RLIMIT_DATA)
-    if (limit->mem != 0 &&
-        setrlimit(RLIMIT_DATA, limit->mem) != 0)
-        return errno;
-#elif defined(RLIMIT_VMEM)
-    if (limit->mem != 0 &&
-        setrlimit(RLIMIT_VMEM, limit->mem) != 0)
-        return errno;
-#endif
-#endif
-    return 0;
-}
-
 static int _fdwalker(void *data , int fd)
 {
     int  i;
@@ -149,7 +88,7 @@ static int _run_exec(const char *executa
                      acr_buf_t *out,
                      acr_buf_t *err,
                      acr_buf_t *inp,
-                     acr_limit_t *limit,
+                     int timeout,
                      int *retval)
 {
     int   i, rc   = 0;
@@ -171,7 +110,7 @@ static int _run_exec(const char *executa
      * Ignore SIGPIPE
      */
     AcrSigIgnore(SIGPIPE);
-    if (limit != 0 && limit->timeout == 0)
+    if (timeout == 0)
         detach = 1;
     /* Create signaling pipe that is used both for reporting the
      * failed exec and syncing with exec.
@@ -296,9 +235,6 @@ static int _run_exec(const char *executa
          * using fdwalk
          */
         AcrFdwalk(_fdwalker, pipes);
-
-        if ((rc = _setplimit(limit)) != 0)
-            goto child_cleanup;
         if (detach) {
             /* Time to do detach the process.
              */
@@ -381,12 +317,11 @@ child_cleanup:
         i_close(&pipes[PIPE_STDERR_WRS]);
         i_close(&pipes[PIPE_SIGERR_WRS]);
         i_close(&pipes[PIPE_SIGPID_WRS]);
-/*
-        if (limit != 0 && limit->timeout > 0) {
-            endat = AcrTimeNow() + AcrTimeFromMsec(limit->timeout);
+
+        if (timeout > 0) {
+            endat = AcrTimeNow() + AcrTimeFromMsec(timeout);
             polltime = PROC_TIMEOUT_STEP;
         }
-*/
         if (pipes[PIPE_STDINP_WRS] == -1 &&
             pipes[PIPE_STDOUT_RDS] == -1 &&
             pipes[PIPE_STDERR_RDS] == -1)
@@ -648,3 +583,69 @@ ACR_JNI_EXPORT(jobject, ExecImpl, init0)
     return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
 }
 
+ACR_UNX_EXPORT(jlong, PosixExec, run0)(JNI_STDARGS, jstring executable,
+                                       jobjectArray args, jobjectArray envp,
+                                       jstring cwd, jbyteArray inp,
+                                       jobject out, jobject err,
+                                       jint timeout)
+{
+    int rv = 0;
+    int rc = 0;
+    acr_buf_t bb[3];
+    acr_buf_t *ib = 0;
+    acr_buf_t *ob = 0;
+    acr_buf_t *eb = 0;
+    
+    WITH_CSTR(executable) {
+    WITH_CSTR(cwd) {
+        char **argp;
+        char **envs;
+
+        argp = AcrGetJavaStringArrayA(env, args);
+        envs = AcrGetJavaStringArrayA(env, envp);
+        if (inp != 0) {
+            ib = &bb[0];
+            ib->len = (*env)->GetArrayLength(env, inp);
+            ib->buf = (*env)->GetPrimitiveArrayCritical(env, inp, 0);
+        }
+        if (out != 0)
+            ob = &bb[1];
+        if (err != 0 && err != out)
+            eb = &bb[2];
+        /* Call actual execute
+         */
+        rv = _run_exec(J2S(executable), argp, envs, J2S(cwd),
+                       ob, eb, ib, timeout, &rc);
+        if (ib != 0 && inp != 0)
+            (*env)->ReleasePrimitiveArrayCritical(env, inp, ib->buf, 0);
+        if (rv != ACR_PARENT_ERROR) {
+            if (out != 0) {
+                /* Write to the output stream */
+                int r = AcrWriteToOutputStream(env, out, ob->buf, ob->len);
+                if (r != 0) {
+                    rv = r;
+                    goto cleanup;
+                }
+            }
+            if (err != 0 && err != out) {
+                /* Write to the error stream */
+                int r = AcrWriteToOutputStream(env, err, eb->buf, eb->len);
+                if (r != 0) {
+                    rv = r;
+                    goto cleanup;
+                }
+            }
+        }
+
+cleanup:
+        if (ob != 0)
+            AcrFree(ob->buf);
+        if (eb != 0)
+            AcrFree(ob->buf);
+        AcrFreeStringArray((void **)envs);
+        AcrFreeStringArray((void **)argp);
+    } DONE_WITH_STR(cwd);
+    } DONE_WITH_STR(executable);
+
+    return ((jlong)rv << 32) | ((jlong)rc & ACR_I64_C(0xFFFFFFFF));
+}

Added: commons/sandbox/runtime/trunk/src/main/native/shared/baos.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/baos.c?rev=1097316&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/baos.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/baos.c Thu Apr 28 04:31:29 2011
@@ -0,0 +1,75 @@
+/* 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.
+ */
+
+#include "acr/clazz.h"
+#include "acr/baos.h"
+#include "acr/string.h"
+
+J_DECLARE_CLAZZ = {
+    INVALID_FIELD_BASE,
+    0,
+    0,
+    0,
+    "java/io/OutputStream"
+};
+
+J_DECLARE_M_ID(0000) = {
+    0,
+    "write",
+    "([B)V"
+};
+
+ACR_CLASS_CTOR(OutputStream)
+{
+    int rv;
+
+    if ((rv = AcrLoadClass(env, &_clazzn, 0)) != ACR_SUCCESS)
+        return rv;
+    J_LOAD_METHOD(0000);
+
+    _clazzn.u = 1;
+    return 0;
+}
+
+ACR_CLASS_DTOR(OutputStream)
+{
+    AcrUnloadClass(env, &_clazzn);
+}
+
+int
+AcrWriteToOutputStream(JNI_STDARGS, const char *data, int len)
+{
+    int rc = ACR_ENOENT;
+
+    if (data == 0 || len < 1)
+        return 0;
+    if (IS_JOBJECT_NULL(env, obj))
+        return ACR_EINVAL;
+    if (CLAZZ_LOADED) {
+        jbyteArray ba = (*env)->NewByteArray(env, len);
+        if (ba == 0)
+            return ACR_ENOMEM;
+        (*env)->SetByteArrayRegion(env, ba, 0, len, (jbyte *)data);
+        CALL_VMETHOD1(0000, obj, ba);
+        if ((*env)->ExceptionCheck(env)) {
+            (*env)->ExceptionClear(env);
+            rc = ACR_ENOMEM;
+        }
+        else
+            rc = 0;
+    }
+    return rc;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/baos.c
------------------------------------------------------------------------------
    svn:eol-style = native

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=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Thu Apr 28 04:31:29 2011
@@ -17,6 +17,7 @@
 #include "acr/clazz.h"
 #include "acr/misc.h"
 /* Runtime class includes */
+#include "acr/baos.h"
 #include "acr/object.h"
 #include "acr/unsafe.h"
 #include "acr/string.h"
@@ -213,6 +214,7 @@ AcrInitCoreClasses(JNI_STDENV)
     ACR_CLASS_LOAD(String);
     ACR_CLASS_LOAD(System);
     ACR_CLASS_LOAD(Observer);
+    ACR_CLASS_LOAD(OutputStream);
     return 0;
 }
 
@@ -242,6 +244,7 @@ AcrUnloadRuntimeClasses(JNI_STDENV)
     ACR_CLASS_UNLOAD(FileDescriptor);
     ACR_CLASS_UNLOAD(Callback);
     ACR_CLASS_UNLOAD(Unsafe);
+    ACR_CLASS_UNLOAD(OutputStream);
     ACR_CLASS_UNLOAD(Observer);
     ACR_CLASS_UNLOAD(System);
     ACR_CLASS_UNLOAD(String);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1097316&r1=1097315&r2=1097316&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Thu Apr 28 04:31:29 2011
@@ -1110,7 +1110,7 @@ AcrGetJavaStringArrayW(JNI_STDENV, jobje
         return 0;
     for (i = 0; i < cnt; i++) {
         jstring str = (*env)->GetObjectArrayElement(env, arr, i);
-        if (str) {
+        if (str != 0) {
             ret[i] = AcrGetJavaStringW(env, str, 0);
             (*env)->DeleteLocalRef(env, str);
         }

Added: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java?rev=1097316&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java (added)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java Thu Apr 28 04:31:29 2011
@@ -0,0 +1,66 @@
+/* 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.testng.annotations.*;
+import org.testng.Assert;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.util.ArrayList;
+
+public class TestExec extends Assert
+{
+
+
+    @Test(groups = { "core" })
+    public void runPosix()
+        throws Exception
+    {
+        Exec e = Exec.newInstance();
+        assertNotNull(e);
+        ArrayList<String> args = new ArrayList<String>();
+        if (Os.TYPE.contains(OsType.UNIX)) {
+            args.add("/bin/ls");
+            args.add("-al");
+        }
+        else {
+
+        }
+        e.redirectOutputStream(true);
+        int r = e.run(args);
+        assertEquals(r, Status.CHILD_DONE);
+        ByteArrayOutputStream os = (ByteArrayOutputStream)e.getOutputStream();
+        System.out.println("Exec returned " + new String(os.toByteArray()));
+        
+    }
+
+    @Test(groups = { "core" })
+    public void runError()
+        throws Exception
+    {
+        Exec e = Exec.newInstance();
+        assertNotNull(e);
+        ArrayList<String> args = new ArrayList<String>();
+        args.add("/foo/bar/errorpath");
+        int r = e.run(args);
+        assertEquals(r, Status.CHILD_ERROR);
+    }
+
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java
------------------------------------------------------------------------------
    svn:eol-style = native