mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-19 19:23:24 +02:00
util/nvmutil: lock gbe file
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -253,6 +253,7 @@ static int xstrxcmp(const char *a, const char *b, size_t maxlen);
|
|||||||
*/
|
*/
|
||||||
static void open_dev_urandom(void);
|
static void open_dev_urandom(void);
|
||||||
static void open_gbe_file(void);
|
static void open_gbe_file(void);
|
||||||
|
static void lock_gbe_file(void);
|
||||||
static void xopen(int *fd, const char *path, int flags, struct stat *st);
|
static void xopen(int *fd, const char *path, int flags, struct stat *st);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -652,6 +653,7 @@ main(int argc, char *argv[])
|
|||||||
open_dev_urandom();
|
open_dev_urandom();
|
||||||
|
|
||||||
open_gbe_file();
|
open_gbe_file();
|
||||||
|
lock_gbe_file();
|
||||||
|
|
||||||
#ifdef NVMUTIL_PLEDGE
|
#ifdef NVMUTIL_PLEDGE
|
||||||
if (pledge("stdio", NULL) == -1)
|
if (pledge("stdio", NULL) == -1)
|
||||||
@@ -880,6 +882,24 @@ open_gbe_file(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
lock_gbe_file(void)
|
||||||
|
{
|
||||||
|
struct flock fl;
|
||||||
|
|
||||||
|
memset(&fl, 0, sizeof(fl));
|
||||||
|
|
||||||
|
if (command[cmd_index].flags == O_RDONLY)
|
||||||
|
fl.l_type = F_RDLCK;
|
||||||
|
else
|
||||||
|
fl.l_type = F_WRLCK;
|
||||||
|
|
||||||
|
fl.l_whence = SEEK_SET;
|
||||||
|
|
||||||
|
if (fcntl(gbe_fd, F_SETLK, &fl) == -1)
|
||||||
|
err(errno, "file is locked by another process");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xopen(int *fd_ptr, const char *path, int flags, struct stat *st)
|
xopen(int *fd_ptr, const char *path, int flags, struct stat *st)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user