summaryrefslogtreecommitdiffstats
path: root/commands/nv.c
diff options
context:
space:
mode:
authorEnrico Jorns <ejo@pengutronix.de>2017-11-01 08:27:07 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-11-03 08:51:21 +0100
commit2145fdf074f9b377d2e8aefbcb4a1d3f114045f4 (patch)
tree63740297a1651a147102295ecdde91f3b8f60f67 /commands/nv.c
parent31fd03b3807309ce033ba7285dadeea3bfc4e566 (diff)
downloadbarebox-2145fdf074f9b377d2e8aefbcb4a1d3f114045f4.tar.gz
commands: nv: assure error code will be returned when an error occurred
Due to iteration over possibly multiple variables, the return value of an individual call to nvvar_remove() / nvvar_add() gets lost. This will result in do_nv() returning success (0) if any variable processing failed as long as processing of the last variable succeeded. Processing will not be aborted on individual errors, such as the 'cp' handles it for invalid files. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/nv.c')
-rw-r--r--commands/nv.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/commands/nv.c b/commands/nv.c
index 2e6d079..ebef97e 100644
--- a/commands/nv.c
+++ b/commands/nv.c
@@ -28,7 +28,7 @@ static int do_nv(int argc, char *argv[])
{
int opt;
int do_remove = 0, do_save = 0;
- int ret, i;
+ int failed = 0, i;
char *value;
while ((opt = getopt(argc, argv, "rs")) > 0) {
@@ -62,19 +62,29 @@ static int do_nv(int argc, char *argv[])
}
for (i = 0; i < argc; i++) {
+ int ret;
value = strchr(argv[0], '=');
if (value) {
*value = 0;
value++;
}
- if (do_remove)
+ if (do_remove) {
ret = nvvar_remove(argv[i]);
- else
+ if (ret) {
+ printf("Failed removing %s: %s\n", argv[i], strerror(-ret));
+ failed = 1;
+ }
+ } else {
ret = nvvar_add(argv[i], value);
+ if (ret) {
+ printf("Failed adding %s: %s\n", argv[i], strerror(-ret));
+ failed = 1;
+ }
+ }
}
- return ret;
+ return failed;
}
BAREBOX_CMD_HELP_START(nv)