Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9e1e0d2 authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Reimplement reopenStdio in Java."

parents 3d00fdf4 dac83f5e
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@
package com.android.internal.os;

import static android.system.OsConstants.O_CLOEXEC;
import static android.system.OsConstants.STDERR_FILENO;
import static android.system.OsConstants.STDIN_FILENO;
import static android.system.OsConstants.STDOUT_FILENO;

import android.net.Credentials;
import android.net.LocalSocket;
@@ -856,14 +859,15 @@ class ZygoteConnection {

        if (descriptors != null) {
            try {
                ZygoteInit.reopenStdio(descriptors[0],
                        descriptors[1], descriptors[2]);
                Os.dup2(descriptors[0], STDIN_FILENO);
                Os.dup2(descriptors[1], STDOUT_FILENO);
                Os.dup2(descriptors[2], STDERR_FILENO);

                for (FileDescriptor fd: descriptors) {
                    IoUtils.closeQuietly(fd);
                }
                newStderr = System.err;
            } catch (IOException ex) {
            } catch (ErrnoException ex) {
                Log.e(TAG, "Error reopening stdio", ex);
            }
        }
+0 −15
Original line number Diff line number Diff line
@@ -766,21 +766,6 @@ public class ZygoteInit {
     */
    static native int getpgid(int pid) throws IOException;

    /**
     * Invokes the syscall dup2() to copy the specified descriptors into
     * stdin, stdout, and stderr. The existing stdio descriptors will be
     * closed and errors during close will be ignored. The specified
     * descriptors will also remain open at their original descriptor numbers,
     * so the caller may want to close the original descriptors.
     *
     * @param in new stdin
     * @param out new stdout
     * @param err new stderr
     * @throws IOException
     */
    static native void reopenStdio(FileDescriptor in,
            FileDescriptor out, FileDescriptor err) throws IOException;

    /**
     * Invokes select() on the provider array of file descriptors (selecting
     * for readability only). Array elements of null are ignored.
+0 −41
Original line number Diff line number Diff line
@@ -88,43 +88,6 @@ static jint com_android_internal_os_ZygoteInit_getpgid(
    return ret;
}

static void com_android_internal_os_ZygoteInit_reopenStdio(JNIEnv* env,
        jobject clazz, jobject in, jobject out, jobject errfd)
{
    int fd;
    int err;

    fd = jniGetFDFromFileDescriptor(env, in);

    if  (env->ExceptionCheck()) {
        return;
    }

    do {
        err = dup2(fd, STDIN_FILENO);
    } while (err < 0 && errno == EINTR);

    fd = jniGetFDFromFileDescriptor(env, out);

    if  (env->ExceptionCheck()) {
        return;
    }

    do {
        err = dup2(fd, STDOUT_FILENO);
    } while (err < 0 && errno == EINTR);

    fd = jniGetFDFromFileDescriptor(env, errfd);

    if  (env->ExceptionCheck()) {
        return;
    }

    do {
        err = dup2(fd, STDERR_FILENO);
    } while (err < 0 && errno == EINTR);
}

static jint com_android_internal_os_ZygoteInit_selectReadable (
        JNIEnv *env, jobject clazz, jobjectArray fds)
{
@@ -205,10 +168,6 @@ static JNINativeMethod gMethods[] = {
      (void *) com_android_internal_os_ZygoteInit_setpgid },
    { "getpgid", "(I)I",
      (void *) com_android_internal_os_ZygoteInit_getpgid },
    { "reopenStdio",
        "(Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;"
        "Ljava/io/FileDescriptor;)V",
            (void *) com_android_internal_os_ZygoteInit_reopenStdio},
    { "selectReadable", "([Ljava/io/FileDescriptor;)I",
        (void *) com_android_internal_os_ZygoteInit_selectReadable },
};