util/nvmutil: remove checkdir()

we don't need it. what follows is a call to open(), which
would fail anyway if the path is a directory; further, this
removes a theoretical race condition in the program, and
makes open() happen sooner, making it more likely that we
get the file first, before another program can take it.

checking whether /dev/urandom is a directory is the height
of absurdity.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-03 19:10:12 +00:00
parent 4325214d82
commit bf081914a3

View File

@@ -17,7 +17,6 @@ static void set_cmd(int, char **);
static void check_cmd_args(int, char **);
static void set_io_flags(int, char **);
static void open_files(void);
static void checkdir(const char *);
static void xopen(int *, const char *, int, struct stat *);
static void read_gbe(void);
static void read_gbe_part(int, int);
@@ -197,9 +196,6 @@ open_files(void)
struct stat st;
struct stat st_rfd;
checkdir("/dev/urandom");
checkdir(fname);
xopen(&rfd, "/dev/urandom", O_RDONLY, &st_rfd);
xopen(&fd, fname, flags, &st);
@@ -215,16 +211,6 @@ open_files(void)
}
}
static void
checkdir(const char *path)
{
struct stat st;
if (stat(path, &st) == -1)
err(ECANCELED, "%s", path);
if (S_ISDIR(st.st_mode))
err(EISDIR, "%s", path);
}
static void
xopen(int *f, const char *l, int p, struct stat *st)
{