summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/libreboot-utils/include/common.h1
-rw-r--r--util/libreboot-utils/lib/file.c36
-rw-r--r--util/libreboot-utils/lib/rand.c14
3 files changed, 29 insertions, 22 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h
index f249e6a5..d08828df 100644
--- a/util/libreboot-utils/include/common.h
+++ b/util/libreboot-utils/include/common.h
@@ -465,7 +465,6 @@ int io_args(int fd, void *mem, size_t nrw,
off_t off, int rw_type);
int check_file(int fd, struct stat *st);
ssize_t rw_over_nrw(ssize_t r, size_t nrw);
-int off_retry(int saved_errno, off_t rval);
int sys_retry(int saved_errno, long rval);
int fs_retry(int saved_errno, int rval);
int rw_retry(int saved_errno, ssize_t rval);
diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c
index 986bf788..efc23ba9 100644
--- a/util/libreboot-utils/lib/file.c
+++ b/util/libreboot-utils/lib/file.c
@@ -717,9 +717,29 @@ xclose(int *fd)
if (*fd < 0)
return;
+ /* nuance regarding EINTR on close():
+ * EINTR can be set on error, but there's
+ * no guarantee whether the fd is then still
+ * open or closed. on some other commands, we
+ * loop EINTR, but for close, we instead skip
+ * aborting *if the errno is EINTR* - so don't
+ * loop it, but do regard EINTR with rval -1
+ * as essenitally a successful close()
+ */
+
+ /* because we don't want to mess with someone
+ * elses file if that fd is then reassigned.
+ * if the operation truly did fail, we ignore
+ * it. just leave it flying in the wind */
+
errno = 0;
- if ((rval = close(*fd)) < 0)
- exitf("xclose: could not close");
+ if ((rval = close(*fd)) < 0) {
+ if (errno != EINTR)
+ exitf("xclose: could not close");
+
+ /* regard EINTR as a successful close */
+ rval = 0;
+ }
*fd = -1;
@@ -762,18 +782,6 @@ xclose(int *fd)
*/
-/* retry switch for offset-based
- * functions e.g. lseek
- */
-/* retry switch for functions that
- return long status e.g. linux syscall
- */
-int
-off_retry(int saved_errno, off_t rval)
-{
- fs_err_retry();
-}
-
/* retry switch for functions that
return long status e.g. linux syscall
*/
diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c
index 153798f6..bf090b43 100644
--- a/util/libreboot-utils/lib/rand.c
+++ b/util/libreboot-utils/lib/rand.c
@@ -156,24 +156,24 @@ retry_rand: {
#if defined(USE_URANDOM) && \
((USE_URANDOM) > 0)
- ssize_t rc;
+ ssize_t rval;
int fd = -1;
open_file_on_eintr("/dev/urandom", &fd, O_RDONLY, 0400, NULL);
while (rw_retry(saved_errno,
- rc = rw(fd, (unsigned char *)buf + off, n - off, 0, IO_READ)));
+ rval = rw(fd, (unsigned char *)buf + off, n - off, 0, IO_READ)));
#elif defined(__linux__)
- long rc;
+ long rval;
while (sys_retry(saved_errno,
- rc = syscall(SYS_getrandom,
+ rval = syscall(SYS_getrandom,
(unsigned char *)buf + off, n - off, 0)));
#else
#error Unsupported operating system (possibly unsecure randomisation)
#endif
- if (rc < 0 || /* syscall fehler */
- rc == 0) { /* prevent infinite loop on fatal err */
+ if (rval < 0 || /* syscall fehler */
+ rval == 0) { /* prevent infinite loop on fatal err */
#if defined(USE_URANDOM) && \
((USE_URANDOM) > 0)
xclose(&fd);
@@ -181,7 +181,7 @@ retry_rand: {
goto err;
}
- if ((off += (size_t)rc) < n)
+ if ((off += (size_t)rval) < n)
goto retry_rand;
#if defined(USE_URANDOM) && \