mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user