From f06db344ad53c987e38970b55e119a5af36641e1 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 25 Mar 2026 00:03:31 +0000 Subject: mkhtemp: fix err() calling it indirectly was out of the question. must call it directly. Signed-off-by: Leah Rowe --- util/libreboot-utils/lib/command.c | 4 ++-- util/libreboot-utils/lib/file.c | 8 ++++---- util/libreboot-utils/lib/num.c | 2 +- util/libreboot-utils/lib/state.c | 26 +++++++++++++------------- util/libreboot-utils/lib/string.c | 7 +++++-- 5 files changed, 25 insertions(+), 22 deletions(-) (limited to 'util/libreboot-utils/lib') diff --git a/util/libreboot-utils/lib/command.c b/util/libreboot-utils/lib/command.c index 6d0e8856..c7048a23 100644 --- a/util/libreboot-utils/lib/command.c +++ b/util/libreboot-utils/lib/command.c @@ -110,7 +110,7 @@ set_cmd(int argc, char *argv[]) cmd = x->cmd[c].str; if (scmp(argv[2], cmd, MAX_CMD_LEN, &rval) < 0) - err_no_cleanup(EINVAL, + err_no_cleanup(0, EINVAL, "could not compare command strings"); if (rval != 0) continue; /* not the right command */ @@ -123,7 +123,7 @@ set_cmd(int argc, char *argv[]) return; } - err_no_cleanup(EINVAL, + err_no_cleanup(0, EINVAL, "Too few args on command '%s'", cmd); } diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c index 46d5e016..552618d6 100644 --- a/util/libreboot-utils/lib/file.c +++ b/util/libreboot-utils/lib/file.c @@ -96,16 +96,16 @@ void xopen(int *fd_ptr, const char *path, int flags, struct stat *st) { if ((*fd_ptr = open(path, flags)) < 0) - err_no_cleanup(errno, "%s", path); + err_no_cleanup(0, errno, "%s", path); if (fstat(*fd_ptr, st) < 0) - err_no_cleanup(errno, "%s: stat", path); + err_no_cleanup(0, errno, "%s: stat", path); if (!S_ISREG(st->st_mode)) - err_no_cleanup(errno, "%s: not a regular file", path); + err_no_cleanup(0, errno, "%s: not a regular file", path); if (lseek_on_eintr(*fd_ptr, 0, SEEK_CUR, 1, 1) == (off_t)-1) - err_no_cleanup(errno, "%s: file not seekable", path); + err_no_cleanup(0, errno, "%s: file not seekable", path); } /* fsync() the directory of a file, diff --git a/util/libreboot-utils/lib/num.c b/util/libreboot-utils/lib/num.c index 43efba71..0b76e257 100644 --- a/util/libreboot-utils/lib/num.c +++ b/util/libreboot-utils/lib/num.c @@ -436,6 +436,6 @@ void check_bin(size_t a, const char *a_name) { if (a > 1) - err_no_cleanup(EINVAL, "%s must be 0 or 1, but is %lu", + err_no_cleanup(0, EINVAL, "%s must be 0 or 1, but is %lu", a_name, (size_t)a); } diff --git a/util/libreboot-utils/lib/state.c b/util/libreboot-utils/lib/state.c index 4ef7163f..42d060b7 100644 --- a/util/libreboot-utils/lib/state.c +++ b/util/libreboot-utils/lib/state.c @@ -98,9 +98,9 @@ xstart(int argc, char *argv[]) return &us; if (argc < 3) - err_no_cleanup(EINVAL, "xstart: Too few arguments"); + err_no_cleanup(0, EINVAL, "xstart: Too few arguments"); if (argv == NULL) - err_no_cleanup(EINVAL, "xstart: NULL argv"); + err_no_cleanup(0, EINVAL, "xstart: NULL argv"); first_run = 0; @@ -113,41 +113,41 @@ xstart(int argc, char *argv[]) us.f.tname = NULL; if ((realdir = realpath(us.f.fname, NULL)) == NULL) - err_no_cleanup(errno, "xstart: can't get realpath of %s", + err_no_cleanup(0, errno, "xstart: can't get realpath of %s", us.f.fname); if (fs_dirname_basename(realdir, &dir, &base, 0) < 0) - err_no_cleanup(errno, "xstart: don't know CWD of %s", + err_no_cleanup(0, errno, "xstart: don't know CWD of %s", us.f.fname); if ((us.f.base = strdup(base)) == NULL) - err_no_cleanup(errno, "strdup base"); + err_no_cleanup(0, errno, "strdup base"); us.f.dirfd = fs_open(dir, O_RDONLY | O_DIRECTORY); if (us.f.dirfd < 0) - err_no_cleanup(errno, "%s: open dir", dir); + err_no_cleanup(0, errno, "%s: open dir", dir); if (new_tmpfile(&us.f.tmp_fd, &us.f.tname, dir, ".gbe.XXXXXXXXXX") < 0) - err_no_cleanup(errno, "%s", us.f.tname); + err_no_cleanup(0, errno, "%s", us.f.tname); if (fs_dirname_basename(us.f.tname, &tmpdir, &tmpbase_local, 0) < 0) - err_no_cleanup(errno, "tmp basename"); + err_no_cleanup(0, errno, "tmp basename"); us.f.tmpbase = strdup(tmpbase_local); if (us.f.tmpbase == NULL) - err_no_cleanup(errno, "strdup tmpbase"); + err_no_cleanup(0, errno, "strdup tmpbase"); free_if_null(&tmpdir); if (us.f.tname == NULL) - err_no_cleanup(errno, "x->f.tname null"); + err_no_cleanup(0, errno, "x->f.tname null"); if (*us.f.tname == '\0') - err_no_cleanup(errno, "x->f.tname empty"); + err_no_cleanup(0, errno, "x->f.tname empty"); if (fstat(us.f.tmp_fd, &us.f.tmp_st) < 0) - err_no_cleanup(errno, "%s: stat", us.f.tname); + err_no_cleanup(0, errno, "%s: stat", us.f.tname); memset(us.f.real_buf, 0, sizeof(us.f.real_buf)); memset(us.f.bufcmp, 0, sizeof(us.f.bufcmp)); @@ -164,7 +164,7 @@ xstatus(void) struct xstate *x = xstart(0, NULL); if (x == NULL) - err_no_cleanup(EACCES, "NULL pointer to xstate"); + err_no_cleanup(0, EACCES, "NULL pointer to xstate"); return x; } diff --git a/util/libreboot-utils/lib/string.c b/util/libreboot-utils/lib/string.c index 2f2be5f3..ea7ca30a 100644 --- a/util/libreboot-utils/lib/string.c +++ b/util/libreboot-utils/lib/string.c @@ -119,7 +119,7 @@ slen(const char *s, /* the one for nvmutil state is in state.c */ /* this one just exits */ void -err_no_cleanup(int nvm_errval, const char *msg, ...) +err_no_cleanup(int stfu, int nvm_errval, const char *msg, ...) { va_list args; int saved_errno = errno; @@ -141,7 +141,10 @@ err_no_cleanup(int nvm_errval, const char *msg, ...) vfprintf(stderr, msg, args); va_end(args); - fprintf(stderr, ": %s\n", strerror(errno)); + if (p != NULL) + fprintf(stderr, ": %s\n", strerror(errno)); + else + fprintf(stderr, "%s\n", strerror(errno)); exit(EXIT_FAILURE); } -- cgit v1.2.1