In preparation for making setenv selectable under CONFIG_SHELL_HUSH,
allow a `setenv dev.var=VAL syntax`:
  - makes command use less surprising for hush users
  - allows seamless integration with current device parameter complete

While at it, propagate setenv's return code to the calling shell.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 commands/setenv.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/commands/setenv.c b/commands/setenv.c
index 3cf769d24a68..a70a0de4cebc 100644
--- a/commands/setenv.c
+++ b/commands/setenv.c
@@ -8,12 +8,20 @@
 
 static int do_setenv(int argc, char *argv[])
 {
+       char *equal;
+
        if (argc < 2)
                return COMMAND_ERROR_USAGE;
 
-       setenv(argv[1], argv[2]);
+       equal = strrchr(argv[1], '=');
+       if (equal) {
+               equal[0] = '\0';
+               if (equal[1])
+                       argv[2] = &equal[1];
+       }
+
 
-       return 0;
+       return setenv(argv[1], argv[2]) ? COMMAND_ERROR : COMMAND_SUCCESS;
 }
 
 BAREBOX_CMD_HELP_START(setenv)
-- 
2.28.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to