diff options
author | Elliott Hughes | 2015-06-30 10:22:24 -0500 |
---|---|---|
committer | Elliott Hughes | 2015-06-30 12:41:15 -0500 |
commit | 6ed68cc412752e4c78755df9a1516e610ec66fa8 (patch) | |
tree | 287929b99130bf3a06b67b5abf2d3b4b6d8199f3 /libutils/Looper.cpp | |
parent | 692dc75d9fbf5c256cd8c66219a930ae0fe9f523 (diff) | |
download | platform-system-core-6ed68cc412752e4c78755df9a1516e610ec66fa8.tar.gz platform-system-core-6ed68cc412752e4c78755df9a1516e610ec66fa8.tar.xz platform-system-core-6ed68cc412752e4c78755df9a1516e610ec66fa8.zip |
Consistently use strerror in libutils.
It's easier for people to debug, and side-steps the problem that errno
values differ between architectures.
Bug: http://b/17458391
Change-Id: I1db9b2cbb653839d3936b91e37e5cff02671318a
Diffstat (limited to 'libutils/Looper.cpp')
-rw-r--r-- | libutils/Looper.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/libutils/Looper.cpp b/libutils/Looper.cpp index 9a2dd6cc4..20c1e927f 100644 --- a/libutils/Looper.cpp +++ b/libutils/Looper.cpp | |||
@@ -17,9 +17,11 @@ | |||
17 | #include <utils/Looper.h> | 17 | #include <utils/Looper.h> |
18 | #include <utils/Timers.h> | 18 | #include <utils/Timers.h> |
19 | 19 | ||
20 | #include <unistd.h> | 20 | #include <errno.h> |
21 | #include <fcntl.h> | 21 | #include <fcntl.h> |
22 | #include <limits.h> | 22 | #include <limits.h> |
23 | #include <string.h> | ||
24 | #include <unistd.h> | ||
23 | 25 | ||
24 | 26 | ||
25 | namespace android { | 27 | namespace android { |
@@ -71,32 +73,32 @@ Looper::Looper(bool allowNonCallbacks) : | |||
71 | mResponseIndex(0), mNextMessageUptime(LLONG_MAX) { | 73 | mResponseIndex(0), mNextMessageUptime(LLONG_MAX) { |
72 | int wakeFds[2]; | 74 | int wakeFds[2]; |
73 | int result = pipe(wakeFds); | 75 | int result = pipe(wakeFds); |
74 | LOG_ALWAYS_FATAL_IF(result != 0, "Could not create wake pipe. errno=%d", errno); | 76 | LOG_ALWAYS_FATAL_IF(result != 0, "Could not create wake pipe: %s", strerror(errno)); |
75 | 77 | ||
76 | mWakeReadPipeFd = wakeFds[0]; | 78 | mWakeReadPipeFd = wakeFds[0]; |
77 | mWakeWritePipeFd = wakeFds[1]; | 79 | mWakeWritePipeFd = wakeFds[1]; |
78 | 80 | ||
79 | result = fcntl(mWakeReadPipeFd, F_SETFL, O_NONBLOCK); | 81 | result = fcntl(mWakeReadPipeFd, F_SETFL, O_NONBLOCK); |
80 | LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake read pipe non-blocking. errno=%d", | 82 | LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake read pipe non-blocking: %s", |
81 | errno); | 83 | strerror(errno)); |
82 | 84 | ||
83 | result = fcntl(mWakeWritePipeFd, F_SETFL, O_NONBLOCK); | 85 | result = fcntl(mWakeWritePipeFd, F_SETFL, O_NONBLOCK); |
84 | LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking. errno=%d", | 86 | LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking: %s", |
85 | errno); | 87 | strerror(errno)); |
86 | 88 | ||
87 | mIdling = false; | 89 | mIdling = false; |
88 | 90 | ||
89 | // Allocate the epoll instance and register the wake pipe. | 91 | // Allocate the epoll instance and register the wake pipe. |
90 | mEpollFd = epoll_create(EPOLL_SIZE_HINT); | 92 | mEpollFd = epoll_create(EPOLL_SIZE_HINT); |
91 | LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance. errno=%d", errno); | 93 | LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance: %s", strerror(errno)); |
92 | 94 | ||
93 | struct epoll_event eventItem; | 95 | struct epoll_event eventItem; |
94 | memset(& eventItem, 0, sizeof(epoll_event)); // zero out unused members of data field union | 96 | memset(& eventItem, 0, sizeof(epoll_event)); // zero out unused members of data field union |
95 | eventItem.events = EPOLLIN; | 97 | eventItem.events = EPOLLIN; |
96 | eventItem.data.fd = mWakeReadPipeFd; | 98 | eventItem.data.fd = mWakeReadPipeFd; |
97 | result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, & eventItem); | 99 | result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, & eventItem); |
98 | LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance. errno=%d", | 100 | LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance: %s", |
99 | errno); | 101 | strerror(errno)); |
100 | } | 102 | } |
101 | 103 | ||
102 | Looper::~Looper() { | 104 | Looper::~Looper() { |
@@ -233,7 +235,7 @@ int Looper::pollInner(int timeoutMillis) { | |||
233 | if (errno == EINTR) { | 235 | if (errno == EINTR) { |
234 | goto Done; | 236 | goto Done; |
235 | } | 237 | } |
236 | ALOGW("Poll failed with an unexpected error, errno=%d", errno); | 238 | ALOGW("Poll failed with an unexpected error: %s", strerror(errno)); |
237 | result = POLL_ERROR; | 239 | result = POLL_ERROR; |
238 | goto Done; | 240 | goto Done; |
239 | } | 241 | } |
@@ -377,7 +379,7 @@ void Looper::wake() { | |||
377 | 379 | ||
378 | if (nWrite != 1) { | 380 | if (nWrite != 1) { |
379 | if (errno != EAGAIN) { | 381 | if (errno != EAGAIN) { |
380 | ALOGW("Could not write wake signal, errno=%d", errno); | 382 | ALOGW("Could not write wake signal: %s", strerror(errno)); |
381 | } | 383 | } |
382 | } | 384 | } |
383 | } | 385 | } |
@@ -447,14 +449,14 @@ int Looper::addFd(int fd, int ident, int events, const sp<LooperCallback>& callb | |||
447 | if (requestIndex < 0) { | 449 | if (requestIndex < 0) { |
448 | int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, & eventItem); | 450 | int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, & eventItem); |
449 | if (epollResult < 0) { | 451 | if (epollResult < 0) { |
450 | ALOGE("Error adding epoll events for fd %d, errno=%d", fd, errno); | 452 | ALOGE("Error adding epoll events for fd %d: %s", fd, strerror(errno)); |
451 | return -1; | 453 | return -1; |
452 | } | 454 | } |
453 | mRequests.add(fd, request); | 455 | mRequests.add(fd, request); |
454 | } else { | 456 | } else { |
455 | int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_MOD, fd, & eventItem); | 457 | int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_MOD, fd, & eventItem); |
456 | if (epollResult < 0) { | 458 | if (epollResult < 0) { |
457 | ALOGE("Error modifying epoll events for fd %d, errno=%d", fd, errno); | 459 | ALOGE("Error modifying epoll events for fd %d: %s", fd, strerror(errno)); |
458 | return -1; | 460 | return -1; |
459 | } | 461 | } |
460 | mRequests.replaceValueAt(requestIndex, request); | 462 | mRequests.replaceValueAt(requestIndex, request); |
@@ -477,7 +479,7 @@ int Looper::removeFd(int fd) { | |||
477 | 479 | ||
478 | int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, NULL); | 480 | int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, NULL); |
479 | if (epollResult < 0) { | 481 | if (epollResult < 0) { |
480 | ALOGE("Error removing epoll events for fd %d, errno=%d", fd, errno); | 482 | ALOGE("Error removing epoll events for fd %d: %s", fd, strerror(errno)); |
481 | return -1; | 483 | return -1; |
482 | } | 484 | } |
483 | 485 | ||