mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
lbutils: unify xopen and open_on_eintr
use open_on_eintr for gbe files Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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__)
|
||||
|
||||
Reference in New Issue
Block a user