am 6d1e6ec3: Merge "Consistently use strerror in libutils."
* commit '6d1e6ec36fe47432739b06501894670c10f3d953': Consistently use strerror in libutils.
This commit is contained in:
commit
b40ebc5433
6 changed files with 31 additions and 29 deletions
|
|
@ -17,9 +17,11 @@
|
||||||
#include <utils/Looper.h>
|
#include <utils/Looper.h>
|
||||||
#include <utils/Timers.h>
|
#include <utils/Timers.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
@ -71,32 +73,32 @@ Looper::Looper(bool allowNonCallbacks) :
|
||||||
mResponseIndex(0), mNextMessageUptime(LLONG_MAX) {
|
mResponseIndex(0), mNextMessageUptime(LLONG_MAX) {
|
||||||
int wakeFds[2];
|
int wakeFds[2];
|
||||||
int result = pipe(wakeFds);
|
int result = pipe(wakeFds);
|
||||||
LOG_ALWAYS_FATAL_IF(result != 0, "Could not create wake pipe. errno=%d", errno);
|
LOG_ALWAYS_FATAL_IF(result != 0, "Could not create wake pipe: %s", strerror(errno));
|
||||||
|
|
||||||
mWakeReadPipeFd = wakeFds[0];
|
mWakeReadPipeFd = wakeFds[0];
|
||||||
mWakeWritePipeFd = wakeFds[1];
|
mWakeWritePipeFd = wakeFds[1];
|
||||||
|
|
||||||
result = fcntl(mWakeReadPipeFd, F_SETFL, O_NONBLOCK);
|
result = fcntl(mWakeReadPipeFd, F_SETFL, O_NONBLOCK);
|
||||||
LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake read pipe non-blocking. errno=%d",
|
LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake read pipe non-blocking: %s",
|
||||||
errno);
|
strerror(errno));
|
||||||
|
|
||||||
result = fcntl(mWakeWritePipeFd, F_SETFL, O_NONBLOCK);
|
result = fcntl(mWakeWritePipeFd, F_SETFL, O_NONBLOCK);
|
||||||
LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking. errno=%d",
|
LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking: %s",
|
||||||
errno);
|
strerror(errno));
|
||||||
|
|
||||||
mIdling = false;
|
mIdling = false;
|
||||||
|
|
||||||
// Allocate the epoll instance and register the wake pipe.
|
// Allocate the epoll instance and register the wake pipe.
|
||||||
mEpollFd = epoll_create(EPOLL_SIZE_HINT);
|
mEpollFd = epoll_create(EPOLL_SIZE_HINT);
|
||||||
LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance. errno=%d", errno);
|
LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance: %s", strerror(errno));
|
||||||
|
|
||||||
struct epoll_event eventItem;
|
struct epoll_event eventItem;
|
||||||
memset(& eventItem, 0, sizeof(epoll_event)); // zero out unused members of data field union
|
memset(& eventItem, 0, sizeof(epoll_event)); // zero out unused members of data field union
|
||||||
eventItem.events = EPOLLIN;
|
eventItem.events = EPOLLIN;
|
||||||
eventItem.data.fd = mWakeReadPipeFd;
|
eventItem.data.fd = mWakeReadPipeFd;
|
||||||
result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, & eventItem);
|
result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, & eventItem);
|
||||||
LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance. errno=%d",
|
LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance: %s",
|
||||||
errno);
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
Looper::~Looper() {
|
Looper::~Looper() {
|
||||||
|
|
@ -233,7 +235,7 @@ int Looper::pollInner(int timeoutMillis) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
ALOGW("Poll failed with an unexpected error, errno=%d", errno);
|
ALOGW("Poll failed with an unexpected error: %s", strerror(errno));
|
||||||
result = POLL_ERROR;
|
result = POLL_ERROR;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
@ -377,7 +379,7 @@ void Looper::wake() {
|
||||||
|
|
||||||
if (nWrite != 1) {
|
if (nWrite != 1) {
|
||||||
if (errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
ALOGW("Could not write wake signal, errno=%d", errno);
|
ALOGW("Could not write wake signal: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -447,14 +449,14 @@ int Looper::addFd(int fd, int ident, int events, const sp<LooperCallback>& callb
|
||||||
if (requestIndex < 0) {
|
if (requestIndex < 0) {
|
||||||
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, & eventItem);
|
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, & eventItem);
|
||||||
if (epollResult < 0) {
|
if (epollResult < 0) {
|
||||||
ALOGE("Error adding epoll events for fd %d, errno=%d", fd, errno);
|
ALOGE("Error adding epoll events for fd %d: %s", fd, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mRequests.add(fd, request);
|
mRequests.add(fd, request);
|
||||||
} else {
|
} else {
|
||||||
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_MOD, fd, & eventItem);
|
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_MOD, fd, & eventItem);
|
||||||
if (epollResult < 0) {
|
if (epollResult < 0) {
|
||||||
ALOGE("Error modifying epoll events for fd %d, errno=%d", fd, errno);
|
ALOGE("Error modifying epoll events for fd %d: %s", fd, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mRequests.replaceValueAt(requestIndex, request);
|
mRequests.replaceValueAt(requestIndex, request);
|
||||||
|
|
@ -477,7 +479,7 @@ int Looper::removeFd(int fd) {
|
||||||
|
|
||||||
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, NULL);
|
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, NULL);
|
||||||
if (epollResult < 0) {
|
if (epollResult < 0) {
|
||||||
ALOGE("Error removing epoll events for fd %d, errno=%d", fd, errno);
|
ALOGE("Error removing epoll events for fd %d: %s", fd, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,10 @@
|
||||||
#define LOG_TAG "ProcessCallStack"
|
#define LOG_TAG "ProcessCallStack"
|
||||||
// #define LOG_NDEBUG 0
|
// #define LOG_NDEBUG 0
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <utils/Errors.h>
|
#include <utils/Errors.h>
|
||||||
|
|
@ -135,8 +136,8 @@ void ProcessCallStack::update() {
|
||||||
|
|
||||||
dp = opendir(PATH_SELF_TASK);
|
dp = opendir(PATH_SELF_TASK);
|
||||||
if (dp == NULL) {
|
if (dp == NULL) {
|
||||||
ALOGE("%s: Failed to update the process's call stacks (errno = %d, '%s')",
|
ALOGE("%s: Failed to update the process's call stacks: %s",
|
||||||
__FUNCTION__, errno, strerror(errno));
|
__FUNCTION__, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,8 +173,8 @@ void ProcessCallStack::update() {
|
||||||
|
|
||||||
ssize_t idx = mThreadMap.add(tid, ThreadInfo());
|
ssize_t idx = mThreadMap.add(tid, ThreadInfo());
|
||||||
if (idx < 0) { // returns negative error value on error
|
if (idx < 0) { // returns negative error value on error
|
||||||
ALOGE("%s: Failed to add new ThreadInfo (errno = %zd, '%s')",
|
ALOGE("%s: Failed to add new ThreadInfo: %s",
|
||||||
__FUNCTION__, idx, strerror(-idx));
|
__FUNCTION__, strerror(-idx));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,8 +196,8 @@ void ProcessCallStack::update() {
|
||||||
__FUNCTION__, tid, threadInfo.callStack.size());
|
__FUNCTION__, tid, threadInfo.callStack.size());
|
||||||
}
|
}
|
||||||
if (code != 0) { // returns positive error value on error
|
if (code != 0) { // returns positive error value on error
|
||||||
ALOGE("%s: Failed to readdir from %s (errno = %d, '%s')",
|
ALOGE("%s: Failed to readdir from %s: %s",
|
||||||
__FUNCTION__, PATH_SELF_TASK, -code, strerror(code));
|
__FUNCTION__, PATH_SELF_TASK, strerror(code));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <utils/SystemClock.h>
|
#include <utils/SystemClock.h>
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
|
|
@ -160,9 +161,9 @@ int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
|
||||||
(android_pthread_entry)entryFunction, userData);
|
(android_pthread_entry)entryFunction, userData);
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
ALOGE("androidCreateRawThreadEtc failed (entry=%p, res=%d, errno=%d)\n"
|
ALOGE("androidCreateRawThreadEtc failed (entry=%p, res=%d, %s)\n"
|
||||||
"(android threadPriority=%d)",
|
"(android threadPriority=%d)",
|
||||||
entryFunction, result, errno, threadPriority);
|
entryFunction, result, strerror(errno), threadPriority);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,12 +56,12 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
|
||||||
int fd = ::open(filename.string(), O_RDONLY);
|
int fd = ::open(filename.string(), O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
result = -errno;
|
result = -errno;
|
||||||
ALOGE("Error opening file '%s', %s.", filename.string(), strerror(errno));
|
ALOGE("Error opening file '%s': %s", filename.string(), strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
if (fstat(fd, &stat)) {
|
if (fstat(fd, &stat)) {
|
||||||
result = -errno;
|
result = -errno;
|
||||||
ALOGE("Error getting size of file '%s', %s.", filename.string(), strerror(errno));
|
ALOGE("Error getting size of file '%s': %s", filename.string(), strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
size_t length = size_t(stat.st_size);
|
size_t length = size_t(stat.st_size);
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
|
||||||
ssize_t nrd = read(fd, buffer, length);
|
ssize_t nrd = read(fd, buffer, length);
|
||||||
if (nrd < 0) {
|
if (nrd < 0) {
|
||||||
result = -errno;
|
result = -errno;
|
||||||
ALOGE("Error reading file '%s', %s.", filename.string(), strerror(errno));
|
ALOGE("Error reading file '%s': %s", filename.string(), strerror(errno));
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue