Add TEMP_FAILURE_RETRY to libsuspend.
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
diff --git a/libsuspend/autosuspend_autosleep.c b/libsuspend/autosuspend_autosleep.c
index 0d31e74..7262cc7 100644
--- a/libsuspend/autosuspend_autosleep.c
+++ b/libsuspend/autosuspend_autosleep.c
@@ -40,7 +40,7 @@
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);
@@ -62,7 +62,7 @@
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);
@@ -86,7 +86,7 @@
{
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);
diff --git a/libsuspend/autosuspend_earlysuspend.c b/libsuspend/autosuspend_earlysuspend.c
index 2bece4c..3793a69 100644
--- a/libsuspend/autosuspend_earlysuspend.c
+++ b/libsuspend/autosuspend_earlysuspend.c
@@ -49,11 +49,9 @@
{
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);
@@ -64,11 +62,9 @@
{
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);
@@ -134,7 +130,7 @@
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);
@@ -195,7 +191,7 @@
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));
@@ -203,7 +199,7 @@
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);
diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c
index 7483a8f..ee4ebe7 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -51,7 +51,8 @@
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);
@@ -72,13 +73,13 @@
}
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);
@@ -157,14 +158,14 @@
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);