From: Enrico Jorns <ejo@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Enrico Jorns <ejo@pengutronix.de>
Subject: [PATCH 3/5] commands: nv: assure error code will be returned when an error occurred
Date: Mon, 30 Oct 2017 11:34:19 +0100 [thread overview]
Message-ID: <20171030103421.15353-4-ejo@pengutronix.de> (raw)
In-Reply-To: <20171030103421.15353-1-ejo@pengutronix.de>
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>
---
commands/nv.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/commands/nv.c b/commands/nv.c
index 2ee18187e0..2229adde17 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) {
@@ -61,19 +61,29 @@ static int do_nv(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
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)
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-10-30 10:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-30 10:34 [PATCH v2 0/5] Fixes for nv command handling Enrico Jorns
2017-10-30 10:34 ` [PATCH 1/5] commands: nv: fail with verbose message if invoked without args Enrico Jorns
2017-10-31 17:51 ` Stefan Lengfeld
2017-10-31 21:47 ` Enrico Jörns
2017-11-01 19:43 ` Stefan Lengfeld
2017-10-30 10:34 ` [PATCH 2/5] commands: nv: call nvvar_print() only if no argument is given Enrico Jorns
2017-10-30 10:34 ` Enrico Jorns [this message]
2017-10-30 10:34 ` [PATCH 4/5] common: globvar: let nvvar_remove() report non-existing variable Enrico Jorns
2017-10-30 10:34 ` [PATCH 5/5] commands: nv: adjust command help Enrico Jorns
2017-10-30 16:51 ` Sam Ravnborg
2017-10-31 21:52 ` Enrico Jörns
-- strict thread matches above, loose matches on Subject: below --
2017-09-13 12:23 [PATCH 0/5] Fixes for nv command handling Enrico Jorns
2017-09-13 12:23 ` [PATCH 3/5] commands: nv: assure error code will be returned when an error occurred Enrico Jorns
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171030103421.15353-4-ejo@pengutronix.de \
--to=ejo@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox