diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-04-01 10:03:41 +0100 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-04-01 10:03:41 +0100 |
| commit | 861f56375aee4291285e8c853896044ce04343cd (patch) | |
| tree | b9ed6e8ae1a8d0504036e4c45827df4b82dd4658 | |
| parent | d91dd0ad81f041e725599665d23c16d8c9f35b75 (diff) | |
libreboot-utils: fix ALL compiler warnings
i wasn't using strict mode enough in make:
make strict
now it compiles cleanly. mostly removing
unused variables, fixing implicit conversions,
etc.
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/libreboot-utils/include/common.h | 16 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/checksum.c | 4 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/command.c | 54 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/file.c | 29 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/io.c | 71 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/mkhtemp.c | 8 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/num.c | 5 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/rand.c | 13 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/state.c | 26 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/string.c | 41 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/usage.c | 2 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/word.c | 2 | ||||
| -rw-r--r-- | util/libreboot-utils/mkhtemp.c | 12 | ||||
| -rw-r--r-- | util/libreboot-utils/nvmutil.c | 14 |
14 files changed, 143 insertions, 154 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index 48831ea3..a08dec08 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -84,16 +84,14 @@ int fchmod(int fd, mode_t mode); #define MAX_CMD_LEN 50 #ifndef PATH_MAX +#define PATH_MAX 4096 +#endif +#ifndef PATH_MAX #error PATH_MAX_undefined #elif ((PATH_MAX) < 1024) #error PATH_MAX_too_low #endif -#define OFF_ERR 0 -#ifndef OFF_RESET -#define OFF_RESET 1 -#endif - #ifndef S_ISVTX #define S_ISVTX 01000 #endif @@ -481,7 +479,7 @@ ssize_t rw_gbe_file_exact(int fd, unsigned char *mem, size_t nrw, int fsync_dir(const char *path); ssize_t rw_file_exact(int fd, unsigned char *mem, size_t len, - off_t off, int rw_type, size_t max_retries, int off_reset); + off_t off, int rw_type, size_t max_retries); ssize_t rw(int fd, void *mem, size_t nrw, off_t off, int rw_type); int io_args(int fd, void *mem, size_t nrw, @@ -489,7 +487,7 @@ int io_args(int fd, void *mem, size_t nrw, int check_file(int fd, struct stat *st); ssize_t rw_over_nrw(ssize_t r, size_t nrw); off_t lseek_on_eintr(int fd, off_t off, - int whence, int loop_eagain, int loop_eintr); + int whence); ssize_t read_on_eintr(int fd, void *buf, size_t count); ssize_t write_on_eintr(int fd, @@ -508,7 +506,7 @@ int rw_retry(int saved_errno, ssize_t rval); void usage(void); int with_fallback_errno(int fallback); -void err_exit(int nvm_errval, const char *msg, ...); +void exitf(const char *msg, ...); func_t errhook(func_t ptr); /* hook function for cleanup on err */ const char *lbgetprogname(void); void no_op(void); @@ -636,8 +634,6 @@ typedef char bool_skip_checksum_read[(SKIP_CHECKSUM_READ==0)?1:-1]; typedef char bool_checksum_read[(CHECKSUM_READ==1)?1:-1]; typedef char bool_skip_checksum_write[(SKIP_CHECKSUM_WRITE==0)?1:-1]; typedef char bool_checksum_write[(CHECKSUM_WRITE==1)?1:-1]; -typedef char bool_off_err[(OFF_ERR==0)?1:-1]; -typedef char bool_off_reset[(OFF_RESET==0||OFF_RESET==1)?1:-1]; #endif #endif diff --git a/util/libreboot-utils/lib/checksum.c b/util/libreboot-utils/lib/checksum.c index 97b0efca..f71bcb4f 100644 --- a/util/libreboot-utils/lib/checksum.c +++ b/util/libreboot-utils/lib/checksum.c @@ -59,10 +59,10 @@ read_checksums(void) if (_num_invalid >= _max_invalid) { if (_max_invalid == 1) - err_exit(ECANCELED, "%s: part %lu has a bad checksum", + exitf("%s: part %lu has a bad checksum", f->fname, (size_t)f->part); - err_exit(ECANCELED, "%s: No valid checksum found in file", + exitf("%s: No valid checksum found in file", f->fname); } } diff --git a/util/libreboot-utils/lib/command.c b/util/libreboot-utils/lib/command.c index 5ccf9de9..526ad03b 100644 --- a/util/libreboot-utils/lib/command.c +++ b/util/libreboot-utils/lib/command.c @@ -43,24 +43,24 @@ sanitize_command_index(size_t c) check_command_num(c); if (cmd->argc < 3) - err_exit(EINVAL, "cmd index %lu: argc below 3, %d", + exitf("cmd index %lu: argc below 3, %d", (size_t)c, cmd->argc); if (cmd->str == NULL) - err_exit(EINVAL, "cmd index %lu: NULL str", + exitf("cmd index %lu: NULL str", (size_t)c); if (*cmd->str == '\0') - err_exit(EINVAL, "cmd index %lu: empty str", + exitf("cmd index %lu: empty str", (size_t)c); if (slen(cmd->str, MAX_CMD_LEN +1, &rval) > MAX_CMD_LEN) { - err_exit(EINVAL, "cmd index %lu: str too long: %s", + exitf("cmd index %lu: str too long: %s", (size_t)c, cmd->str); } if (cmd->run == NULL) - err_exit(EINVAL, "cmd index %lu: cmd ptr null", + exitf("cmd index %lu: cmd ptr null", (size_t)c); check_bin(cmd->arg_part, "cmd.arg_part"); @@ -74,19 +74,19 @@ sanitize_command_index(size_t c) case NVM_SIZE: break; default: - err_exit(EINVAL, "Unsupported rw_size: %lu", + exitf("Unsupported rw_size: %lu", (size_t)gbe_rw_size); } if (gbe_rw_size > GBE_PART_SIZE) - err_exit(EINVAL, "rw_size larger than GbE part: %lu", + exitf("rw_size larger than GbE part: %lu", (size_t)gbe_rw_size); _flag = (cmd->flags & O_ACCMODE); if (_flag != O_RDONLY && _flag != O_RDWR) - err_exit(EINVAL, "invalid cmd.flags setting"); + exitf("invalid cmd.flags setting"); } void @@ -114,7 +114,7 @@ set_cmd(int argc, char *argv[]) return; } - err_exit(EINVAL, + exitf( "Too few args on command '%s'", cmd); } @@ -139,11 +139,11 @@ set_cmd_args(int argc, char *argv[]) /* Maintainer bug */ if (cmd->arg_part && argc < 4) - err_exit(EINVAL, + exitf( "arg_part set for command that needs argc4"); if (cmd->arg_part && i == CMD_SETMAC) - err_exit(EINVAL, + exitf( "arg_part set on CMD_SETMAC"); if (i == CMD_SETMAC) { @@ -165,13 +165,13 @@ conv_argv_part_num(const char *part_str) unsigned char ch; if (part_str[0] == '\0' || part_str[1] != '\0') - err_exit(EINVAL, "Partnum string '%s' wrong length", part_str); + exitf("Partnum string '%s' wrong length", part_str); /* char signedness is implementation-defined */ ch = (unsigned char)part_str[0]; if (ch < '0' || ch > '1') - err_exit(EINVAL, "Bad part number (%c)", ch); + exitf("Bad part number (%c)", ch); return (size_t)(ch - '0'); } @@ -180,7 +180,7 @@ void check_command_num(size_t c) { if (!valid_command(c)) - err_exit(EINVAL, "Invalid run_cmd arg: %lu", + exitf("Invalid run_cmd arg: %lu", (size_t)c); } @@ -196,7 +196,7 @@ valid_command(size_t c) cmd = &x->cmd[c]; if (c != cmd->chk) - err_exit(EINVAL, + exitf( "Invalid cmd chk value (%lu) vs arg: %lu", cmd->chk, c); @@ -231,7 +231,7 @@ parse_mac_string(void) size_t rval; if (slen(x->mac.str, 18, &rval) != 17) - err_exit(EINVAL, "MAC address is the wrong length"); + exitf("MAC address is the wrong length"); memset(mac->mac_buf, 0, sizeof(mac->mac_buf)); @@ -239,10 +239,10 @@ parse_mac_string(void) set_mac_byte(mac_byte); if ((mac->mac_buf[0] | mac->mac_buf[1] | mac->mac_buf[2]) == 0) - err_exit(EINVAL, "Must not specify all-zeroes MAC address"); + exitf("Must not specify all-zeroes MAC address"); if (mac->mac_buf[0] & 1) - err_exit(EINVAL, "Must not specify multicast MAC address"); + exitf("Must not specify multicast MAC address"); } void @@ -260,7 +260,7 @@ set_mac_byte(size_t mac_byte_pos) if (mac_str_pos < 15) { if ((separator = mac->str[mac_str_pos + 2]) != ':') - err_exit(EINVAL, "Invalid MAC address separator '%c'", + exitf("Invalid MAC address separator '%c'", separator); } @@ -282,9 +282,9 @@ set_mac_nib(size_t mac_str_pos, if ((hex_num = hextonum(mac_ch)) > 15) { if (hex_num >= 17) - err_exit(EIO, "Randomisation failure"); + exitf("Randomisation failure"); else - err_exit(EINVAL, "Invalid character '%c'", + exitf("Invalid character '%c'", mac->str[mac_str_pos + mac_nib_pos]); } @@ -467,7 +467,7 @@ cat(size_t nff) if ((size_t)x->cat != nff) { - err_exit(ECANCELED, "erroneous call to cat"); + exitf("erroneous call to cat"); } fflush(NULL); @@ -490,11 +490,11 @@ void cat_buf(unsigned char *b) { if (b == NULL) - err_exit(errno, "null pointer in cat command"); + exitf("null pointer in cat command"); if (rw_file_exact(STDOUT_FILENO, b, - GBE_PART_SIZE, 0, IO_WRITE, MAX_ZERO_RW_RETRY, OFF_ERR) < 0) - err_exit(errno, "stdout: cat"); + GBE_PART_SIZE, 0, IO_WRITE, MAX_ZERO_RW_RETRY) < 0) + exitf("stdout: cat"); } void check_cmd(void (*fn)(void), @@ -504,7 +504,7 @@ check_cmd(void (*fn)(void), size_t i = x->i; if (x->cmd[i].run != fn) - err_exit(ECANCELED, "Running %s, but cmd %s is set", + exitf("Running %s, but cmd %s is set", name, x->cmd[i].str); /* prevent second command @@ -516,6 +516,6 @@ check_cmd(void (*fn)(void), void cmd_helper_err(void) { - err_exit(ECANCELED, + exitf( "Erroneously running command twice"); } diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c index 12f52c56..9c4683ce 100644 --- a/util/libreboot-utils/lib/file.c +++ b/util/libreboot-utils/lib/file.c @@ -16,6 +16,9 @@ more correct usage example: long max = pathconf("/", _PC_PATH_MAX); */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif #include <sys/types.h> #include <sys/stat.h> @@ -137,7 +140,7 @@ err_fsync_dir: ssize_t rw_file_exact(int fd, unsigned char *mem, size_t nrw, - off_t off, int rw_type, size_t max_retries, int off_reset) + off_t off, int rw_type, size_t max_retries) { int saved_errno = errno; ssize_t rval = 0; @@ -207,7 +210,6 @@ rw(int fd, void *mem, size_t nrw, { ssize_t rval = 0; ssize_t r = -1; - struct stat st; int saved_errno = errno; errno = 0; @@ -566,11 +568,11 @@ open_file_on_eintr(const char *path, errno = 0; if (path == NULL) - err_exit(EINVAL, "open_file_on_eintr: null path"); + exitf("open_file_on_eintr: null path"); if (fd == NULL) - err_exit(EFAULT, "%s: open_file_on_eintr: null fd ptr", path); + exitf("%s: open_file_on_eintr: null fd ptr", path); if (*fd >= 0) - err_exit(EBADF, + exitf( "%s: open_file_on_eintr: file already open", path); errno = 0; @@ -578,7 +580,7 @@ open_file_on_eintr(const char *path, rval = open(path, flags, mode))); if (rval < 0) - err_exit(errno, + exitf( "%s: open_file_on_eintr: could not close", path); reset_caller_errno(rval); @@ -594,14 +596,14 @@ open_file_on_eintr(const char *path, if (st != NULL) { if (fstat(*fd, st) < 0) - err_exit(errno, "%s: stat", path); + exitf("%s: stat", path); if (!S_ISREG(st->st_mode)) - err_exit(errno, "%s: not a regular file", path); + exitf("%s: not a regular file", path); } - if (lseek_on_eintr(*fd, 0, SEEK_CUR, 1, 1) == (off_t)-1) - err_exit(errno, "%s: file not seekable", path); + if (lseek_on_eintr(*fd, 0, SEEK_CUR) == (off_t)-1) + exitf("%s: file not seekable", path); errno = saved_errno; /* see previous comment */ } @@ -662,8 +664,7 @@ openat_on_eintr(int dirfd, const char *path, #endif off_t -lseek_on_eintr(int fd, off_t off, int whence, - int loop_eagain, int loop_eintr) +lseek_on_eintr(int fd, off_t off, int whence) { int saved_errno = errno; off_t rval = 0; @@ -803,7 +804,7 @@ close_on_eintr(int *fd) int rval = 0; if (fd == NULL) - err_exit(EINVAL, "close_on_eintr: null pointer"); + exitf("close_on_eintr: null pointer"); if (*fd < 0) return; @@ -812,7 +813,7 @@ close_on_eintr(int *fd) rval = close(*fd))); if (rval < 0) - err_exit(errno, "close_on_eintr: could not close"); + exitf("close_on_eintr: could not close"); *fd = -1; diff --git a/util/libreboot-utils/lib/io.c b/util/libreboot-utils/lib/io.c index 56f8528a..f8e67977 100644 --- a/util/libreboot-utils/lib/io.c +++ b/util/libreboot-utils/lib/io.c @@ -41,17 +41,17 @@ open_gbe_file(void) &f->gbe_st); if (f->gbe_st.st_nlink > 1) - err_exit(EINVAL, + exitf( "%s: warning: file has multiple (%lu) hard links\n", f->fname, (size_t)f->gbe_st.st_nlink); if (f->gbe_st.st_nlink == 0) - err_exit(EIO, "%s: file unlinked while open", f->fname); + exitf("%s: file unlinked while open", f->fname); while (fs_retry(saved_errno, _flags = fcntl(f->gbe_fd, F_GETFL))); if (_flags == -1) - err_exit(errno, "%s: fcntl(F_GETFL)", f->fname); + exitf("%s: fcntl(F_GETFL)", f->fname); /* O_APPEND allows POSIX write() to ignore * the current write offset and write at EOF, @@ -59,7 +59,7 @@ open_gbe_file(void) */ if (_flags & O_APPEND) - err_exit(EIO, "%s: O_APPEND flag", f->fname); + exitf("%s: O_APPEND flag", f->fname); f->gbe_file_size = f->gbe_st.st_size; @@ -69,13 +69,13 @@ open_gbe_file(void) case SIZE_128KB: break; default: - err_exit(EINVAL, "File size must be 8KB, 16KB or 128KB"); + exitf("File size must be 8KB, 16KB or 128KB"); } /* currently fails (EBADF), locks are advisory anyway: */ /* if (lock_file(f->gbe_fd, cmd->flags) == -1) - err_exit(errno, "%s: can't lock", f->fname); + exitf("%s: can't lock", f->fname); */ reset_caller_errno(0); @@ -109,44 +109,44 @@ read_file(void) /* read main file */ _r = rw_file_exact(f->gbe_fd, f->buf, f->gbe_file_size, - 0, IO_PREAD, MAX_ZERO_RW_RETRY, OFF_ERR); + 0, IO_PREAD, MAX_ZERO_RW_RETRY); if (_r < 0) - err_exit(errno, "%s: read failed", f->fname); + exitf("%s: read failed", f->fname); /* copy to tmpfile */ _r = rw_file_exact(f->tmp_fd, f->buf, f->gbe_file_size, - 0, IO_PWRITE, MAX_ZERO_RW_RETRY, OFF_ERR); + 0, IO_PWRITE, MAX_ZERO_RW_RETRY); if (_r < 0) - err_exit(errno, "%s: %s: copy failed", + exitf("%s: %s: copy failed", f->fname, f->tname); /* file size comparison */ if (fstat(f->tmp_fd, &_st) == -1) - err_exit(errno, "%s: stat", f->tname); + exitf("%s: stat", f->tname); f->gbe_tmp_size = _st.st_size; if (f->gbe_tmp_size != f->gbe_file_size) - err_exit(EIO, "%s: %s: not the same size", + exitf("%s: %s: not the same size", f->fname, f->tname); /* needs sync, for verification */ if (fsync_on_eintr(f->tmp_fd) == -1) - err_exit(errno, "%s: fsync (tmpfile copy)", f->tname); + exitf("%s: fsync (tmpfile copy)", f->tname); _r = rw_file_exact(f->tmp_fd, f->bufcmp, f->gbe_file_size, - 0, IO_PREAD, MAX_ZERO_RW_RETRY, OFF_ERR); + 0, IO_PREAD, MAX_ZERO_RW_RETRY); if (_r < 0) - err_exit(errno, "%s: read failed (cmp)", f->tname); + exitf("%s: read failed (cmp)", f->tname); if (vcmp(f->buf, f->bufcmp, f->gbe_file_size) != 0) - err_exit(errno, "%s: %s: read contents differ (pre-test)", + exitf("%s: %s: read contents differ (pre-test)", f->fname, f->tname); } @@ -164,10 +164,10 @@ write_gbe_file(void) return; if (same_file(f->tmp_fd, &f->tmp_st, 0) < 0) - err_exit(errno, "%s: file inode/device changed", f->tname); + exitf("%s: file inode/device changed", f->tname); if (same_file(f->gbe_fd, &f->gbe_st, 1) < 0) - err_exit(errno, "%s: file has changed", f->fname); + exitf("%s: file has changed", f->fname); update_checksum = cmd->chksum_write; @@ -200,7 +200,7 @@ rw_gbe_file_part(size_t p, int rw_type, gbe_rw_size = cmd->rw_size; if (rw_type < IO_PREAD || rw_type > IO_PWRITE) - err_exit(errno, "%s: %s: part %lu: invalid rw_type, %d", + exitf("%s: %s: part %lu: invalid rw_type, %d", f->fname, rw_type_str, (size_t)p, rw_type); mem_offset = gbe_mem_offset(p, rw_type_str); @@ -210,11 +210,11 @@ rw_gbe_file_part(size_t p, int rw_type, gbe_rw_size, file_offset, rw_type); if (rval == -1) - err_exit(errno, "%s: %s: part %lu", + exitf("%s: %s: part %lu", f->fname, rw_type_str, (size_t)p); if ((size_t)rval != gbe_rw_size) - err_exit(EIO, "%s: partial %s: part %lu", + exitf("%s: partial %s: part %lu", f->fname, rw_type_str, (size_t)p); } @@ -238,7 +238,7 @@ write_to_gbe_bin(void) */ if (fsync_on_eintr(f->tmp_fd) == -1) - err_exit(errno, "%s: fsync (pre-verification)", + exitf("%s: fsync (pre-verification)", f->tname); check_written_part(0); @@ -247,7 +247,7 @@ write_to_gbe_bin(void) report_io_err_rw(); if (f->io_err_gbe) - err_exit(EIO, "%s: bad write", f->fname); + exitf("%s: bad write", f->fname); saved_errno = errno; @@ -319,10 +319,10 @@ check_written_part(size_t p) memset(f->pad, 0xff, sizeof(f->pad)); if (same_file(f->tmp_fd, &f->tmp_st, 0) < 0) - err_exit(errno, "%s: file inode/device changed", f->tname); + exitf("%s: file inode/device changed", f->tname); if (same_file(f->gbe_fd, &f->gbe_st, 1) < 0) - err_exit(errno, "%s: file changed during write", f->fname); + exitf("%s: file changed during write", f->fname); rval = rw_gbe_file_exact(f->tmp_fd, f->pad, gbe_rw_size, file_offset, IO_PREAD); @@ -424,24 +424,10 @@ gbe_mv(void) int saved_errno; int tmp_gbe_bin_exists; - char *dest_tmp; - int dest_fd = -1; - - char *dir = NULL; - char *base = NULL; - char *dest_name = NULL; - - int dirfd = -1; - - struct stat st_dir; - /* will be set 0 if it doesn't */ tmp_gbe_bin_exists = 1; - dest_tmp = NULL; - dest_fd = -1; - saved_errno = errno; rval = fs_rename_at(f->dirfd, f->tmpbase, @@ -450,7 +436,6 @@ gbe_mv(void) if (rval > -1) tmp_gbe_bin_exists = 0; -ret_gbe_mv: if (f->gbe_fd > -1) { close_on_eintr(&f->gbe_fd); @@ -532,11 +517,11 @@ gbe_x_offset(size_t p, const char *f_op, const char *d_type, off = ((off_t)p) * (off_t)nsize; if (off > ncmp - GBE_PART_SIZE) - err_exit(ECANCELED, "%s: GbE %s %s out of bounds", + exitf("%s: GbE %s %s out of bounds", f->fname, d_type, f_op); if (off != 0 && off != ncmp >> 1) - err_exit(ECANCELED, "%s: GbE %s %s at bad offset", + exitf("%s: GbE %s %s at bad offset", f->fname, d_type, f_op); return off; @@ -572,7 +557,7 @@ rw_gbe_file_exact(int fd, unsigned char *mem, size_t nrw, goto err_rw_gbe_file_exact; r = rw_file_exact(fd, mem, nrw, off, rw_type, - MAX_ZERO_RW_RETRY, OFF_ERR); + MAX_ZERO_RW_RETRY); return rw_over_nrw(r, nrw); diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c index d3ca92b0..4d7ad0bd 100644 --- a/util/libreboot-utils/lib/mkhtemp.c +++ b/util/libreboot-utils/lib/mkhtemp.c @@ -58,10 +58,8 @@ new_tmp_common(int *fd, char **path, int type, struct stat st; const char *templatestr; - size_t templatestr_len; size_t dirlen; - size_t destlen; char *dest = NULL; /* final path (will be written into "path") */ int saved_errno = errno; int dirfd = -1; @@ -114,9 +112,8 @@ new_tmp_common(int *fd, char **path, int type, else templatestr = "tmp.XXXXXXXXXX"; - /* may as well calculate in advance */ - destlen = slen(tmpdir, PATH_MAX, &dirlen) + 1 - + slen(templatestr, PATH_MAX, &templatestr_len); + /* may as well calculate in advance */ + dirlen = slen(tmpdir, PATH_MAX, &dirlen); /* full path: */ dest = scatn(3, (const char *[]) { tmpdir, "/", templatestr }, PATH_MAX, &dest); @@ -441,7 +438,6 @@ mkhtemp(int *fd, size_t retries; - int close_errno; int saved_errno = errno; int r; diff --git a/util/libreboot-utils/lib/num.c b/util/libreboot-utils/lib/num.c index ad349173..ce5e420d 100644 --- a/util/libreboot-utils/lib/num.c +++ b/util/libreboot-utils/lib/num.c @@ -29,7 +29,6 @@ unsigned short hextonum(char ch_s) { unsigned char ch; - size_t rval; ch = (unsigned char)ch_s; @@ -81,7 +80,7 @@ spew_hex(const void *data, size_t len) if (len <= 4294967296) /* below 4GB */ printf("%08zx ", i); else - printf("%0*zx ", sizeof(size_t) * 2, i); + printf("%16zu ", i); for (j = 0; j < 16; j++) { @@ -112,6 +111,6 @@ void check_bin(size_t a, const char *a_name) { if (a > 1) - err_exit(EINVAL, "%s must be 0 or 1, but is %lu", + exitf("%s must be 0 or 1, but is %lu", a_name, (size_t)a); } diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c index adfad3d7..082612d6 100644 --- a/util/libreboot-utils/lib/rand.c +++ b/util/libreboot-utils/lib/rand.c @@ -7,6 +7,10 @@ #ifndef RAND_H #define RAND_H +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif + #ifdef __OpenBSD__ #include <sys/param.h> #endif @@ -107,7 +111,7 @@ rsize(size_t n) { size_t rval = SIZE_MAX; if (!n) - err_exit(EFAULT, "rsize: division by zero"); + exitf("rsize: division by zero"); /* rejection sampling (clamp rand to eliminate modulo bias) */ for (; rval >= SIZE_MAX - (SIZE_MAX % n); rset(&rval, sizeof(rval))); @@ -133,7 +137,7 @@ rset(void *buf, size_t n) goto err; if (n == 0) - err_exit(EPERM, "rset: zero-byte request"); + exitf("rset: zero-byte request"); #if (defined(__OpenBSD__) || defined(__FreeBSD__) || \ defined(__NetBSD__) || defined(__APPLE__) || \ @@ -144,7 +148,7 @@ rset(void *buf, size_t n) #else size_t off = 0; -retry_rand: +retry_rand: { #if defined(USE_URANDOM) && \ ((USE_URANDOM) > 0) @@ -178,6 +182,7 @@ retry_rand: ((USE_URANDOM) > 0) close_on_eintr(&fd); #endif +} #endif reset_caller_errno(0); @@ -188,7 +193,7 @@ err: close_on_eintr(&fd); #endif (void) with_fallback_errno(ECANCELED); - err_exit(errno, "Randomisierungsfehler"); + exitf("Randomisierungsfehler"); exit(EXIT_FAILURE); } #endif diff --git a/util/libreboot-utils/lib/state.c b/util/libreboot-utils/lib/state.c index f32d4078..b956a483 100644 --- a/util/libreboot-utils/lib/state.c +++ b/util/libreboot-utils/lib/state.c @@ -4,6 +4,10 @@ * State machine (singleton) for nvmutil data. */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif + #include <sys/types.h> #include <sys/stat.h> @@ -92,9 +96,9 @@ xstart(int argc, char *argv[]) return &us; if (argc < 3) - err_exit(EINVAL, "xstart: Too few arguments"); + exitf("xstart: Too few arguments"); if (argv == NULL) - err_exit(EINVAL, "xstart: NULL argv"); + exitf("xstart: NULL argv"); first_run = 0; @@ -106,11 +110,11 @@ xstart(int argc, char *argv[]) us.f.tname = NULL; if ((realdir = realpath(us.f.fname, NULL)) == NULL) - err_exit(errno, "xstart: can't get realpath of %s", + exitf("xstart: can't get realpath of %s", us.f.fname); if (fs_dirname_basename(realdir, &dir, &base, 0) < 0) - err_exit(errno, "xstart: don't know CWD of %s", + exitf("xstart: don't know CWD of %s", us.f.fname); sdup(base, PATH_MAX, &us.f.base); @@ -118,26 +122,26 @@ xstart(int argc, char *argv[]) us.f.dirfd = fs_open(dir, O_RDONLY | O_DIRECTORY); if (us.f.dirfd < 0) - err_exit(errno, "%s: open dir", dir); + exitf("%s: open dir", dir); if (new_tmpfile(&us.f.tmp_fd, &us.f.tname, dir, ".gbe.XXXXXXXXXX") < 0) - err_exit(errno, "%s", us.f.tname); + exitf("%s", us.f.tname); if (fs_dirname_basename(us.f.tname, &tmpdir, &tmpbase_local, 0) < 0) - err_exit(errno, "tmp basename"); + exitf("tmp basename"); sdup(tmpbase_local, PATH_MAX, &us.f.tmpbase); free_and_set_null(&tmpdir); if (us.f.tname == NULL) - err_exit(errno, "x->f.tname null"); + exitf("x->f.tname null"); if (*us.f.tname == '\0') - err_exit(errno, "x->f.tname empty"); + exitf("x->f.tname empty"); if (fstat(us.f.tmp_fd, &us.f.tmp_st) < 0) - err_exit(errno, "%s: stat", us.f.tname); + exitf("%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)); @@ -154,7 +158,7 @@ xstatus(void) struct xstate *x = xstart(0, NULL); if (x == NULL) - err_exit(EACCES, "NULL pointer to xstate"); + exitf("NULL pointer to xstate"); return x; } diff --git a/util/libreboot-utils/lib/string.c b/util/libreboot-utils/lib/string.c index ce54a524..5e0b4c33 100644 --- a/util/libreboot-utils/lib/string.c +++ b/util/libreboot-utils/lib/string.c @@ -54,7 +54,7 @@ pagesize(void) if (!set) { if ((rval = sysconf(_SC_PAGESIZE)) < 0) - err_exit(errno, "could not determine page size"); + exitf("could not determine page size"); set = 1; } @@ -66,7 +66,7 @@ void free_and_set_null(char **buf) { if (buf == NULL) - err_exit(EFAULT, + exitf( "null ptr (to ptr for freeing) in free_and_set_null"); if (*buf == NULL) @@ -99,9 +99,9 @@ vmalloc(void **buf, size_t size) errno = 0; if (size >= SIZE_MAX - 1) - err_exit(EOVERFLOW, "integer overflow in vmalloc"); + exitf("integer overflow in vmalloc"); if (buf == NULL) - err_exit(EFAULT, "Bad pointer passed to vmalloc"); + exitf("Bad pointer passed to vmalloc"); /* lots of programs will * re-initialise a buffer @@ -111,14 +111,14 @@ vmalloc(void **buf, size_t size) * force the programmer to behave */ if (*buf != NULL) - err_exit(EFAULT, "Non-null pointer given to vmalloc"); + exitf("Non-null pointer given to vmalloc"); if (!size) - err_exit(EFAULT, + exitf( "Tried to vmalloc(0) and that is very bad. Fix it now"); if ((rval = malloc(size)) == NULL) - err_exit(errno, "malloc fail in vmalloc"); + exitf("malloc fail in vmalloc"); reset_caller_errno(0); return *buf = rval; @@ -181,7 +181,7 @@ err: if (rval != NULL) *rval = -1; - err_exit(errno, "scmp"); + exitf("scmp"); return -1; out: reset_caller_errno(0); @@ -195,7 +195,7 @@ int ccmp(const char *a, const char *b, unsigned char bc; if (if_err(a == NULL || b == NULL || rval == NULL, EFAULT)) - err_exit(errno, "ccmp"); + exitf("ccmp"); ac = (unsigned char)a[i]; bc = (unsigned char)b[i]; @@ -263,7 +263,7 @@ err: if (rval != NULL) *rval = 0; - err_exit(errno, "slen"); /* abort */ + exitf("slen"); /* abort */ return 0; /* gcc15 is happy */ out: reset_caller_errno(0); @@ -335,7 +335,7 @@ err: *dest = NULL; (void) with_fallback_errno(EFAULT); - err_exit(errno, "sdup"); + exitf("sdup"); return NULL; out: @@ -352,7 +352,7 @@ scatn(ssize_t sc, const char **sv, char *final = NULL; char *rcur = NULL; char *rtmp = NULL; - size_t i; + ssize_t i; errno = 0; if (if_err(sc < 2, EINVAL) || @@ -387,7 +387,7 @@ err: (void) with_fallback_errno(EFAULT); - err_exit(errno, "scatn"); + exitf("scatn"); return NULL; } @@ -425,7 +425,7 @@ err: (void) with_fallback_errno(EINVAL); if (dest != NULL) *dest = NULL; - err_exit(errno, "scat"); + exitf("scat"); return NULL; } @@ -471,7 +471,7 @@ err: free_and_set_null(&rval2); (void) with_fallback_errno(EINVAL); - err_exit(errno, "dcat"); + exitf("dcat"); } /* because no libc reimagination is complete @@ -491,7 +491,7 @@ vcmp(const void *s1, const void *s2, size_t n) errno = 0; if (if_err(s1 == NULL || s2 == NULL, EFAULT)) - err_exit(EFAULT, "vcmp: null input"); + exitf("vcmp: null input"); x = s1; y = s2; @@ -529,11 +529,10 @@ with_fallback_errno(int fallback) /* the one for nvmutil state is in state.c */ /* this one just exits */ void -err_exit(int nvm_errval, const char *msg, ...) +exitf(const char *msg, ...) { va_list args; int saved_errno = errno; - const char *p; func_t err_cleanup = errhook(NULL); err_cleanup(); @@ -561,7 +560,7 @@ err_exit(int nvm_errval, const char *msg, ...) * e.g. you might want to * close some files, depending * on your program. - * see: err_exit() + * see: exitf() */ func_t errhook(func_t ptr) { @@ -632,7 +631,7 @@ xpledgex(const char *promises, const char *execpromises) errno = 0; #ifdef __OpenBSD__ if (pledge(promises, execpromises) == -1) - err_exit(errno, "pledge"); + exitf("pledge"); #endif reset_caller_errno(0); return 0; @@ -645,7 +644,7 @@ xunveilx(const char *path, const char *permissions) errno = 0; #ifdef __OpenBSD__ if (pledge(promises, execpromises) == -1) - err_exit(errno, "pledge"); + exitf("pledge"); #endif reset_caller_errno(0); return 0; diff --git a/util/libreboot-utils/lib/usage.c b/util/libreboot-utils/lib/usage.c index 7c9fa34b..4ade2f9e 100644 --- a/util/libreboot-utils/lib/usage.c +++ b/util/libreboot-utils/lib/usage.c @@ -26,5 +26,5 @@ usage(void) util, util, util, util, util, util, util); - err_exit(EINVAL, "Too few arguments"); + exitf("Too few arguments"); } diff --git a/util/libreboot-utils/lib/word.c b/util/libreboot-utils/lib/word.c index 85e1d88b..45ac3d48 100644 --- a/util/libreboot-utils/lib/word.c +++ b/util/libreboot-utils/lib/word.c @@ -63,6 +63,6 @@ check_nvm_bound(size_t c, size_t p) check_bin(p, "part number"); if (c >= NVM_WORDS) - err_exit(ECANCELED, "check_nvm_bound: out of bounds %lu", + exitf("check_nvm_bound: out of bounds %lu", (size_t)c); } diff --git a/util/libreboot-utils/mkhtemp.c b/util/libreboot-utils/mkhtemp.c index 65e637e9..ced8aa96 100644 --- a/util/libreboot-utils/mkhtemp.c +++ b/util/libreboot-utils/mkhtemp.c @@ -95,7 +95,7 @@ main(int argc, char *argv[]) p > template && *--p == 'X'; xc++); if (xc < 3) /* the gnu mktemp errs on less than 3 */ - err_exit(EINVAL, + exitf( "template must have 3 X or more on end (12+ advised"); } @@ -109,21 +109,21 @@ main(int argc, char *argv[]) if (tmpdir != NULL) { rp = realpath(tmpdir, resolved); if (rp == NULL) - err_exit(errno, "%s", tmpdir); + exitf("%s", tmpdir); tmpdir = resolved; } if (new_tmp_common(&fd, &s, type, tmpdir, template) < 0) - err_exit(errno, "%s", s); + exitf("%s", s); xpledgex("stdio", NULL); if (s == NULL) - err_exit(EFAULT, "bad string initialisation"); + exitf("bad string initialisation"); if (*s == '\0') - err_exit(EFAULT, "empty string initialisation"); + exitf("empty string initialisation"); slen(s, PATH_MAX, &len); /* Nullterminierung prüfen */ /* for good measure. (bonus: also re-checks length overflow) */ @@ -133,7 +133,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; err_usage: - err_exit(EINVAL, + exitf( "usage: %s [-d] [-p dir] [template]\n", lbgetprogname()); } diff --git a/util/libreboot-utils/nvmutil.c b/util/libreboot-utils/nvmutil.c index 26d15145..46e4a15c 100644 --- a/util/libreboot-utils/nvmutil.c +++ b/util/libreboot-utils/nvmutil.c @@ -6,6 +6,10 @@ * These images configure your Intel Gigabit Ethernet adapter. */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif + #include <sys/types.h> #include <sys/stat.h> @@ -44,15 +48,15 @@ main(int argc, char *argv[]) xunveilx("/dev/urandom", "r"); #ifndef S_ISREG - err_exit(ECANCELED, + exitf( "Can't determine file types (S_ISREG undefined)"); #endif #if ((CHAR_BIT) != 8) - err_exit(ECANCELED, "Unsupported char size"); + exitf("Unsupported char size"); #endif if ((x = xstart(argc, argv)) == NULL) - err_exit(ECANCELED, "NULL state on init"); + exitf("NULL state on init"); /* parse user command */ /* TODO: CHECK ACCESSES VIA xstatus() */ @@ -72,7 +76,7 @@ main(int argc, char *argv[]) xpledgex("stdio flock rpath wpath cpath", NULL); if (cmd->run == NULL) - err_exit(errno, "Command not set"); + exitf("Command not set"); sanitize_command_list(); open_gbe_file(); @@ -88,7 +92,7 @@ main(int argc, char *argv[]) exit_cleanup(); if (f->io_err_gbe_bin) - err_exit(EIO, "%s: error writing final file"); + exitf("%s: error writing final file"); free_and_set_null(&f->tname); |
