diff options
author | Jesse Hall <jessehall@google.com> | 2014-10-06 09:49:45 -0700 |
---|---|---|
committer | The Android Automerger <android-build@google.com> | 2014-10-06 17:50:10 -0700 |
commit | 40fc668a460e65afa6b35ef2b00b043ed810c51a (patch) | |
tree | 59ed8515ac8f7715e872b7c96e214043146228d5 | |
parent | 2281aa7a362165f70621b42c0de84ea186d7b330 (diff) | |
download | native-40fc668a460e65afa6b35ef2b00b043ed810c51a.tar.gz |
Parcel: extra validation/debug code for writeDupFileDescriptor
Temporary extra debug validation for b/17477219: a Parcel recipient is
getting a positive but invalid fd unexpectedly. Trying to track down
where it's coming from.
Debug code for bug: 17477219
Change-Id: Idb1e71621025a3928c7adc88fd44790e1abd2a01
-rw-r--r-- | libs/binder/Parcel.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index ba5688c7ce..f61eacae87 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -26,6 +26,7 @@ #include <binder/TextOutput.h> #include <errno.h> +#include <utils/CallStack.h> #include <utils/Debug.h> #include <utils/Log.h> #include <utils/String8.h> @@ -767,6 +768,29 @@ status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership) status_t Parcel::writeDupFileDescriptor(int fd) { int dupFd = dup(fd); + + { // Temporary extra debug validation for b/17477219: a Parcel recipient is + // getting a positive but invalid fd unexpectedly. Trying to track down + // where it's coming from. + int dupErrno = dupFd < 0 ? errno : 0; + int fdFlags = fcntl(fd, F_GETFD); + int fdFlagsErrno = fdFlags == -1 ? errno : 0; + int dupFlags = fcntl(dupFd, F_GETFD); + int dupFlagsErrno = dupFlags == -1 ? errno : 0; + if (dupFd < 0 || fdFlags == -1 || dupFlags == -1) { + ALOGE("Parcel::writeDupFileDescriptor failed:\n" + " fd=%d flags=%d err=%d(%s)\n" + " dupFd=%d dupErr=%d(%s) flags=%d err=%d(%s)", + fd, fdFlags, fdFlagsErrno, strerror(fdFlagsErrno), + dupFd, dupErrno, strerror(dupErrno), + dupFlags, dupFlagsErrno, strerror(dupFlagsErrno)); + if (fd < 0 || fdFlags == -1) { + CallStack(LOG_TAG); + } + return -errno; + } + } + if (dupFd < 0) { return -errno; } @@ -1297,6 +1321,7 @@ status_t Parcel::read(FlattenableHelperInterface& val) const oldfd, fds[i], dupErrno, strerror(dupErrno), oldfd, flags, fcntlErrno, strerror(fcntlErrno), flat, flat ? flat->type : 0); + CallStack(LOG_TAG); } } |