diff options
Diffstat (limited to 'util')
| -rw-r--r-- | util/libreboot-utils/include/common.h | 4 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/file.c | 34 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/io.c | 12 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/rand.c | 2 |
4 files changed, 27 insertions, 25 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index e8252d4b..1932b2da 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -346,7 +346,6 @@ int fd_verify_dir_identity(int fd, int is_owner(struct stat *st); int lock_file(int fd, int flags); int same_file(int fd, struct stat *st_old, int check_size); -void xopen(int *fd, const char *path, int flags, struct stat *st); /* Read GbE file and verify checksums */ @@ -546,7 +545,8 @@ 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); +void open_on_eintr(const char *path, int *fd, int flags, mode_t mode, + struct stat *st); 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 96654640..4623748c 100644 --- a/util/libreboot-utils/lib/file.c +++ b/util/libreboot-utils/lib/file.c @@ -65,22 +65,6 @@ err_same_file: return set_errno(saved_errno, ESTALE); } -void -xopen(int *fd_ptr, const char *path, int flags, struct stat *st) -{ - if ((*fd_ptr = open(path, flags)) < 0) - err_exit(errno, "%s", path); - - if (fstat(*fd_ptr, st) < 0) - err_exit(errno, "%s: stat", path); - - if (!S_ISREG(st->st_mode)) - err_exit(errno, "%s: not a regular file", path); - - if (lseek_on_eintr(*fd_ptr, 0, SEEK_CUR, 1, 1) == (off_t)-1) - err_exit(errno, "%s: file not seekable", path); -} - int fsync_dir(const char *path) { @@ -568,8 +552,9 @@ free_and_set_null(char **buf) } void -open_on_eintr(char *path, - int *fd, int flags, mode_t mode) +open_on_eintr(const char *path, + int *fd, int flags, mode_t mode, + struct stat *st) { int r = -1; int saved_errno = errno; @@ -594,6 +579,17 @@ open_on_eintr(char *path, *fd = r; + if (st != NULL) { + if (fstat(*fd, st) < 0) + err_exit(errno, "%s: stat", path); + + if (!S_ISREG(st->st_mode)) + err_exit(errno, "%s: not a regular file", path); + } + + if (lseek_on_eintr(*fd, 0, SEEK_CUR, 1, 1) == (off_t)-1) + err_exit(errno, "%s: file not seekable", path); + errno = saved_errno; } @@ -683,7 +679,7 @@ rootfs(void) global_fs.rootfd = -1; open_on_eintr("/", &global_fs.rootfd, - O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0400); + O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0400, NULL); if (global_fs.rootfd < 0) return NULL; diff --git a/util/libreboot-utils/lib/io.c b/util/libreboot-utils/lib/io.c index d3f5733d..a09e3992 100644 --- a/util/libreboot-utils/lib/io.c +++ b/util/libreboot-utils/lib/io.c @@ -27,9 +27,12 @@ open_gbe_file(void) int _flags; - xopen(&f->gbe_fd, f->fname, - cmd->flags | O_BINARY | - O_NOFOLLOW | O_CLOEXEC | O_NOCTTY, &f->gbe_st); + f->gbe_fd = -1; + + open_on_eintr(f->fname, &f->gbe_fd, + O_NOFOLLOW | O_CLOEXEC | O_NOCTTY, + ((cmd->flags & O_ACCMODE) == O_RDONLY) ? 0400 : 0600, + &f->gbe_st); if (f->gbe_st.st_nlink > 1) err_exit(EINVAL, @@ -62,8 +65,11 @@ open_gbe_file(void) err_exit(EINVAL, "File size must be 8KB, 16KB or 128KB"); } +/* currently fails (EBADF), locks are advisory anyway: */ +/* if (lock_file(f->gbe_fd, cmd->flags) == -1) err_exit(errno, "%s: can't lock", f->fname); +*/ } void diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c index 030ca5ec..9edc8a5b 100644 --- a/util/libreboot-utils/lib/rand.c +++ b/util/libreboot-utils/lib/rand.c @@ -142,7 +142,7 @@ rset(void *buf, size_t n) #if defined(USE_URANDOM) && \ ((USE_URANDOM) > 0) int fd = -1; - open_on_eintr("/dev/urandom", &fd, O_RDONLY, 0400); + open_on_eintr("/dev/urandom", &fd, O_RDONLY, 0400, NULL); retry_rand: if ((rc = read(fd, (unsigned char *)buf + off, n - off)) < 0) { #elif defined(__linux__) |
