mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-15 08:20:59 +02:00
util/nvmutil: close files in err()
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+21
-11
@@ -81,6 +81,7 @@ static int xstrxcmp(const char *a, const char *b, size_t maxlen);
|
|||||||
static void err(int nvm_errval, const char *msg, ...);
|
static void err(int nvm_errval, const char *msg, ...);
|
||||||
static const char *getnvmprogname(void);
|
static const char *getnvmprogname(void);
|
||||||
static void set_err(int errval);
|
static void set_err(int errval);
|
||||||
|
static void close_files(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sizes in bytes:
|
* Sizes in bytes:
|
||||||
@@ -372,17 +373,7 @@ main(int argc, char *argv[])
|
|||||||
else if (gbe_flags != O_RDONLY)
|
else if (gbe_flags != O_RDONLY)
|
||||||
write_gbe_file();
|
write_gbe_file();
|
||||||
|
|
||||||
if (gbe_fd > -1) {
|
close_files();
|
||||||
if (close(gbe_fd) == -1)
|
|
||||||
err(ECANCELED, "close '%s'", fname);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef HAVE_ARC4RANDOM_BUF
|
|
||||||
if (urandom_fd > -1) {
|
|
||||||
if (close(urandom_fd) == -1)
|
|
||||||
err(ECANCELED, "close '%s'", rname);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (errno)
|
if (errno)
|
||||||
err(ECANCELED, "Unhandled error on exit");
|
err(ECANCELED, "Unhandled error on exit");
|
||||||
@@ -1345,6 +1336,9 @@ xstrxcmp(const char *a, const char *b, size_t maxlen)
|
|||||||
static void
|
static void
|
||||||
err(int nvm_errval, const char *msg, ...)
|
err(int nvm_errval, const char *msg, ...)
|
||||||
{
|
{
|
||||||
|
if (nvm_errval != -1)
|
||||||
|
close_files();
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
fprintf(stderr, "%s: ", getnvmprogname());
|
fprintf(stderr, "%s: ", getnvmprogname());
|
||||||
@@ -1386,3 +1380,19 @@ set_err(int x)
|
|||||||
else
|
else
|
||||||
errno = ECANCELED;
|
errno = ECANCELED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
close_files(void)
|
||||||
|
{
|
||||||
|
if (gbe_fd > -1) {
|
||||||
|
if (close(gbe_fd) == -1)
|
||||||
|
err(-1, "close '%s'", fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_ARC4RANDOM_BUF
|
||||||
|
if (urandom_fd > -1) {
|
||||||
|
if (close(urandom_fd) == -1)
|
||||||
|
err(-1, "close '%s'", rname);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user