shell: Use argc and argv in shell handlers#760
shell: Use argc and argv in shell handlers#760mehlis merged 7 commits intoRIOT-OS:masterfrom Kijewski:shell-args
Conversation
|
What happens if I do? |
|
The first prints a warning and does not call the handler. I added the command |
|
Personally I would prefer if the second one would drop the trailing space and the third would not be chopped up. Do you think that's feasible? (I would have gone for a state machine .. haven't looked into your implementation, just telling ;-) |
|
Pfft... state machine (what is that supposed to mean?!).. I need to rest! |
|
Now all three kinds of wrong quoting cause an error message. |
sys/shell/shell.c
Outdated
There was a problem hiding this comment.
The comment does not match the line that immediately follows it?
There was a problem hiding this comment.
Ahh, I did not put a newline after this line, so it's supposed to be the same logical block.
But now I see that @kaspar030 probably meant shell_command_handler_t handler = handler = ....
|
@Kijewski nice work, but you missed all the apps in the |
|
@mehlis I don't think that I understand |
There was a problem hiding this comment.
text was and is declared as char[5]. The previous implementation did not test the input, so I don't know if the limitation is needed at all.
|
OK, only one thing missing: The second invocation should not reuse the old parameters. |
|
@Kijewski PR needs rebase |
|
I didn't convert, |
Compare #708. Now the tokenization of an input line is done by the shell itself. You may quote arguments with `"..."`. Empty arguments, supplied by `""` are preserved. Spaces in between arguments are squasheds; spaces inside quotes are preserved. You cannot partially quote an argument. You must not use - `cmd "abc`, - `cmd abc"def"`, or - `cmd "abc"def`.
|
Rebased.
|
|
@Kijewski I'll provide an update for my code. |
|
@Kijewski rpl_udp@master is compiling in my system, or do you mean with this PR it is not compiling anymore? |
|
regarding #760 (comment): --- a/sys/shell/shell.c
+++ b/sys/shell/shell.c
@@ -92,6 +92,8 @@ static void handle_input_line(shell_t *shell, char *line)
{
static const char *INCORRECT_QUOTING = "shell: incorrect quoting";
+ size_t linelen = strlen(line);
+
/* first we need to calculate the number of arguments */
unsigned argc = 0;
char *pos;
@@ -160,6 +162,7 @@ static void handle_input_line(shell_t *shell, char *line)
puts("shell: command not found.");
}
}
+ memset(line, 0, linelen);
} |
|
Maybe this belongs in the uart handler though... |
--- a/sys/shell/shell.c
+++ b/sys/shell/shell.c
@@ -208,6 +208,7 @@ void shell_run(shell_t *shell)
if (!res) {
handle_input_line(shell, line_buf);
+ memset(line_buf, 0, shell->shell_buffer_size);
}
print_prompt(shell); |
|
There is really a bug in my implementation. The input line only has to be null terminated, not zeroed out. I'll look into it. |
|
I tried out Ludwigs fixes for preventing old parameters to show up, I would go for the |
|
Terminating the string with two zeros would have worked, but I changed the implementation a bit in my last commit. |
|
It is still broken though. Also - I think the buffer need to be zeroed out at least once before using it. |
--- a/sys/shell/shell.c
+++ b/sys/shell/shell.c
@@ -200,6 +200,7 @@ static inline void print_prompt(shell_t *shell)
void shell_run(shell_t *shell)
{
char line_buf[shell->shell_buffer_size];
+ memset(line_buf, 0, shell->shell_buffer_size);
print_prompt(shell); |
|
valgrind is of my opinion here.. |
$ rm -r ./bin
$ make BOARD=native all-valgrind
$ valgrind ./bin/native/*.elf
==10739== Memcheck, a memory error detector
==10739== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==10739== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==10739== Command: ./bin/native/test_shell.elf
==10739==
RIOT native uart0 initialized.
RIOT native interrupts/signals initialized.
LED_GREEN_OFF
LED_RED_ON
RIOT native board initialized.
RIOT native hardware initialization complete.
kernel_init(): This is RIOT! (Version: 2014.01-333-g28c4-localhost-shell-args)
kernel_init(): jumping into first task...
test_shell.
UART0 thread started.
uart0_init() [OK]
> echo 1 2 3
echo 1 2 3
“echo” “1” “2” “3”
> echo
echo
“echo”
> ./bin/native/test_shell.elf: closed stdio
^Clpm_set(): exit()
==10739==
==10739== HEAP SUMMARY:
==10739== in use at exit: 0 bytes in 0 blocks
==10739== total heap usage: 7 allocs, 7 frees, 700 bytes allocated
==10739==
==10739== All heap blocks were freed -- no leaks are possible
==10739==
==10739== For counts of detected and suppressed errors, rerun with: -v
==10739== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) |
|
Try echo without parameters. |
$ valgrind ./bin/native/*.elf
==10778== Memcheck, a memory error detector
==10778== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==10778== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==10778== Command: ./bin/native/test_shell.elf
==10778==
RIOT native uart0 initialized.
RIOT native interrupts/signals initialized.
LED_GREEN_OFF
LED_RED_ON
RIOT native board initialized.
RIOT native hardware initialization complete.
kernel_init(): This is RIOT! (Version: 2014.01-333-g28c4-localhost-shell-args)
kernel_init(): jumping into first task...
test_shell.
UART0 thread started.
uart0_init() [OK]
> echo
echo
“echo”
> ./bin/native/test_shell.elf: closed stdio
^Clpm_set(): exit()
==10778==
==10778== HEAP SUMMARY:
==10778== in use at exit: 0 bytes in 0 blocks
==10778== total heap usage: 3 allocs, 3 frees, 300 bytes allocated
==10778==
==10778== All heap blocks were freed -- no leaks are possible
==10778==
==10778== For counts of detected and suppressed errors, rerun with: -v
==10778== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)Did you fetch my last commit https://github.com/Kijewski/RIOT/commit/28c4ef45f703ea5a9fd3545abd22c9cdeed40a6c? |
|
Ah, very well - I think I fucked up when updating my copy of your branch. |
|
Yup, everything is fine now. |
|
As far as I'm concerned this PR is quite useful and it's running fine on the MSBA2 and the avsextrem, so I give it an ACK |
|
sc_rtc.c is broken. |
|
I think it's important that someone reviews my changes to the actual shell handlers. Most of them were trivial, but there were monsters like |
|
@LudwigOrtmann, I admit, I'm a noob. :) Could you give me some pointers how to use the default example? |
|
rtc has online help ;-) |
|
Or what were you referring to? |
|
@Kijewski PR for register prefix is open (on your branch) |
|
tested with ccn-lite-client with network, ok for me |
shell: adapt register prefix command to new shell api
|
I fixed my errors in sc_rtc and merged @mehlis' PR. |
|
@LudwigOrtmann any other findings? from my side: ACK |
|
@Kijewski regarding sc_disk: As there is no code to test this with at the moment I don't really care if it works or not though ;-) |
|
ACK - "There can be nothing wrong in this PR that isn't outweighed with what is right in this PR". |
shell: Use argc and argv in shell handlers
Compare #708.
Now the tokenization of an input line is done by the shell itself. You
may quote arguments with
"...". Empty arguments, supplied by""arepreserved. Spaces in between arguments are squasheds; spaces inside
quotes are preserved.
You cannot partially quote an argument. You must not use
cmd "abc,cmd abc"def", orcmd "abc"def.