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

Commit d8beca64 authored by Narayan Kamath's avatar Narayan Kamath Committed by Gerrit Code Review
Browse files

Merge "Remove support for --classpath and make --runtime-init the default."

parents e315feea f48029f0
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -614,9 +614,9 @@ public class Process {
        synchronized(Process.class) {
        synchronized(Process.class) {
            ArrayList<String> argsForZygote = new ArrayList<String>();
            ArrayList<String> argsForZygote = new ArrayList<String>();


            // --runtime-init, --setuid=, --setgid=,
            // --runtime-args, --setuid=, --setgid=,
            // and --setgroups= must go first
            // and --setgroups= must go first
            argsForZygote.add("--runtime-init");
            argsForZygote.add("--runtime-args");
            argsForZygote.add("--setuid=" + uid);
            argsForZygote.add("--setuid=" + uid);
            argsForZygote.add("--setgid=" + gid);
            argsForZygote.add("--setgid=" + gid);
            if ((debugFlags & Zygote.DEBUG_ENABLE_JNI_LOGGING) != 0) {
            if ((debugFlags & Zygote.DEBUG_ENABLE_JNI_LOGGING) != 0) {
+18 −75
Original line number Original line Diff line number Diff line
@@ -191,7 +191,7 @@ class ZygoteConnection {
                rlimits = parsedArgs.rlimits.toArray(intArray2d);
                rlimits = parsedArgs.rlimits.toArray(intArray2d);
            }
            }


            if (parsedArgs.runtimeInit && parsedArgs.invokeWith != null) {
            if (parsedArgs.invokeWith != null) {
                FileDescriptor[] pipeFds = Os.pipe2(O_CLOEXEC);
                FileDescriptor[] pipeFds = Os.pipe2(O_CLOEXEC);
                childPipeFd = pipeFds[1];
                childPipeFd = pipeFds[1];
                serverPipeFd = pipeFds[0];
                serverPipeFd = pipeFds[0];
@@ -303,20 +303,13 @@ class ZygoteConnection {
     *   <li> --rlimit=r,c,m<i>tuple of values for setrlimit() call.
     *   <li> --rlimit=r,c,m<i>tuple of values for setrlimit() call.
     *    <code>r</code> is the resource, <code>c</code> and <code>m</code>
     *    <code>r</code> is the resource, <code>c</code> and <code>m</code>
     *    are the settings for current and max value.</i>
     *    are the settings for current and max value.</i>
     *   <li> --classpath=<i>colon-separated classpath</i> indicates
     *   <li> --instruction-set=<i>instruction-set-string</i> which instruction set to use/emulate.
     * that the specified class (which must b first non-flag argument) should
     *   <li> --nice-name=<i>nice name to appear in ps</i>
     * be loaded from jar files in the specified classpath. Incompatible with
     *   <li> --runtime-args indicates that the remaining arg list should
     * --runtime-init
     *   <li> --runtime-init indicates that the remaining arg list should
     * be handed off to com.android.internal.os.RuntimeInit, rather than
     * be handed off to com.android.internal.os.RuntimeInit, rather than
     * processed directly
     * processed directly.
     * Android runtime startup (eg, Binder initialization) is also eschewed.
     * Android runtime startup (eg, Binder initialization) is also eschewed.
     *   <li> --nice-name=<i>nice name to appear in ps</i>
     *   <li> [--] &lt;args for RuntimeInit &gt;
     *   <li> If <code>--runtime-init</code> is present:
     *      [--] &lt;args for RuntimeInit &gt;
     *   <li> If <code>--runtime-init</code> is absent:
     *      [--] &lt;classname&gt; [args...]
     *   <li> --instruction-set=<i>instruction-set-string</i> which instruction set to use/emulate.
     * </ul>
     * </ul>
     */
     */
    static class Arguments {
    static class Arguments {
@@ -344,12 +337,6 @@ class ZygoteConnection {
        int targetSdkVersion;
        int targetSdkVersion;
        boolean targetSdkVersionSpecified;
        boolean targetSdkVersionSpecified;


        /** from --classpath */
        String classpath;

        /** from --runtime-init */
        boolean runtimeInit;

        /** from --nice-name */
        /** from --nice-name */
        String niceName;
        String niceName;


@@ -411,6 +398,8 @@ class ZygoteConnection {
                throws IllegalArgumentException {
                throws IllegalArgumentException {
            int curArg = 0;
            int curArg = 0;


            boolean seenRuntimeArgs = true;

            for ( /* curArg */ ; curArg < args.length; curArg++) {
            for ( /* curArg */ ; curArg < args.length; curArg++) {
                String arg = args[curArg];
                String arg = args[curArg];


@@ -451,8 +440,8 @@ class ZygoteConnection {
                    debugFlags |= Zygote.DEBUG_ENABLE_JNI_LOGGING;
                    debugFlags |= Zygote.DEBUG_ENABLE_JNI_LOGGING;
                } else if (arg.equals("--enable-assert")) {
                } else if (arg.equals("--enable-assert")) {
                    debugFlags |= Zygote.DEBUG_ENABLE_ASSERT;
                    debugFlags |= Zygote.DEBUG_ENABLE_ASSERT;
                } else if (arg.equals("--runtime-init")) {
                } else if (arg.equals("--runtime-args")) {
                    runtimeInit = true;
                    seenRuntimeArgs = true;
                } else if (arg.startsWith("--seinfo=")) {
                } else if (arg.startsWith("--seinfo=")) {
                    if (seInfoSpecified) {
                    if (seInfoSpecified) {
                        throw new IllegalArgumentException(
                        throw new IllegalArgumentException(
@@ -497,17 +486,6 @@ class ZygoteConnection {
                    }
                    }


                    rlimits.add(rlimitTuple);
                    rlimits.add(rlimitTuple);
                } else if (arg.equals("-classpath")) {
                    if (classpath != null) {
                        throw new IllegalArgumentException(
                                "Duplicate arg specified");
                    }
                    try {
                        classpath = args[++curArg];
                    } catch (IndexOutOfBoundsException ex) {
                        throw new IllegalArgumentException(
                                "-classpath requires argument");
                    }
                } else if (arg.startsWith("--setgroups=")) {
                } else if (arg.startsWith("--setgroups=")) {
                    if (gids != null) {
                    if (gids != null) {
                        throw new IllegalArgumentException(
                        throw new IllegalArgumentException(
@@ -554,9 +532,8 @@ class ZygoteConnection {
                }
                }
            }
            }


            if (runtimeInit && classpath != null) {
            if (!seenRuntimeArgs) {
                throw new IllegalArgumentException(
                throw new IllegalArgumentException("Unexpected argument : " + args[curArg]);
                        "--runtime-init and -classpath are incompatible");
            }
            }


            remainingArgs = new String[args.length - curArg];
            remainingArgs = new String[args.length - curArg];
@@ -878,7 +855,6 @@ class ZygoteConnection {
            Process.setArgV0(parsedArgs.niceName);
            Process.setArgV0(parsedArgs.niceName);
        }
        }


        if (parsedArgs.runtimeInit) {
        if (parsedArgs.invokeWith != null) {
        if (parsedArgs.invokeWith != null) {
            WrapperInit.execApplication(parsedArgs.invokeWith,
            WrapperInit.execApplication(parsedArgs.invokeWith,
                    parsedArgs.niceName, parsedArgs.targetSdkVersion,
                    parsedArgs.niceName, parsedArgs.targetSdkVersion,
@@ -887,39 +863,6 @@ class ZygoteConnection {
            RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion,
            RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion,
                    parsedArgs.remainingArgs, null /* classLoader */);
                    parsedArgs.remainingArgs, null /* classLoader */);
        }
        }
        } else {
            String className;
            try {
                className = parsedArgs.remainingArgs[0];
            } catch (ArrayIndexOutOfBoundsException ex) {
                logAndPrintError(newStderr,
                        "Missing required class name argument", null);
                return;
            }

            String[] mainArgs = new String[parsedArgs.remainingArgs.length - 1];
            System.arraycopy(parsedArgs.remainingArgs, 1,
                    mainArgs, 0, mainArgs.length);

            if (parsedArgs.invokeWith != null) {
                WrapperInit.execStandalone(parsedArgs.invokeWith,
                        parsedArgs.classpath, className, mainArgs);
            } else {
                ClassLoader cloader;
                if (parsedArgs.classpath != null) {
                    cloader = new PathClassLoader(parsedArgs.classpath,
                            ClassLoader.getSystemClassLoader());
                } else {
                    cloader = ClassLoader.getSystemClassLoader();
                }

                try {
                    ZygoteInit.invokeStaticMain(cloader, className, mainArgs);
                } catch (RuntimeException ex) {
                    logAndPrintError(newStderr, "Error starting.", ex);
                }
            }
        }
    }
    }


    /**
    /**
+0 −48
Original line number Original line Diff line number Diff line
@@ -102,54 +102,6 @@ public class ZygoteInit {
    /** Controls whether we should preload resources during zygote init. */
    /** Controls whether we should preload resources during zygote init. */
    private static final boolean PRELOAD_RESOURCES = true;
    private static final boolean PRELOAD_RESOURCES = true;


    /**
     * Invokes a static "main(argv[]) method on class "className".
     * Converts various failing exceptions into RuntimeExceptions, with
     * the assumption that they will then cause the VM instance to exit.
     *
     * @param loader class loader to use
     * @param className Fully-qualified class name
     * @param argv Argument vector for main()
     */
    static void invokeStaticMain(ClassLoader loader,
            String className, String[] argv)
            throws ZygoteInit.MethodAndArgsCaller {
        Class<?> cl;

        try {
            cl = loader.loadClass(className);
        } catch (ClassNotFoundException ex) {
            throw new RuntimeException(
                    "Missing class when invoking static main " + className,
                    ex);
        }

        Method m;
        try {
            m = cl.getMethod("main", new Class[] { String[].class });
        } catch (NoSuchMethodException ex) {
            throw new RuntimeException(
                    "Missing static main on " + className, ex);
        } catch (SecurityException ex) {
            throw new RuntimeException(
                    "Problem getting static main on " + className, ex);
        }

        int modifiers = m.getModifiers();
        if (! (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers))) {
            throw new RuntimeException(
                    "Main method is not public and static on " + className);
        }

        /*
         * This throw gets caught in ZygoteInit.main(), which responds
         * by invoking the exception's run() method. This arrangement
         * clears up all the stack frames that were required in setting
         * up the process.
         */
        throw new ZygoteInit.MethodAndArgsCaller(m, argv);
    }

    /**
    /**
     * Registers a server socket for zygote command connections
     * Registers a server socket for zygote command connections
     *
     *