diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2017-11-13 08:21:07 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-11-13 08:21:07 +0100 |
commit | e65434fca43a20a2f6dc207a02e7b03b749ba1b4 (patch) | |
tree | 01096e7aaaa36befc1636161422bed85be299673 | |
parent | 8489388b5b1c1a7042a46ba22f3d8ae16057946f (diff) | |
parent | 1467855ffcfb9c826bb761a87ff4578aedcf0fc4 (diff) | |
download | barebox-e65434fca43a20a2f6dc207a02e7b03b749ba1b4.tar.gz barebox-e65434fca43a20a2f6dc207a02e7b03b749ba1b4.tar.xz |
Merge branch 'for-next/nv'
-rw-r--r-- | commands/nv.c | 45 | ||||
-rw-r--r-- | common/globalvar.c | 4 |
2 files changed, 32 insertions, 17 deletions
diff --git a/commands/nv.c b/commands/nv.c index 37cdb96647..51b855ee4b 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) { @@ -44,50 +44,63 @@ static int do_nv(int argc, char *argv[]) } } - if (do_save) - return nvvar_save(); - - if (argc == optind) { + if (argc == 1) { nvvar_print(); return 0; } + if (do_save) { + return nvvar_save(); + } + argc -= optind; argv += optind; - if (argc < 1) + if (argc < 1) { + printf("Invalid usage: Missing argument"); 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) -BAREBOX_CMD_HELP_TEXT("Add a new non volatile variable named VAR, optionally set to VALUE.") -BAREBOX_CMD_HELP_TEXT("non volatile variables are persistent variables that overwrite the") -BAREBOX_CMD_HELP_TEXT("global variables of the same name. Their value is saved implicitly with") -BAREBOX_CMD_HELP_TEXT("'saveenv' or explicitly with 'nv -s'") +BAREBOX_CMD_HELP_TEXT("Add a new non volatile (NV) variable named VAR, optionally set to VALUE.") +BAREBOX_CMD_HELP_TEXT("NV variables are persistent variables that overwrite the global variables") +BAREBOX_CMD_HELP_TEXT("of the same name.") +BAREBOX_CMD_HELP_TEXT("Their value is saved implicitly with 'saveenv' or explicitly with 'nv -s'") BAREBOX_CMD_HELP_TEXT("") BAREBOX_CMD_HELP_TEXT("Options:") -BAREBOX_CMD_HELP_OPT("-r", "remove non volatile variables") -BAREBOX_CMD_HELP_OPT("-s", "Save NV variables") +BAREBOX_CMD_HELP_OPT("-r VAR1 ...", "remove NV variable(s)") +BAREBOX_CMD_HELP_OPT("-s\t", "save NV variables") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(nv) .cmd = do_nv, - BAREBOX_CMD_DESC("create or set non volatile variables") + BAREBOX_CMD_DESC("create, set or remove non volatile (NV) variables") BAREBOX_CMD_OPTS("[-r] VAR[=VALUE] ...") BAREBOX_CMD_GROUP(CMD_GRP_ENV) BAREBOX_CMD_HELP(cmd_nv_help) diff --git a/common/globalvar.c b/common/globalvar.c index fdfaf76fae..ee756e5140 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -261,9 +261,11 @@ int nvvar_remove(const char *name) unlink(fname); free(fname); + + return 0; } - return 0; + return -ENOENT; } int nvvar_load(void) |