Search in sources :

Example 46 with ErrnoException

use of libcore.io.ErrnoException in project XobotOS by xamarin.

the class ProcessManager method watchChildren.

/**
     * Loops indefinitely and calls ProcessManager.onExit() when children exit.
     */
private void watchChildren() {
    MutableInt status = new MutableInt(-1);
    while (true) {
        try {
            // Wait for children in our process group.
            int pid = Libcore.os.waitpid(0, status, 0);
            // Work out what onExit wants to hear.
            int exitValue;
            if (WIFEXITED(status.value)) {
                exitValue = WEXITSTATUS(status.value);
            } else if (WIFSIGNALED(status.value)) {
                exitValue = WTERMSIG(status.value);
            } else if (WIFSTOPPED(status.value)) {
                exitValue = WSTOPSIG(status.value);
            } else {
                throw new AssertionError("unexpected status from waitpid: " + status.value);
            }
            onExit(pid, exitValue);
        } catch (ErrnoException errnoException) {
            if (errnoException.errno == ECHILD) {
                // Expected errno: there are no children to wait for.
                // onExit will sleep until it is informed of another child coming to life.
                waitForMoreChildren();
                continue;
            } else {
                throw new AssertionError(errnoException);
            }
        }
    }
}
Also used : ErrnoException(libcore.io.ErrnoException) MutableInt(libcore.util.MutableInt)

Aggregations

ErrnoException (libcore.io.ErrnoException)46 IOException (java.io.IOException)15 FileDescriptor (java.io.FileDescriptor)13 StructStat (libcore.io.StructStat)9 File (java.io.File)7 InetSocketAddress (java.net.InetSocketAddress)7 NonReadableChannelException (java.nio.channels.NonReadableChannelException)6 NonWritableChannelException (java.nio.channels.NonWritableChannelException)6 StructFlock (libcore.io.StructFlock)6 FileOutputStream (java.io.FileOutputStream)5 SocketAddress (java.net.SocketAddress)4 FileInputStream (java.io.FileInputStream)3 SocketTimeoutException (java.net.SocketTimeoutException)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 FileLock (java.nio.channels.FileLock)3 MutableLong (libcore.util.MutableLong)3 PrintStream (java.io.PrintStream)2 SocketException (java.net.SocketException)2 LinkedList (java.util.LinkedList)2 GaiException (libcore.io.GaiException)2