Skip to content

Commit

Permalink
Add TEMP_FAILURE_RETRY to libsuspend.
Browse files Browse the repository at this point in the history
In testing, I observed one instance of a call failing due to a signal
sent to the process.  This could happen at various times so it's better
to be safe than sorry.

Bug: 20534809
Change-Id: I42242087300d8b840a50aec34aa6b2e1507cab50
  • Loading branch information
Jeff Brown committed May 18, 2015
1 parent a51d8b9 commit 0446e16
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
6 changes: 3 additions & 3 deletions libsuspend/autosuspend_autosleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static int autosuspend_autosleep_enable(void)

ALOGV("autosuspend_autosleep_enable\n");

ret = write(autosleep_fd, sleep_state, strlen(sleep_state));
ret = TEMP_FAILURE_RETRY(write(autosleep_fd, sleep_state, strlen(sleep_state)));
if (ret < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error writing to %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
Expand All @@ -62,7 +62,7 @@ static int autosuspend_autosleep_disable(void)

ALOGV("autosuspend_autosleep_disable\n");

ret = write(autosleep_fd, on_state, strlen(on_state));
ret = TEMP_FAILURE_RETRY(write(autosleep_fd, on_state, strlen(on_state)));
if (ret < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error writing to %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
Expand All @@ -86,7 +86,7 @@ struct autosuspend_ops *autosuspend_autosleep_init(void)
{
char buf[80];

autosleep_fd = open(SYS_POWER_AUTOSLEEP, O_WRONLY);
autosleep_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_AUTOSLEEP, O_WRONLY));
if (autosleep_fd < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
Expand Down
18 changes: 7 additions & 11 deletions libsuspend/autosuspend_earlysuspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ int wait_for_fb_wake(void)
{
int err = 0;
char buf;
int fd = open(EARLYSUSPEND_WAIT_FOR_FB_WAKE, O_RDONLY, 0);
int fd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_WAIT_FOR_FB_WAKE, O_RDONLY, 0));
// if the file doesn't exist, the error will be caught in read() below
do {
err = read(fd, &buf, 1);
} while (err < 0 && errno == EINTR);
err = TEMP_FAILURE_RETRY(read(fd, &buf, 1));
ALOGE_IF(err < 0,
"*** ANDROID_WAIT_FOR_FB_WAKE failed (%s)", strerror(errno));
close(fd);
Expand All @@ -64,11 +62,9 @@ static int wait_for_fb_sleep(void)
{
int err = 0;
char buf;
int fd = open(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, O_RDONLY, 0);
int fd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, O_RDONLY, 0));
// if the file doesn't exist, the error will be caught in read() below
do {
err = read(fd, &buf, 1);
} while (err < 0 && errno == EINTR);
err = TEMP_FAILURE_RETRY(read(fd, &buf, 1));
ALOGE_IF(err < 0,
"*** ANDROID_WAIT_FOR_FB_SLEEP failed (%s)", strerror(errno));
close(fd);
Expand Down Expand Up @@ -134,7 +130,7 @@ static int autosuspend_earlysuspend_disable(void)

ALOGV("autosuspend_earlysuspend_disable\n");

ret = write(sPowerStatefd, pwr_state_on, strlen(pwr_state_on));
ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, pwr_state_on, strlen(pwr_state_on)));
if (ret < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
Expand Down Expand Up @@ -195,15 +191,15 @@ struct autosuspend_ops *autosuspend_earlysuspend_init(void)
char buf[80];
int ret;

sPowerStatefd = open(EARLYSUSPEND_SYS_POWER_STATE, O_RDWR);
sPowerStatefd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_SYS_POWER_STATE, O_RDWR));

if (sPowerStatefd < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGW("Error opening %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
return NULL;
}

ret = write(sPowerStatefd, "on", 2);
ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, "on", 2));
if (ret < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGW("Error writing 'on' to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
Expand Down
11 changes: 6 additions & 5 deletions libsuspend/autosuspend_wakeup_count.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
usleep(100000);
ALOGV("%s: read wakeup_count\n", __func__);
lseek(wakeup_count_fd, 0, SEEK_SET);
wakeup_count_len = read(wakeup_count_fd, wakeup_count, sizeof(wakeup_count));
wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
sizeof(wakeup_count)));
if (wakeup_count_len < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error reading from %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
Expand All @@ -72,13 +73,13 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
}

ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
ret = write(wakeup_count_fd, wakeup_count, wakeup_count_len);
ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
if (ret < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
} else {
ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
ret = write(state_fd, sleep_state, strlen(sleep_state));
ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
if (ret < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error writing to %s: %s\n", SYS_POWER_STATE, buf);
Expand Down Expand Up @@ -157,14 +158,14 @@ struct autosuspend_ops *autosuspend_wakeup_count_init(void)
int ret;
char buf[80];

state_fd = open(SYS_POWER_STATE, O_RDWR);
state_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_STATE, O_RDWR));
if (state_fd < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s: %s\n", SYS_POWER_STATE, buf);
goto err_open_state;
}

wakeup_count_fd = open(SYS_POWER_WAKEUP_COUNT, O_RDWR);
wakeup_count_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_WAKEUP_COUNT, O_RDWR));
if (wakeup_count_fd < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
Expand Down

0 comments on commit 0446e16

Please sign in to comment.