summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authortao.pei <tao.pei@ck-telecom.com>2015-07-17 17:18:41 +0800
committerSteve Kondik <steve@cyngn.com>2016-03-22 17:14:35 -0700
commitd954486023aea49be22b53495166f40a028fdb67 (patch)
tree54204db770d39944a8cc858e2b3dc1748ac25dcd /media
parentf97015ad37e8386a4215e2d25a4196edef5f7c8d (diff)
downloadframeworks_av-d954486023aea49be22b53495166f40a028fdb67.zip
frameworks_av-d954486023aea49be22b53495166f40a028fdb67.tar.gz
frameworks_av-d954486023aea49be22b53495166f40a028fdb67.tar.bz2
Use errno correctly.
After a failed write() or ioctl(), errno wasn't being checked until after some other function calls that could also modify errno, thus checking the wrong errno. Make sure to check it prior to doing anything else that can modify it. [Preconditions] 1.PC connects with phone(mtp). [Procedures] 1.Copy a file from PC to phone. 2.Cancel the copying. 3.Recopy the file. Change-Id: Id772fca7ccb96d3f43bd4beb210bedd8d3ac17fa
Diffstat (limited to 'media')
-rw-r--r--media/mtp/MtpServer.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 6a334e6..3c91ffd 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -215,10 +215,11 @@ void MtpServer::run() {
mResponse.setTransactionID(transaction);
ALOGV("sending response %04X", mResponse.getResponseCode());
ret = mResponse.write(fd);
+ const int savedErrno = errno;
mResponse.dump();
if (ret < 0) {
ALOGE("request write returned %d, errno: %d", ret, errno);
- if (errno == ECANCELED) {
+ if (savedErrno == ECANCELED) {
// return to top of loop and wait for next command
continue;
}
@@ -793,15 +794,19 @@ MtpResponseCode MtpServer::doGetObject() {
// then transfer the file
int ret = ioctl(mFD, MTP_SEND_FILE_WITH_HEADER, (unsigned long)&mfr);
- ALOGV("MTP_SEND_FILE_WITH_HEADER returned %d\n", ret);
- close(mfr.fd);
if (ret < 0) {
- if (errno == ECANCELED)
- return MTP_RESPONSE_TRANSACTION_CANCELLED;
- else
- return MTP_RESPONSE_GENERAL_ERROR;
+ if (errno == ECANCELED) {
+ result = MTP_RESPONSE_TRANSACTION_CANCELLED;
+ } else {
+ result = MTP_RESPONSE_GENERAL_ERROR;
+ }
+ } else {
+ result = MTP_RESPONSE_OK;
}
- return MTP_RESPONSE_OK;
+
+ ALOGV("MTP_SEND_FILE_WITH_HEADER returned %d\n", ret);
+ close(mfr.fd);
+ return result;
}
MtpResponseCode MtpServer::doGetThumb() {
@@ -870,14 +875,15 @@ MtpResponseCode MtpServer::doGetPartialObject(MtpOperationCode operation) {
// transfer the file
int ret = ioctl(mFD, MTP_SEND_FILE_WITH_HEADER, (unsigned long)&mfr);
ALOGV("MTP_SEND_FILE_WITH_HEADER returned %d\n", ret);
- close(mfr.fd);
+ result = MTP_RESPONSE_OK;
if (ret < 0) {
if (errno == ECANCELED)
- return MTP_RESPONSE_TRANSACTION_CANCELLED;
+ result = MTP_RESPONSE_TRANSACTION_CANCELLED;
else
- return MTP_RESPONSE_GENERAL_ERROR;
+ result = MTP_RESPONSE_GENERAL_ERROR;
}
- return MTP_RESPONSE_OK;
+ close(mfr.fd);
+ return result;
}
MtpResponseCode MtpServer::doSendObjectInfo() {
@@ -991,6 +997,7 @@ MtpResponseCode MtpServer::doSendObject() {
MtpResponseCode result = MTP_RESPONSE_OK;
mode_t mask;
int ret, initialData;
+ bool isCanceled = false;
if (mSendObjectHandle == kInvalidObjectHandle) {
ALOGE("Expected SendObjectInfo before SendObject");
@@ -1038,6 +1045,10 @@ MtpResponseCode MtpServer::doSendObject() {
ALOGV("receiving %s\n", (const char *)mSendObjectFilePath);
// transfer the file
ret = ioctl(mFD, MTP_RECEIVE_FILE, (unsigned long)&mfr);
+ if ((ret < 0) && (errno == ECANCELED)) {
+ isCanceled = true;
+ }
+
ALOGV("MTP_RECEIVE_FILE returned %d\n", ret);
}
}
@@ -1045,7 +1056,7 @@ MtpResponseCode MtpServer::doSendObject() {
if (ret < 0) {
unlink(mSendObjectFilePath);
- if (errno == ECANCELED)
+ if (isCanceled)
result = MTP_RESPONSE_TRANSACTION_CANCELLED;
else
result = MTP_RESPONSE_GENERAL_ERROR;
@@ -1214,6 +1225,7 @@ MtpResponseCode MtpServer::doSendPartialObject() {
length -= initialData;
}
+ bool isCanceled = false;
if (ret < 0) {
ALOGE("failed to write initial data");
} else {
@@ -1225,12 +1237,15 @@ MtpResponseCode MtpServer::doSendPartialObject() {
// transfer the file
ret = ioctl(mFD, MTP_RECEIVE_FILE, (unsigned long)&mfr);
+ if ((ret < 0) && (errno == ECANCELED)) {
+ isCanceled = true;
+ }
ALOGV("MTP_RECEIVE_FILE returned %d", ret);
}
}
if (ret < 0) {
mResponse.setParameter(1, 0);
- if (errno == ECANCELED)
+ if (isCanceled)
return MTP_RESPONSE_TRANSACTION_CANCELLED;
else
return MTP_RESPONSE_GENERAL_ERROR;