commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1097422 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ java/org/apache/commons/runtime/platform/unix/ native/os/linux/ native/os/solaris/ native/os/unix/ test/org/apache/commons/runtime/
Date Thu, 28 Apr 2011 11:35:01 GMT
Author: mturk
Date: Thu Apr 28 11:35:01 2011
New Revision: 1097422

URL: http://svn.apache.org/viewvc?rev=1097422&view=rev
Log:
Implement Vm.self

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/Vm.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
    commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java

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=1097422&r1=1097421&r2=1097422&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 11:35:01 2011
@@ -47,6 +47,8 @@ public abstract class Exec
 
     protected String                    cwd = null;
     protected String[]                  env = null;
+    protected int                       exitval;
+    protected int                       timeout = -1;
 
     public static Exec newInstance()
         throws OperationNotImplementedException,
@@ -59,6 +61,11 @@ public abstract class Exec
 
     public abstract int run(List<String> args);
 
+    public int exitval()
+    {
+        return exitval;
+    }
+
     public void setInput(byte[] buf)
     {
         inp = buf;

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java?rev=1097422&r1=1097421&r2=1097422&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Vm.java Thu Apr
28 11:35:01 2011
@@ -38,4 +38,6 @@ public final class Vm
      * Returns the process ID of the parent of the current VM.
      */
     public static native int getParentPid();
+
+    public static native String self();
 }

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=1097422&r1=1097421&r2=1097422&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 11:35:01 2011
@@ -50,8 +50,10 @@ final class PosixExec extends Exec
     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);
+        long rv = run0(argv[0], argv, env, cwd, inp, out, err, timeout);
+        exitval = (int)(rv & 0xffffffffL);
+        int res = (int)(rv >>> 32);
 
-        return (int)(retval >>> 32);
+        return res;
     }
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c?rev=1097422&r1=1097421&r2=1097422&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/os.c Thu Apr 28 11:35:01 2011
@@ -82,3 +82,17 @@ ACR_JNI_EXPORT(jstring, Os, getVersion)(
     else
         return CSTR_TO_JSTRING(_unknown);
 }
+
+ACR_JNI_EXPORT(jstring, Vm, self)(JNI_STDARGS)
+{
+    char buf[PATH_MAX];
+    ssize_t sz;
+    
+    if ((sz = readlink("/proc/self/exe", buf, sizeof(buf) - 1)) == -1) {
+        return 0;
+    }
+    else {
+        buf[sz] = '\0';
+        return CSTR_TO_JSTRING(buf);
+    }
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c?rev=1097422&r1=1097421&r2=1097422&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/solaris/os.c Thu Apr 28 11:35:01 2011
@@ -87,3 +87,21 @@ ACR_JNI_EXPORT(jstring, Os, getVersion)(
      else
         return CSTR_TO_JSTRING(buf);
 }
+
+ACR_JNI_EXPORT(jstring, Vm, self)(JNI_STDARGS)
+{
+    char buf[PATH_MAX];
+    const char *en;
+    ssize_t sz;
+
+    en = getexecname();
+    if (en != 0 && *en == '/')
+        return CSTR_TO_JSTRING(en);
+    /* Fallback to reading a.out link */
+    if ((sz = readlink("/proc/self/path/a.out", buf, sizeof(buf) - 1)) == -1)
+        return 0;
+    else {
+        buf[sz] = '\0';
+        return CSTR_TO_JSTRING(buf);
+    }
+}

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=1097422&r1=1097421&r2=1097422&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 11:35:01 2011
@@ -546,14 +546,18 @@ child_cleanup:
 finished:
     AcrSigDefault(SIGPIPE);
     if (obuf != 0) {
+#if 0
         AcrSbPutb(obuf, 0);
         AcrSbPutb(obuf, 0);
+#endif
         out->len = AcrSbLen(obuf);
         out->buf = AcrSbDetach(obuf);
     }
     if (ebuf != 0) {
+#if 0
         AcrSbPutb(ebuf, 0);
         AcrSbPutb(ebuf, 0);
+#endif
         err->len = AcrSbLen(ebuf);
         err->buf = AcrSbDetach(ebuf);
     }
@@ -641,7 +645,7 @@ cleanup:
         if (ob != 0)
             AcrFree(ob->buf);
         if (eb != 0)
-            AcrFree(ob->buf);
+            AcrFree(eb->buf);
         AcrFreeStringArray((void **)envs);
         AcrFreeStringArray((void **)argp);
     } DONE_WITH_STR(cwd);

Modified: 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=1097422&r1=1097421&r2=1097422&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java Thu
Apr 28 11:35:01 2011
@@ -43,11 +43,12 @@ public class TestExec extends Assert
 
         }
         e.redirectOutputStream(true);
+        e.redirectErrorStream(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()));
-        
+        System.out.println("Exec returned:");
+        System.out.println(new String(os.toByteArray()));        
     }
 
     @Test(groups = { "core" })
@@ -62,5 +63,22 @@ public class TestExec extends Assert
         assertEquals(r, Status.CHILD_ERROR);
     }
 
+    @Test(groups = { "core" })
+    public void runJavaVersion()
+        throws Exception
+    {
+        Exec e = Exec.newInstance();
+        assertNotNull(e);
+        ArrayList<String> args = new ArrayList<String>();
+        args.add(Vm.self());
+        args.add("-version");
+        e.redirectOutputStream(true);
+        int r = e.run(args);
+        assertEquals(r, Status.CHILD_DONE);
+        ByteArrayOutputStream os = (ByteArrayOutputStream)e.getOutputStream();
+        System.out.println("Running java -version returned:");
+        System.out.println(new String(os.toByteArray()));
+    }
+
 
 }



Mime
View raw message