summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Brown2015-05-15 16:56:03 -0500
committerJeff Brown2015-05-18 17:53:56 -0500
commit0446e16f5333977810dec3a33c1af89d1f61d2de (patch)
tree7761c6f8cfe532f6df5f27740d10d110d68a1e6e /libsuspend
parenta51d8b9a1c06a17b8d5d5fd9547a3bf813ea4157 (diff)
downloadplatform-system-core-0446e16f5333977810dec3a33c1af89d1f61d2de.tar.gz
platform-system-core-0446e16f5333977810dec3a33c1af89d1f61d2de.tar.xz
platform-system-core-0446e16f5333977810dec3a33c1af89d1f61d2de.zip
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
Diffstat (limited to 'libsuspend')
-rw-r--r--libsuspend/autosuspend_autosleep.c6
-rw-r--r--libsuspend/autosuspend_earlysuspend.c18
-rw-r--r--libsuspend/autosuspend_wakeup_count.c11
3 files changed, 16 insertions, 19 deletions
diff --git a/libsuspend/autosuspend_autosleep.c b/libsuspend/autosuspend_autosleep.c
index 0d31e741e..7262cc7e8 100644
--- a/libsuspend/autosuspend_autosleep.c
+++ b/libsuspend/autosuspend_autosleep.c
@@ -40,7 +40,7 @@ static int autosuspend_autosleep_enable(void)
40 40
41 ALOGV("autosuspend_autosleep_enable\n"); 41 ALOGV("autosuspend_autosleep_enable\n");
42 42
43 ret = write(autosleep_fd, sleep_state, strlen(sleep_state)); 43 ret = TEMP_FAILURE_RETRY(write(autosleep_fd, sleep_state, strlen(sleep_state)));
44 if (ret < 0) { 44 if (ret < 0) {
45 strerror_r(errno, buf, sizeof(buf)); 45 strerror_r(errno, buf, sizeof(buf));
46 ALOGE("Error writing to %s: %s\n", SYS_POWER_AUTOSLEEP, buf); 46 ALOGE("Error writing to %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
@@ -62,7 +62,7 @@ static int autosuspend_autosleep_disable(void)
62 62
63 ALOGV("autosuspend_autosleep_disable\n"); 63 ALOGV("autosuspend_autosleep_disable\n");
64 64
65 ret = write(autosleep_fd, on_state, strlen(on_state)); 65 ret = TEMP_FAILURE_RETRY(write(autosleep_fd, on_state, strlen(on_state)));
66 if (ret < 0) { 66 if (ret < 0) {
67 strerror_r(errno, buf, sizeof(buf)); 67 strerror_r(errno, buf, sizeof(buf));
68 ALOGE("Error writing to %s: %s\n", SYS_POWER_AUTOSLEEP, buf); 68 ALOGE("Error writing to %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
@@ -86,7 +86,7 @@ struct autosuspend_ops *autosuspend_autosleep_init(void)
86{ 86{
87 char buf[80]; 87 char buf[80];
88 88
89 autosleep_fd = open(SYS_POWER_AUTOSLEEP, O_WRONLY); 89 autosleep_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_AUTOSLEEP, O_WRONLY));
90 if (autosleep_fd < 0) { 90 if (autosleep_fd < 0) {
91 strerror_r(errno, buf, sizeof(buf)); 91 strerror_r(errno, buf, sizeof(buf));
92 ALOGE("Error opening %s: %s\n", SYS_POWER_AUTOSLEEP, buf); 92 ALOGE("Error opening %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
diff --git a/libsuspend/autosuspend_earlysuspend.c b/libsuspend/autosuspend_earlysuspend.c
index 2bece4c3b..3793a699e 100644
--- a/libsuspend/autosuspend_earlysuspend.c
+++ b/libsuspend/autosuspend_earlysuspend.c
@@ -49,11 +49,9 @@ int wait_for_fb_wake(void)
49{ 49{
50 int err = 0; 50 int err = 0;
51 char buf; 51 char buf;
52 int fd = open(EARLYSUSPEND_WAIT_FOR_FB_WAKE, O_RDONLY, 0); 52 int fd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_WAIT_FOR_FB_WAKE, O_RDONLY, 0));
53 // if the file doesn't exist, the error will be caught in read() below 53 // if the file doesn't exist, the error will be caught in read() below
54 do { 54 err = TEMP_FAILURE_RETRY(read(fd, &buf, 1));
55 err = read(fd, &buf, 1);
56 } while (err < 0 && errno == EINTR);
57 ALOGE_IF(err < 0, 55 ALOGE_IF(err < 0,
58 "*** ANDROID_WAIT_FOR_FB_WAKE failed (%s)", strerror(errno)); 56 "*** ANDROID_WAIT_FOR_FB_WAKE failed (%s)", strerror(errno));
59 close(fd); 57 close(fd);
@@ -64,11 +62,9 @@ static int wait_for_fb_sleep(void)
64{ 62{
65 int err = 0; 63 int err = 0;
66 char buf; 64 char buf;
67 int fd = open(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, O_RDONLY, 0); 65 int fd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, O_RDONLY, 0));
68 // if the file doesn't exist, the error will be caught in read() below 66 // if the file doesn't exist, the error will be caught in read() below
69 do { 67 err = TEMP_FAILURE_RETRY(read(fd, &buf, 1));
70 err = read(fd, &buf, 1);
71 } while (err < 0 && errno == EINTR);
72 ALOGE_IF(err < 0, 68 ALOGE_IF(err < 0,
73 "*** ANDROID_WAIT_FOR_FB_SLEEP failed (%s)", strerror(errno)); 69 "*** ANDROID_WAIT_FOR_FB_SLEEP failed (%s)", strerror(errno));
74 close(fd); 70 close(fd);
@@ -134,7 +130,7 @@ static int autosuspend_earlysuspend_disable(void)
134 130
135 ALOGV("autosuspend_earlysuspend_disable\n"); 131 ALOGV("autosuspend_earlysuspend_disable\n");
136 132
137 ret = write(sPowerStatefd, pwr_state_on, strlen(pwr_state_on)); 133 ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, pwr_state_on, strlen(pwr_state_on)));
138 if (ret < 0) { 134 if (ret < 0) {
139 strerror_r(errno, buf, sizeof(buf)); 135 strerror_r(errno, buf, sizeof(buf));
140 ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf); 136 ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
@@ -195,7 +191,7 @@ struct autosuspend_ops *autosuspend_earlysuspend_init(void)
195 char buf[80]; 191 char buf[80];
196 int ret; 192 int ret;
197 193
198 sPowerStatefd = open(EARLYSUSPEND_SYS_POWER_STATE, O_RDWR); 194 sPowerStatefd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_SYS_POWER_STATE, O_RDWR));
199 195
200 if (sPowerStatefd < 0) { 196 if (sPowerStatefd < 0) {
201 strerror_r(errno, buf, sizeof(buf)); 197 strerror_r(errno, buf, sizeof(buf));
@@ -203,7 +199,7 @@ struct autosuspend_ops *autosuspend_earlysuspend_init(void)
203 return NULL; 199 return NULL;
204 } 200 }
205 201
206 ret = write(sPowerStatefd, "on", 2); 202 ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, "on", 2));
207 if (ret < 0) { 203 if (ret < 0) {
208 strerror_r(errno, buf, sizeof(buf)); 204 strerror_r(errno, buf, sizeof(buf));
209 ALOGW("Error writing 'on' to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf); 205 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 7483a8fb2..ee4ebe74a 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -51,7 +51,8 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
51 usleep(100000); 51 usleep(100000);
52 ALOGV("%s: read wakeup_count\n", __func__); 52 ALOGV("%s: read wakeup_count\n", __func__);
53 lseek(wakeup_count_fd, 0, SEEK_SET); 53 lseek(wakeup_count_fd, 0, SEEK_SET);
54 wakeup_count_len = read(wakeup_count_fd, wakeup_count, sizeof(wakeup_count)); 54 wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
55 sizeof(wakeup_count)));
55 if (wakeup_count_len < 0) { 56 if (wakeup_count_len < 0) {
56 strerror_r(errno, buf, sizeof(buf)); 57 strerror_r(errno, buf, sizeof(buf));
57 ALOGE("Error reading from %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf); 58 ALOGE("Error reading from %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
@@ -72,13 +73,13 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
72 } 73 }
73 74
74 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count); 75 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
75 ret = write(wakeup_count_fd, wakeup_count, wakeup_count_len); 76 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
76 if (ret < 0) { 77 if (ret < 0) {
77 strerror_r(errno, buf, sizeof(buf)); 78 strerror_r(errno, buf, sizeof(buf));
78 ALOGE("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf); 79 ALOGE("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
79 } else { 80 } else {
80 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE); 81 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
81 ret = write(state_fd, sleep_state, strlen(sleep_state)); 82 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
82 if (ret < 0) { 83 if (ret < 0) {
83 strerror_r(errno, buf, sizeof(buf)); 84 strerror_r(errno, buf, sizeof(buf));
84 ALOGE("Error writing to %s: %s\n", SYS_POWER_STATE, buf); 85 ALOGE("Error writing to %s: %s\n", SYS_POWER_STATE, buf);
@@ -157,14 +158,14 @@ struct autosuspend_ops *autosuspend_wakeup_count_init(void)
157 int ret; 158 int ret;
158 char buf[80]; 159 char buf[80];
159 160
160 state_fd = open(SYS_POWER_STATE, O_RDWR); 161 state_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_STATE, O_RDWR));
161 if (state_fd < 0) { 162 if (state_fd < 0) {
162 strerror_r(errno, buf, sizeof(buf)); 163 strerror_r(errno, buf, sizeof(buf));
163 ALOGE("Error opening %s: %s\n", SYS_POWER_STATE, buf); 164 ALOGE("Error opening %s: %s\n", SYS_POWER_STATE, buf);
164 goto err_open_state; 165 goto err_open_state;
165 } 166 }
166 167
167 wakeup_count_fd = open(SYS_POWER_WAKEUP_COUNT, O_RDWR); 168 wakeup_count_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_WAKEUP_COUNT, O_RDWR));
168 if (wakeup_count_fd < 0) { 169 if (wakeup_count_fd < 0) {
169 strerror_r(errno, buf, sizeof(buf)); 170 strerror_r(errno, buf, sizeof(buf));
170 ALOGE("Error opening %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf); 171 ALOGE("Error opening %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);