diff options
Diffstat (limited to 'util/libreboot-utils')
| -rw-r--r-- | util/libreboot-utils/include/common.h | 1 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/file.c | 36 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/rand.c | 4 |
3 files changed, 36 insertions, 5 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index d41c4a77..d9f327ee 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -545,6 +545,7 @@ int fs_rename_at(int olddirfd, const char *old, int newdirfd, const char *new); int fs_open(const char *path, int flags); void free_and_set_null(char **buf); +void open_on_eintr(char *path, int *fd, int flags, mode_t mode); struct filesystem *rootfs(void); int fs_resolve_at(int dirfd, const char *path, int flags); int fs_next_component(const char **p, diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c index 3c7a3ba2..5d656e0e 100644 --- a/util/libreboot-utils/lib/file.c +++ b/util/libreboot-utils/lib/file.c @@ -590,6 +590,36 @@ free_and_set_null(char **buf) } void +open_on_eintr(char *path, + int *fd, int flags, mode_t mode) +{ + int r = -1; + int saved_errno = errno; + + if (path == NULL) + err_exit(EINVAL, "open_on_eintr: null path"); + + if (fd == NULL) + err_exit(EFAULT, "%s: open_on_eintr: null fd ptr", path); + + if (*fd >= 0) + err_exit(EBADF, "%s: open_on_eintr: file already open", path); + + do { + r = open(path, flags, mode); + } while (r == -1 && ( + errno == EINTR || errno == EAGAIN || + errno == EWOULDBLOCK || errno == ETXTBSY)); + + if (r < 0) + err_exit(errno, "%s: open_on_eintr: could not close", path); + + *fd = r; + + errno = saved_errno; +} + +void close_on_eintr(int *fd) { int r; @@ -672,8 +702,10 @@ rootfs(void) if (!fs_initialised) { - global_fs.rootfd = - open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC); + global_fs.rootfd = -1; + + open_on_eintr("/", &global_fs.rootfd, + O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0400); if (global_fs.rootfd < 0) return NULL; diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c index 99da713c..030ca5ec 100644 --- a/util/libreboot-utils/lib/rand.c +++ b/util/libreboot-utils/lib/rand.c @@ -142,9 +142,7 @@ rset(void *buf, size_t n) #if defined(USE_URANDOM) && \ ((USE_URANDOM) > 0) int fd = -1; - - if ((fd = open("/dev/urandom", O_RDONLY)) < 0) - goto err; + open_on_eintr("/dev/urandom", &fd, O_RDONLY, 0400); retry_rand: if ((rc = read(fd, (unsigned char *)buf + off, n - off)) < 0) { #elif defined(__linux__) |
