diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-03 03:31:09 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-03 03:31:09 +0000 |
| commit | 7213bba0c57d550676bb3adf56884c6bc60285da (patch) | |
| tree | 6afc781c2d383850c4aa74569f57c5b7f4bc67df /util/nvmutil | |
| parent | 490f311d05cc3ba63f506989311edeed8d26c64a (diff) | |
util/nvmutil: don't exit with errno as status
exit with 0 or 1, as is proper.
errno is an int, but the return value on a shell
can be e.g. byte, and depending how that number (errno)
is valued, could overflow and cause a zero exit, where
you want a non-zero exit.
the code has been changed, in such a way to maintain
current behaviour (don't change errno), except that when
errno is set upon exit, the exit value is now one.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 2510547f..8d5b707c 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -22,7 +22,7 @@ void cmd_setchecksum(void), cmd_brick(void), swap(int partnum), writeGbe(void), set_cmd(int, char **), setWord(int, int, uint16_t), check_bounds(int, int), xopen (int *, const char *, int p, struct stat *), checkMacSeparator(int), set_mac_byte(int, uint64_t *), usage(char*), set_io_flags(int, char **); -int goodChecksum(int partnum), write_mac_part(int); +int goodChecksum(int partnum), write_mac_part(int), set_err(int); uint8_t hextonum(char chs), rhex(void); uint16_t word(int, int); @@ -60,7 +60,6 @@ op_t op[] = { }; void (*cmd)(void) = NULL; -#define set_err(x) errno = errno ? errno : x #define err_if(x) if (x) err(set_err(ECANCELED), "%s", fname) int @@ -94,7 +93,7 @@ main(int argc, char *argv[]) writeGbe(); err_if((errno != 0) && (cmd != cmd_dump)); - return errno; + return errno ? 1 : 0; } void @@ -478,3 +477,10 @@ usage(char *util) util, util, util, util, util, util, util); err(set_err(ECANCELED), "Too few arguments"); } + +int +set_err(int x) +{ + errno = errno ? errno : x; + return 1; +} |
