---
src/booleans.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 46 insertions(+), 6 deletions(-)
diff --git a/src/booleans.c b/src/booleans.c
index 60bf963..5f312be 100644
--- a/src/booleans.c
+++ b/src/booleans.c
@@ -33,6 +33,46 @@ static int filename_select(const struct dirent *d)
return 1;
}
+static int readx(int fd, void *_buf, size_t count)
+{
+ char *buf = _buf;
+ size_t n = 0, r;
+
+ if (count < 0)
+ return -1;
+ while (n < count) {
+ r = read(fd, buf + n, count -n);
+ if (r < 0) {
+ if (errno == EINTR)
+ continue;
+ return -1;
+ }
+ if (r == 0)
+ return 0; /* EOF */
+ n += r;
+ }
+ return 0;
+}
+
+static int writex(int fd, const void *_buf, size_t count)
+{
+ const char *buf = _buf;
+ size_t n = 0, r;
+
+ if (count < 0)
+ return -1;
+ while (n < count) {
+ r = write(fd, buf + n, count -n);
+ if (r < 0) {
+ if (errno == EINTR)
+ continue;
+ return -1;
+ }
+ n += r;
+ }
+ return 0;
+}
+
int security_get_boolean_names(char ***names, int *len)
{
char path[PATH_MAX];
@@ -108,9 +148,9 @@ static int get_bool_value(const char *name, char **buf)
if (fd < 0)
goto out;
- len = read(fd, *buf, STRBUF_SIZE);
+ len = readx(fd, *buf, STRBUF_SIZE);
close(fd);
- if (len != STRBUF_SIZE)
+ if (len < 0)
goto out;
free(fname);
@@ -190,11 +230,11 @@ int security_set_boolean(const char *name, int value)
buf[0] = '0';
buf[1] = '\0';
- ret = write(fd, buf, 2);
+ ret = writex(fd, buf, 2);
close(fd);
out:
free(fname);
- if (ret > 0)
+ if (ret == 0)
return 0;
else
return -1;
@@ -221,10 +261,10 @@ int security_commit_booleans(void)
buf[0] = '1';
buf[1] = '\0';
- ret = write(fd, buf, 2);
+ ret = writex(fd, buf, 2);
close(fd);
- if (ret > 0)
+ if (ret == 0)
return 0;
else
return -1;
--
1.7.9.5
--
This message was distributed to subscribers of the seandroid-list mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe seandroid-list" without quotes as the message.