diff options
Diffstat (limited to 'util/libreboot-utils/lib')
| -rw-r--r-- | util/libreboot-utils/lib/file.c | 36 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/rand.c | 14 |
2 files changed, 29 insertions, 21 deletions
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) && \ |
