libreboot-utils: unified error handling

i now use a singleton hook function per program:
nvmutil, mkhtemp and lottery

call this at the startup of your program:

(void) errhook(exit_cleanup);

then provide that function. make it static,
so that each program has its own version.

if you're writing a program that handles lots
of files for example, and you want to do certain
cleanup on exit (including error exit), this can
be quite useful.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-28 06:53:37 +00:00
parent 55f0e6ac8e
commit 0f1a22174f
14 changed files with 182 additions and 186 deletions
+7 -6
View File
@@ -225,10 +225,12 @@ int fchmod(int fd, mode_t mode);
/* command table
*/
typedef void (*func_t)(void);
struct commands {
size_t chk;
char *str;
void (*run)(void);
func_t run;
int argc;
unsigned char arg_part;
unsigned char chksum_read;
@@ -488,12 +490,11 @@ int try_err(int loop_err, int errval);
*/
void usage(void);
void err_no_cleanup(int stfu, int nvm_errval, const char *msg, ...);
void b0rk(int nvm_errval, const char *msg, ...);
int exit_cleanup(void);
void err_exit(int nvm_errval, const char *msg, ...);
func_t errhook(func_t ptr); /* hook function for cleanup on err */
const char *getnvmprogname(void);
void err_mkhtemp(int stfu, int errval, const char *msg, ...);
void no_op(void);
void err_mkhtemp(int errval, const char *msg, ...);
/* libc hardening
*/