diff options
author | Gilad Arnold <garnold@google.com> | 2015-08-24 18:19:18 -0700 |
---|---|---|
committer | Gilad Arnold <garnold@google.com> | 2015-08-25 19:51:15 -0700 |
commit | 5c103d4734ef0dfa1fb2f3359d41505acd0478ca (patch) | |
tree | bd736fb612f77daa9c4ab3165ee8fef15d143f97 | |
parent | f162a324dd2c6bd9aa08741fc623d134eecbc2cf (diff) | |
download | tlsdate-5c103d4734ef0dfa1fb2f3359d41505acd0478ca.tar.gz |
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
-rw-r--r-- | src/seccomp.c | 2 | ||||
-rw-r--r-- | 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 */ @@ -23,7 +23,6 @@ #include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> -#include <sys/uio.h> #include <sys/wait.h> #include <syslog.h> #include <time.h> @@ -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) |