util/nvmutil: always print filename in err_if

the previous code size optimisations removed mention
of the file name, on file-related err() calls.

almost every error the user runs across will be file
related, so put the path on err() called from err_if()

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2023-09-18 16:42:49 +01:00
parent 9a92524a47
commit 0897a0be17
+5 -5
View File
@@ -31,7 +31,6 @@ void setWord(int pos16, int partnum, uint16_t val16);
void xorswap_buf(int partnum); void xorswap_buf(int partnum);
void writeGbeFile(void); void writeGbeFile(void);
#define FILENAME argv[1]
#define COMMAND argv[2] #define COMMAND argv[2]
#define MAC_ADDRESS argv[3] #define MAC_ADDRESS argv[3]
#define PARTNUM argv[3] #define PARTNUM argv[3]
@@ -43,7 +42,7 @@ size_t nf = 128, gbe[2];
uint8_t nvmPartModified[2] = {0, 0}, skipread[2] = {0, 0}; uint8_t nvmPartModified[2] = {0, 0}, skipread[2] = {0, 0};
int endian = 1, flags = O_RDWR, rfd, fd, part, gbeFileModified = 0; int endian = 1, flags = O_RDWR, rfd, fd, part, gbeFileModified = 0;
const char *strMac = NULL, *strRMac = "??:??:??:??:??:??"; const char *strMac = NULL, *strRMac = "??:??:??:??:??:??", *filename = NULL;
typedef struct op { typedef struct op {
char *str; char *str;
@@ -61,7 +60,7 @@ op_t op[] = {
void (*cmd)(void) = NULL; void (*cmd)(void) = NULL;
#define ERR() errno = errno ? errno : ECANCELED #define ERR() errno = errno ? errno : ECANCELED
#define err_if(x) if (x) err(ERR(), NULL) #define err_if(x) if (x) err(ERR(), "%s", filename)
#define xopen(f,l,p) if (opendir(l) != NULL) err(errno = EISDIR, "%s", l); \ #define xopen(f,l,p) if (opendir(l) != NULL) err(errno = EISDIR, "%s", l); \
if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \ if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \
@@ -76,13 +75,14 @@ main(int argc, char *argv[])
{ {
err_if((errno = argc < 3 ? EINVAL : errno)); err_if((errno = argc < 3 ? EINVAL : errno));
flags = (strcmp(COMMAND, "dump") == 0) ? O_RDONLY : flags; flags = (strcmp(COMMAND, "dump") == 0) ? O_RDONLY : flags;
filename = argv[1];
#ifdef __OpenBSD__ #ifdef __OpenBSD__
err_if(unveil("/dev/urandom", "r") == -1); err_if(unveil("/dev/urandom", "r") == -1);
err_if(unveil(FILENAME, flags == O_RDONLY ? "r" : "rw") == -1); err_if(unveil(filename, flags == O_RDONLY ? "r" : "rw") == -1);
err_if(pledge(flags == O_RDONLY ? "stdio rpath" : "stdio rpath wpath", err_if(pledge(flags == O_RDONLY ? "stdio rpath" : "stdio rpath wpath",
NULL) == -1); NULL) == -1);
#endif #endif
openFiles(FILENAME); openFiles(filename);
#ifdef __OpenBSD__ #ifdef __OpenBSD__
err_if(pledge("stdio", NULL) == -1); err_if(pledge("stdio", NULL) == -1);
#endif #endif