summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2011-10-21 11:36:16 -0700
committerElliott Hughes <enh@google.com>2011-10-21 11:36:16 -0700
commite8e19f6476b30ccf9f69925c10ce62efdba4e62a (patch)
treeafb554d45abfe9246bfa45ec3ffbc9669a2849fa /luni/src
parenta0602309f2de896505bd475f9de460c761c8bc2a (diff)
downloadlibcore-e8e19f6476b30ccf9f69925c10ce62efdba4e62a.zip
libcore-e8e19f6476b30ccf9f69925c10ce62efdba4e62a.tar.gz
libcore-e8e19f6476b30ccf9f69925c10ce62efdba4e62a.tar.bz2
Cope with fstat(2) failures during close.
Whatever the root cause of the fstat(2) failure, we should still attempt the requested close(2) --- even if it's just going to fail in the same way the fstat(2) did. Bug: 5407056 Change-Id: Ie988d1b1ebdb6b378fb537b2f56245fab568ee7c
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/main/java/libcore/io/BlockGuardOs.java25
1 files changed, 12 insertions, 13 deletions
diff --git a/luni/src/main/java/libcore/io/BlockGuardOs.java b/luni/src/main/java/libcore/io/BlockGuardOs.java
index a0062e4..07ee520 100644
--- a/luni/src/main/java/libcore/io/BlockGuardOs.java
+++ b/luni/src/main/java/libcore/io/BlockGuardOs.java
@@ -48,26 +48,25 @@ public class BlockGuardOs extends ForwardingOs {
}
@Override public void close(FileDescriptor fd) throws ErrnoException {
- if (S_ISSOCK(Libcore.os.fstat(fd).st_mode) && isLingerSocket(fd)) {
- // If the fd is a socket with SO_LINGER set, we might block indefinitely.
- // We allow non-linger sockets so that apps can close their network connections in
- // methods like onDestroy which will run on the UI thread.
- BlockGuard.getThreadPolicy().onNetwork();
- }
- os.close(fd);
- }
-
- private static boolean isLingerSocket(FileDescriptor fd) {
try {
- StructLinger linger = Libcore.os.getsockoptLinger(fd, SOL_SOCKET, SO_LINGER);
- return linger.isOn() && linger.l_linger > 0;
+ if (S_ISSOCK(Libcore.os.fstat(fd).st_mode) && isLingerSocket(fd)) {
+ // If the fd is a socket with SO_LINGER set, we might block indefinitely.
+ // We allow non-linger sockets so that apps can close their network connections in
+ // methods like onDestroy which will run on the UI thread.
+ BlockGuard.getThreadPolicy().onNetwork();
+ }
} catch (ErrnoException ignored) {
// We're called via Socket.close (which doesn't ask for us to be called), so we
// must not throw here, because Socket.close must not throw if asked to close an
// already-closed socket. Also, the passed-in FileDescriptor isn't necessarily
// a socket at all.
- return false;
}
+ os.close(fd);
+ }
+
+ private static boolean isLingerSocket(FileDescriptor fd) throws ErrnoException {
+ StructLinger linger = Libcore.os.getsockoptLinger(fd, SOL_SOCKET, SO_LINGER);
+ return linger.isOn() && linger.l_linger > 0;
}
@Override public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException {