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/io.c4
-rw-r--r--util/libreboot-utils/lib/mkhtemp.c8
-rw-r--r--util/libreboot-utils/lib/rand.c14
5 files changed, 32 insertions, 31 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/io.c b/util/libreboot-utils/lib/io.c
index 5a1b121d..6bfbbf51 100644
--- a/util/libreboot-utils/lib/io.c
+++ b/util/libreboot-utils/lib/io.c
@@ -48,9 +48,7 @@ open_gbe_file(void)
if (f->gbe_st.st_nlink == 0)
exitf("%s: file unlinked while open", f->fname);
- while (fs_retry(saved_errno,
- _flags = fcntl(f->gbe_fd, F_GETFL)));
- if (_flags == -1)
+ if ((_flags = fcntl(f->gbe_fd, F_GETFL)) == -1)
exitf("%s: fcntl(F_GETFL)", f->fname);
/* O_APPEND allows POSIX write() to ignore
diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c
index 8591e817..bb714b82 100644
--- a/util/libreboot-utils/lib/mkhtemp.c
+++ b/util/libreboot-utils/lib/mkhtemp.c
@@ -752,9 +752,7 @@ int secure_file(int *fd,
if_err(*fd < 0, EBADF))
goto err_demons;
- while (fs_retry(saved_errno,
- flags = fcntl(*fd, F_GETFL)));
- if (flags == -1)
+ if ((flags = fcntl(*fd, F_GETFL)) == -1)
goto err_demons;
if (if_err(bad_flags > 0 && (flags & bad_flags), EPERM))
@@ -899,9 +897,7 @@ lock_file(int fd, int flags)
fl.l_whence = SEEK_SET;
- while (fs_retry(saved_errno,
- fcntl_rval = fcntl(fd, F_SETLK, &fl)));
- if (fcntl_rval == -1)
+ if ((fcntl_rval = fcntl(fd, F_SETLK, &fl)) == -1)
goto err_lock_file;
reset_caller_errno(0);
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) && \