libmedia: Preserve futex return status in client obtainBuffer

clock_gettime() can change errno if something goes wrong (most
commonly setting EBADF). This failure should not cause a failure
in ClientProxy::obtainBuffer() if the futex returned successfully
or with a known status. Preserve errno before calling clock_gettime
to prevent propagation of an invalid, unexpected error.

authored-by: Leena Winterrowd <lenhardw@codeaurora.org>

Change-Id: Ib69201031a81395ece47dd8ad7c4dcddd2b00153
diff --git a/media/libmedia/AudioTrackShared.cpp b/media/libmedia/AudioTrackShared.cpp
index 666b747..9d5d996 100644
--- a/media/libmedia/AudioTrackShared.cpp
+++ b/media/libmedia/AudioTrackShared.cpp
@@ -240,6 +240,7 @@
             errno = 0;
             (void) syscall(__NR_futex, &cblk->mFutex,
                     mClientInServer ? FUTEX_WAIT_PRIVATE : FUTEX_WAIT, old & ~CBLK_FUTEX_WAKE, ts);
+            status_t error = errno; // clock_gettime can affect errno
             // update total elapsed time spent waiting
             if (measure) {
                 struct timespec after;
@@ -257,7 +258,7 @@
                 before = after;
                 beforeIsValid = true;
             }
-            switch (errno) {
+            switch (error) {
             case 0:            // normal wakeup by server, or by binderDied()
             case EWOULDBLOCK:  // benign race condition with server
             case EINTR:        // wait was interrupted by signal or other spurious wakeup
@@ -265,7 +266,7 @@
                 // FIXME these error/non-0 status are being dropped
                 break;
             default:
-                status = errno;
+                status = error;
                 ALOGE("%s unexpected error %s", __func__, strerror(status));
                 goto end;
             }