summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2014-12-12 23:18:48 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2014-12-12 23:18:48 +0000
commita101befbef6a07af0746e3dbcd646d2b69a23492 (patch)
tree4ed210c830348b5cb1af1f25f2cf4ba6c1545c8e
parent012de64e2dade079979bfa6cdca323b36901a0e6 (diff)
parent3fe595108f47fffd73cfc2eb48b71a31e5d606d0 (diff)
Merge "Lose some unnecessary JNI from the zygote."
-rw-r--r--core/java/com/android/internal/os/WrapperInit.java3
-rw-r--r--core/java/com/android/internal/os/ZygoteConnection.java7
-rw-r--r--core/java/com/android/internal/os/ZygoteInit.java25
-rw-r--r--core/jni/com_android_internal_os_ZygoteInit.cpp44
4 files changed, 8 insertions, 71 deletions
diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java
index 3301cbeadc9f..af821ba4a13b 100644
--- a/core/java/com/android/internal/os/WrapperInit.java
+++ b/core/java/com/android/internal/os/WrapperInit.java
@@ -62,7 +62,8 @@ public class WrapperInit {
// wrapper that it directly forked).
if (fdNum != 0) {
try {
- FileDescriptor fd = ZygoteInit.createFileDescriptor(fdNum);
+ FileDescriptor fd = new FileDescriptor();
+ fd.setInt$(fdNum);
DataOutputStream os = new DataOutputStream(new FileOutputStream(fd));
os.writeInt(Process.myPid());
os.close();
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 24820bc45d88..2ad132165bf3 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -16,6 +16,8 @@
package com.android.internal.os;
+import static android.system.OsConstants.O_CLOEXEC;
+
import android.net.Credentials;
import android.net.LocalSocket;
import android.os.Process;
@@ -186,10 +188,9 @@ class ZygoteConnection {
}
if (parsedArgs.runtimeInit && parsedArgs.invokeWith != null) {
- FileDescriptor[] pipeFds = Os.pipe();
+ FileDescriptor[] pipeFds = Os.pipe2(O_CLOEXEC);
childPipeFd = pipeFds[1];
serverPipeFd = pipeFds[0];
- ZygoteInit.setCloseOnExec(serverPipeFd, true);
}
/**
@@ -224,8 +225,6 @@ class ZygoteConnection {
parsedArgs.debugFlags, rlimits, parsedArgs.mountExternal, parsedArgs.seInfo,
parsedArgs.niceName, fdsToClose, parsedArgs.instructionSet,
parsedArgs.appDataDir);
- } catch (IOException ex) {
- logAndPrintError(newStderr, "Exception creating pipe", ex);
} catch (ErrnoException ex) {
logAndPrintError(newStderr, "Exception creating pipe", ex);
} catch (IllegalArgumentException ex) {
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 62088fa1be1b..70982e13bb3d 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -165,8 +165,9 @@ public class ZygoteInit {
}
try {
- sServerSocket = new LocalServerSocket(
- createFileDescriptor(fileDesc));
+ FileDescriptor fd = new FileDescriptor();
+ fd.setInt$(fileDesc);
+ sServerSocket = new LocalServerSocket(fd);
} catch (IOException ex) {
throw new RuntimeException(
"Error binding to local socket '" + fileDesc + "'", ex);
@@ -781,16 +782,6 @@ public class ZygoteInit {
FileDescriptor out, FileDescriptor err) throws IOException;
/**
- * Toggles the close-on-exec flag for the specified file descriptor.
- *
- * @param fd non-null; file descriptor
- * @param flag desired close-on-exec flag state
- * @throws IOException
- */
- static native void setCloseOnExec(FileDescriptor fd, boolean flag)
- throws IOException;
-
- /**
* Invokes select() on the provider array of file descriptors (selecting
* for readability only). Array elements of null are ignored.
*
@@ -801,16 +792,6 @@ public class ZygoteInit {
static native int selectReadable(FileDescriptor[] fds) throws IOException;
/**
- * Creates a file descriptor from an int fd.
- *
- * @param fd integer OS file descriptor
- * @return non-null; FileDescriptor instance
- * @throws IOException if fd is invalid
- */
- static native FileDescriptor createFileDescriptor(int fd)
- throws IOException;
-
- /**
* Class not instantiable.
*/
private ZygoteInit() {
diff --git a/core/jni/com_android_internal_os_ZygoteInit.cpp b/core/jni/com_android_internal_os_ZygoteInit.cpp
index 496f569c7f59..a2f3dabd238e 100644
--- a/core/jni/com_android_internal_os_ZygoteInit.cpp
+++ b/core/jni/com_android_internal_os_ZygoteInit.cpp
@@ -125,40 +125,6 @@ static void com_android_internal_os_ZygoteInit_reopenStdio(JNIEnv* env,
} while (err < 0 && errno == EINTR);
}
-static void com_android_internal_os_ZygoteInit_setCloseOnExec (JNIEnv *env,
- jobject clazz, jobject descriptor, jboolean flag)
-{
- int fd;
- int err;
- int fdFlags;
-
- fd = jniGetFDFromFileDescriptor(env, descriptor);
-
- if (env->ExceptionCheck()) {
- return;
- }
-
- fdFlags = fcntl(fd, F_GETFD);
-
- if (fdFlags < 0) {
- jniThrowIOException(env, errno);
- return;
- }
-
- if (flag) {
- fdFlags |= FD_CLOEXEC;
- } else {
- fdFlags &= ~FD_CLOEXEC;
- }
-
- err = fcntl(fd, F_SETFD, fdFlags);
-
- if (err < 0) {
- jniThrowIOException(env, errno);
- return;
- }
-}
-
static jint com_android_internal_os_ZygoteInit_selectReadable (
JNIEnv *env, jobject clazz, jobjectArray fds)
{
@@ -226,12 +192,6 @@ static jint com_android_internal_os_ZygoteInit_selectReadable (
return -1;
}
-static jobject com_android_internal_os_ZygoteInit_createFileDescriptor (
- JNIEnv *env, jobject clazz, jint fd)
-{
- return jniCreateFileDescriptor(env, fd);
-}
-
/*
* JNI registration.
*/
@@ -249,12 +209,8 @@ static JNINativeMethod gMethods[] = {
"(Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;"
"Ljava/io/FileDescriptor;)V",
(void *) com_android_internal_os_ZygoteInit_reopenStdio},
- { "setCloseOnExec", "(Ljava/io/FileDescriptor;Z)V",
- (void *) com_android_internal_os_ZygoteInit_setCloseOnExec},
{ "selectReadable", "([Ljava/io/FileDescriptor;)I",
(void *) com_android_internal_os_ZygoteInit_selectReadable },
- { "createFileDescriptor", "(I)Ljava/io/FileDescriptor;",
- (void *) com_android_internal_os_ZygoteInit_createFileDescriptor }
};
int register_com_android_internal_os_ZygoteInit(JNIEnv* env)
{