Search in sources :

Example 1 with UnixSocketAddress

use of android.system.UnixSocketAddress in project platform_frameworks_base by android.

the class NativeCrashListener method run.

@Override
public void run() {
    final byte[] ackSignal = new byte[1];
    if (DEBUG)
        Slog.i(TAG, "Starting up");
    // The file system entity for this socket is created with 0777 perms, owned
    // by system:system. selinux restricts things so that only crash_dump can
    // access it.
    {
        File socketFile = new File(DEBUGGERD_SOCKET_PATH);
        if (socketFile.exists()) {
            socketFile.delete();
        }
    }
    try {
        FileDescriptor serverFd = Os.socket(AF_UNIX, SOCK_STREAM, 0);
        final UnixSocketAddress sockAddr = UnixSocketAddress.createFileSystem(DEBUGGERD_SOCKET_PATH);
        Os.bind(serverFd, sockAddr);
        Os.listen(serverFd, 1);
        Os.chmod(DEBUGGERD_SOCKET_PATH, 0777);
        while (true) {
            FileDescriptor peerFd = null;
            try {
                if (MORE_DEBUG)
                    Slog.v(TAG, "Waiting for debuggerd connection");
                peerFd = Os.accept(serverFd, null);
                if (MORE_DEBUG)
                    Slog.v(TAG, "Got debuggerd socket " + peerFd);
                if (peerFd != null) {
                    // the reporting thread may take responsibility for
                    // acking the debugger; make sure we play along.
                    consumeNativeCrashData(peerFd);
                }
            } catch (Exception e) {
                Slog.w(TAG, "Error handling connection", e);
            } finally {
                // byte written is irrelevant.
                if (peerFd != null) {
                    try {
                        Os.write(peerFd, ackSignal, 0, 1);
                    } catch (Exception e) {
                        /* we don't care about failures here */
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception writing ack: " + e.getMessage());
                        }
                    }
                    try {
                        Os.close(peerFd);
                    } catch (ErrnoException e) {
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception closing socket: " + e.getMessage());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Slog.e(TAG, "Unable to init native debug socket!", e);
    }
}
Also used : ErrnoException(android.system.ErrnoException) File(java.io.File) FileDescriptor(java.io.FileDescriptor) ErrnoException(android.system.ErrnoException) InterruptedIOException(java.io.InterruptedIOException) UnixSocketAddress(android.system.UnixSocketAddress)

Example 2 with UnixSocketAddress

use of android.system.UnixSocketAddress in project android_frameworks_base by DirtyUnicorns.

the class NativeCrashListener method run.

@Override
public void run() {
    final byte[] ackSignal = new byte[1];
    if (DEBUG)
        Slog.i(TAG, "Starting up");
    // The file system entity for this socket is created with 0700 perms, owned
    // by system:system.  debuggerd runs as root, so is capable of connecting to
    // it, but 3rd party apps cannot.
    {
        File socketFile = new File(DEBUGGERD_SOCKET_PATH);
        if (socketFile.exists()) {
            socketFile.delete();
        }
    }
    try {
        FileDescriptor serverFd = Os.socket(AF_UNIX, SOCK_STREAM, 0);
        final UnixSocketAddress sockAddr = UnixSocketAddress.createFileSystem(DEBUGGERD_SOCKET_PATH);
        Os.bind(serverFd, sockAddr);
        Os.listen(serverFd, 1);
        while (true) {
            FileDescriptor peerFd = null;
            try {
                if (MORE_DEBUG)
                    Slog.v(TAG, "Waiting for debuggerd connection");
                peerFd = Os.accept(serverFd, null);
                if (MORE_DEBUG)
                    Slog.v(TAG, "Got debuggerd socket " + peerFd);
                if (peerFd != null) {
                    // Only the superuser is allowed to talk to us over this socket
                    StructUcred credentials = Os.getsockoptUcred(peerFd, SOL_SOCKET, SO_PEERCRED);
                    if (credentials.uid == 0) {
                        // the reporting thread may take responsibility for
                        // acking the debugger; make sure we play along.
                        consumeNativeCrashData(peerFd);
                    }
                }
            } catch (Exception e) {
                Slog.w(TAG, "Error handling connection", e);
            } finally {
                // byte written is irrelevant.
                if (peerFd != null) {
                    try {
                        Os.write(peerFd, ackSignal, 0, 1);
                    } catch (Exception e) {
                        /* we don't care about failures here */
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception writing ack: " + e.getMessage());
                        }
                    }
                    try {
                        Os.close(peerFd);
                    } catch (ErrnoException e) {
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception closing socket: " + e.getMessage());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Slog.e(TAG, "Unable to init native debug socket!", e);
    }
}
Also used : ErrnoException(android.system.ErrnoException) StructUcred(android.system.StructUcred) File(java.io.File) FileDescriptor(java.io.FileDescriptor) ErrnoException(android.system.ErrnoException) InterruptedIOException(java.io.InterruptedIOException) UnixSocketAddress(android.system.UnixSocketAddress)

Example 3 with UnixSocketAddress

use of android.system.UnixSocketAddress in project android_frameworks_base by AOSPA.

the class NativeCrashListener method run.

@Override
public void run() {
    final byte[] ackSignal = new byte[1];
    if (DEBUG)
        Slog.i(TAG, "Starting up");
    // The file system entity for this socket is created with 0700 perms, owned
    // by system:system.  debuggerd runs as root, so is capable of connecting to
    // it, but 3rd party apps cannot.
    {
        File socketFile = new File(DEBUGGERD_SOCKET_PATH);
        if (socketFile.exists()) {
            socketFile.delete();
        }
    }
    try {
        FileDescriptor serverFd = Os.socket(AF_UNIX, SOCK_STREAM, 0);
        final UnixSocketAddress sockAddr = UnixSocketAddress.createFileSystem(DEBUGGERD_SOCKET_PATH);
        Os.bind(serverFd, sockAddr);
        Os.listen(serverFd, 1);
        while (true) {
            FileDescriptor peerFd = null;
            try {
                if (MORE_DEBUG)
                    Slog.v(TAG, "Waiting for debuggerd connection");
                peerFd = Os.accept(serverFd, null);
                if (MORE_DEBUG)
                    Slog.v(TAG, "Got debuggerd socket " + peerFd);
                if (peerFd != null) {
                    // Only the superuser is allowed to talk to us over this socket
                    StructUcred credentials = Os.getsockoptUcred(peerFd, SOL_SOCKET, SO_PEERCRED);
                    if (credentials.uid == 0) {
                        // the reporting thread may take responsibility for
                        // acking the debugger; make sure we play along.
                        consumeNativeCrashData(peerFd);
                    }
                }
            } catch (Exception e) {
                Slog.w(TAG, "Error handling connection", e);
            } finally {
                // byte written is irrelevant.
                if (peerFd != null) {
                    try {
                        Os.write(peerFd, ackSignal, 0, 1);
                    } catch (Exception e) {
                        /* we don't care about failures here */
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception writing ack: " + e.getMessage());
                        }
                    }
                    try {
                        Os.close(peerFd);
                    } catch (ErrnoException e) {
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception closing socket: " + e.getMessage());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Slog.e(TAG, "Unable to init native debug socket!", e);
    }
}
Also used : ErrnoException(android.system.ErrnoException) StructUcred(android.system.StructUcred) File(java.io.File) FileDescriptor(java.io.FileDescriptor) ErrnoException(android.system.ErrnoException) InterruptedIOException(java.io.InterruptedIOException) UnixSocketAddress(android.system.UnixSocketAddress)

Example 4 with UnixSocketAddress

use of android.system.UnixSocketAddress in project android_frameworks_base by ResurrectionRemix.

the class NativeCrashListener method run.

@Override
public void run() {
    final byte[] ackSignal = new byte[1];
    if (DEBUG)
        Slog.i(TAG, "Starting up");
    // The file system entity for this socket is created with 0700 perms, owned
    // by system:system.  debuggerd runs as root, so is capable of connecting to
    // it, but 3rd party apps cannot.
    {
        File socketFile = new File(DEBUGGERD_SOCKET_PATH);
        if (socketFile.exists()) {
            socketFile.delete();
        }
    }
    try {
        FileDescriptor serverFd = Os.socket(AF_UNIX, SOCK_STREAM, 0);
        final UnixSocketAddress sockAddr = UnixSocketAddress.createFileSystem(DEBUGGERD_SOCKET_PATH);
        Os.bind(serverFd, sockAddr);
        Os.listen(serverFd, 1);
        while (true) {
            FileDescriptor peerFd = null;
            try {
                if (MORE_DEBUG)
                    Slog.v(TAG, "Waiting for debuggerd connection");
                peerFd = Os.accept(serverFd, null);
                if (MORE_DEBUG)
                    Slog.v(TAG, "Got debuggerd socket " + peerFd);
                if (peerFd != null) {
                    // Only the superuser is allowed to talk to us over this socket
                    StructUcred credentials = Os.getsockoptUcred(peerFd, SOL_SOCKET, SO_PEERCRED);
                    if (credentials.uid == 0) {
                        // the reporting thread may take responsibility for
                        // acking the debugger; make sure we play along.
                        consumeNativeCrashData(peerFd);
                    }
                }
            } catch (Exception e) {
                Slog.w(TAG, "Error handling connection", e);
            } finally {
                // byte written is irrelevant.
                if (peerFd != null) {
                    try {
                        Os.write(peerFd, ackSignal, 0, 1);
                    } catch (Exception e) {
                        /* we don't care about failures here */
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception writing ack: " + e.getMessage());
                        }
                    }
                    try {
                        Os.close(peerFd);
                    } catch (ErrnoException e) {
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception closing socket: " + e.getMessage());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Slog.e(TAG, "Unable to init native debug socket!", e);
    }
}
Also used : ErrnoException(android.system.ErrnoException) StructUcred(android.system.StructUcred) File(java.io.File) FileDescriptor(java.io.FileDescriptor) ErrnoException(android.system.ErrnoException) InterruptedIOException(java.io.InterruptedIOException) UnixSocketAddress(android.system.UnixSocketAddress)

Example 5 with UnixSocketAddress

use of android.system.UnixSocketAddress in project android_frameworks_base by crdroidandroid.

the class NativeCrashListener method run.

@Override
public void run() {
    final byte[] ackSignal = new byte[1];
    if (DEBUG)
        Slog.i(TAG, "Starting up");
    // The file system entity for this socket is created with 0700 perms, owned
    // by system:system.  debuggerd runs as root, so is capable of connecting to
    // it, but 3rd party apps cannot.
    {
        File socketFile = new File(DEBUGGERD_SOCKET_PATH);
        if (socketFile.exists()) {
            socketFile.delete();
        }
    }
    try {
        FileDescriptor serverFd = Os.socket(AF_UNIX, SOCK_STREAM, 0);
        final UnixSocketAddress sockAddr = UnixSocketAddress.createFileSystem(DEBUGGERD_SOCKET_PATH);
        Os.bind(serverFd, sockAddr);
        Os.listen(serverFd, 1);
        while (true) {
            FileDescriptor peerFd = null;
            try {
                if (MORE_DEBUG)
                    Slog.v(TAG, "Waiting for debuggerd connection");
                peerFd = Os.accept(serverFd, null);
                if (MORE_DEBUG)
                    Slog.v(TAG, "Got debuggerd socket " + peerFd);
                if (peerFd != null) {
                    // Only the superuser is allowed to talk to us over this socket
                    StructUcred credentials = Os.getsockoptUcred(peerFd, SOL_SOCKET, SO_PEERCRED);
                    if (credentials.uid == 0) {
                        // the reporting thread may take responsibility for
                        // acking the debugger; make sure we play along.
                        consumeNativeCrashData(peerFd);
                    }
                }
            } catch (Exception e) {
                Slog.w(TAG, "Error handling connection", e);
            } finally {
                // byte written is irrelevant.
                if (peerFd != null) {
                    try {
                        Os.write(peerFd, ackSignal, 0, 1);
                    } catch (Exception e) {
                        /* we don't care about failures here */
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception writing ack: " + e.getMessage());
                        }
                    }
                    try {
                        Os.close(peerFd);
                    } catch (ErrnoException e) {
                        if (MORE_DEBUG) {
                            Slog.d(TAG, "Exception closing socket: " + e.getMessage());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Slog.e(TAG, "Unable to init native debug socket!", e);
    }
}
Also used : ErrnoException(android.system.ErrnoException) StructUcred(android.system.StructUcred) File(java.io.File) FileDescriptor(java.io.FileDescriptor) ErrnoException(android.system.ErrnoException) InterruptedIOException(java.io.InterruptedIOException) UnixSocketAddress(android.system.UnixSocketAddress)

Aggregations

ErrnoException (android.system.ErrnoException)5 UnixSocketAddress (android.system.UnixSocketAddress)5 File (java.io.File)5 FileDescriptor (java.io.FileDescriptor)5 InterruptedIOException (java.io.InterruptedIOException)5 StructUcred (android.system.StructUcred)4