util/nvmutil: merge block_unveil back with main

we always want unveil/pledge calls to be in main, when
possible, so that they are more transparent and easier
to understand when re-factoring, because it's extremely
important that these syscalls be done correctly.

main is small enough now, from other re-factoring changes,
that i'm happy to have this back in main now.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-02 22:29:11 +00:00
parent 589ac92781
commit 761968e3c4
+9 -21
View File
@@ -25,10 +25,6 @@ int goodChecksum(int partnum);
uint8_t hextonum(char chs), rhex(void);
uint16_t word(int, int);
#ifdef __OpenBSD__
void block_unveil(void);
#endif
#define COMMAND argv[2]
#define MAC_ADDRESS argv[3]
#define PARTN argv[3]
@@ -86,7 +82,15 @@ main(int argc, char *argv[])
fname = argv[1];
set_io_flags(argc, argv);
#ifdef __OpenBSD__
block_unveil();
if (flags == O_RDONLY) {
err_if(unveil(fname, "r") == -1);
err_if(unveil(NULL, NULL) == -1);
err_if(pledge("stdio rpath", NULL) == -1);
} else {
err_if(unveil(fname, "rw") == -1);
err_if(unveil(NULL, NULL) == -1);
err_if(pledge("stdio rpath wpath", NULL) == -1);
}
#endif
openFiles(fname);
#ifdef __OpenBSD__
@@ -461,22 +465,6 @@ swap(int partnum)
}
}
#ifdef __OpenBSD__
void
block_unveil(void)
{
if (flags == O_RDONLY) {
err_if(unveil(fname, "r") == -1);
err_if(unveil(NULL, NULL) == -1);
err_if(pledge("stdio rpath", NULL) == -1);
} else {
err_if(unveil(fname, "rw") == -1);
err_if(unveil(NULL, NULL) == -1);
err_if(pledge("stdio rpath wpath", NULL) == -1);
}
}
#endif
void
usage(char *util)
{