From 5c103d4734ef0dfa1fb2f3359d41505acd0478ca Mon Sep 17 00:00:00 2001 From: Gilad Arnold Date: Mon, 24 Aug 2015 18:19:18 -0700 Subject: Stop using preadv/pwritev. These are non-standard functions that may not be supported in all environments. We replace them with pread/pwrite, which provide similar atomicity and side-effect semantics, and are also simpler to use. This also adds EINTR protection around pread. Bug: 22373707 Change-Id: I78d813c14a958747ed5750e6d00c1ee8fe8031ad --- src/seccomp.c | 2 +- src/util.c | 25 ++++--------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/seccomp.c b/src/seccomp.c index fbc5a33..9f9a5fe 100644 --- a/src/seccomp.c +++ b/src/seccomp.c @@ -72,7 +72,7 @@ enable_setter_seccomp (void) /* Process ALLOWs as quickly as possible */ SC_ALLOW (read), SC_ALLOW (write), - SC_ALLOW (pwritev), + SC_ALLOW (pwrite64), SC_ALLOW (settimeofday), SC_ALLOW (ioctl), /* TODO(wad) filter for fd and RTC_SET_TIME */ diff --git a/src/util.c b/src/util.c index 6bb279c..71ed0d6 100644 --- a/src/util.c +++ b/src/util.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -286,16 +285,8 @@ int rtc_close(struct rtc_handle *handle) int file_write(int fd, void *buf, size_t sz) { - struct iovec iov[1]; - ssize_t ret; - iov[0].iov_base = buf; - iov[0].iov_len = sz; - ret = IGNORE_EINTR (pwritev (fd, iov, 1, 0)); - if (ret != sz) - { - return -1; - } - return 0; + ssize_t ret = IGNORE_EINTR (pwrite (fd, buf, sz, 0)); + return (ret >= 0 && ((size_t) ret) == sz ? 0 : -1); } int file_open(const char *path, int write, int cloexec) @@ -329,16 +320,8 @@ int file_close(int fd) int file_read(int fd, void *buf, size_t sz) { - struct iovec iov[1]; - iov[0].iov_base = buf; - iov[0].iov_len = sz; - if (preadv (fd, iov, 1, 0) != sz) - { - /* Returns -1 on read failure */ - return -1; - } - /* Returns 0 on a successful buffer fill. */ - return 0; + ssize_t ret = IGNORE_EINTR (pread (fd, buf, sz, 0)); + return (ret >= 0 && ((size_t) ret) == sz ? 0 : -1); } int time_get(struct timeval *tv) -- cgit v1.2.3