summaryrefslogtreecommitdiffstats
path: root/dalvik
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2013-02-05 13:02:13 -0800
committerNick Kralevich <nnk@google.com>2013-02-05 15:55:24 -0800
commit798f855f67b74d481346d9dc2293ba0eedd8daf9 (patch)
tree5f5a88a6e098ca850511c2da49869fdb5823d607 /dalvik
parent4ae5e1769028ccde259e6108e3fb1903faa644e8 (diff)
downloadlibcore-798f855f67b74d481346d9dc2293ba0eedd8daf9.zip
libcore-798f855f67b74d481346d9dc2293ba0eedd8daf9.tar.gz
libcore-798f855f67b74d481346d9dc2293ba0eedd8daf9.tar.bz2
Add support for Libcore.os.exec*()
Add Libcore support for execv() and execve(). This allows java programs to execute other programs without having to write jni wrappers. Change-Id: I82ddc069b5812ebd40f06b7f65ce173d496e0597
Diffstat (limited to 'dalvik')
-rw-r--r--dalvik/src/main/java/dalvik/system/Zygote.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/dalvik/src/main/java/dalvik/system/Zygote.java b/dalvik/src/main/java/dalvik/system/Zygote.java
index c06314e..9e96204 100644
--- a/dalvik/src/main/java/dalvik/system/Zygote.java
+++ b/dalvik/src/main/java/dalvik/system/Zygote.java
@@ -16,6 +16,9 @@
package dalvik.system;
+import libcore.io.ErrnoException;
+import libcore.io.Libcore;
+
import java.io.File;
/**
@@ -172,12 +175,18 @@ public class Zygote {
/**
* Executes "/system/bin/sh -c &lt;command&gt;" using the exec() system call.
- * This method never returns.
+ * This method throws a runtime exception if exec() failed, otherwise, this
+ * method never returns.
*
* @param command The shell command to execute.
*/
public static void execShell(String command) {
- nativeExecShell(command);
+ String[] args = { "/system/bin/sh", "-c", command };
+ try {
+ Libcore.os.execv(args[0], args);
+ } catch (ErrnoException e) {
+ throw new RuntimeException(e);
+ }
}
/**
@@ -194,6 +203,4 @@ public class Zygote {
command.append(" '").append(arg.replace("'", "'\\''")).append("'");
}
}
-
- native private static void nativeExecShell(String command);
}