From 0f1a22174fc7c6a0767617974640d521074174d5 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 28 Mar 2026 06:53:37 +0000 Subject: 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 --- util/libreboot-utils/include/common.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'util/libreboot-utils/include/common.h') diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index 652b8c08..9ec8a0e3 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -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 */ -- cgit v1.2.1