The FSF address has changed in the past. Instead of updating it
each time the address changes, just drop it completely treewide.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
execute_binfmt may return negative return values which hush interprets
as 'exit'. Catch this and print an error message instead.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
'exit' used to do its job by returning value < 0. This is a sign
for hush that 'exit' is executed. This has problems:
- Often commands accidently return a negative value. This causes
the shell to exit.
- execute_binfmt returns a negative value when it does not find
a binary to execute. This again causes the shell to exit.
Returning a negative error value seems to be the right thing
to do, but catching this in the shell would mean that the exit
command does not work anymore.
- if called without arguments exit is supposed to return the code
of the last command. As a command exit has no access to this code.
This patch changes exit to be a builtin and also fixes the last return
code problem. While at it, update the help text.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Make the nonopt arguments to a script available starting from $1
after running getopt. This allows for scripts which use option
parsing but also have nonopts.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
parse_stream_outer used to convert a exit value to a return code,
but parse_stream_outer maybe inside a recursion. This means that
the exit status is lost in this case. Test case:
if [ 0 = 0 ]; then
false
exit $?
fi
echo "shouldn't be here"
Without this patch "shouldn't be here" will be printed.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
We can start a new interactive shell now using the 'sh' command on
the command line. This shell exits on ctrl-c though. Add a loop
around it to continue instead of exiting.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
On a systax error we have to bail out of the shell instead of
setting inp->p to NULL and crash barebox with a NULL pointer
deref. This only happened in scripts.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This fixes the problem I had (i.e. a boot loop caused by a stray fi in
/env/bin/init).
Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
This allows to call 'sh' in scripts without arguments in which
case an interactive shell will be started.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
hush has a long standing and anoying glob bug. hush expands wildcards
during parsing of the script or command stream. When the command stream
begins to execute the wildcards are already expanded which leads to:
mkdir /tmp
cd /tmp
mkdir foo; ls *
ls: *: No such file or directory
To fix this expand wildcards right before executing the command. Since
'for' loops are not executed in commands, we have to keep the old behaviour
in here so that 'for i in *' still works.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
By doing so glob will not return GLOB_NOMATCH anymore but instead
just does what fake_glob would do.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
hush used to escape '*' '[' '?' during parsing because the quotes
got removed in the first parsing loop.
globhack is used to remove these escapes again for glob. Since we now
keep the quotes until the end of parsing and we no longer escape glob
wildcards, we do no longer have to remove any quotes. With this globhack
can be much simpler.
While at it, change the prototype to match the one from glob() and rename
the function to fake_glob, because that's what it is: it just copies the
input string into the output struct without actually globbing.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
hush removes the quotes from strings too early. This leads to some bugs.
When hush executes
echo "hello sascha"
it correctly results in:
argv[0] = "echo"
argv[1] = "hello sascha"
However, the following behaves incorrect:
a="hello sascha"
echo "$a"
results in:
argv[0] = "echo"
argv[1] = "hello"
argv[2] = "sascha"
This is because hush removes the quotes and inserts variable values in a
single loop, so
echo "$a"
becomes:
echo hello sascha
after the loop.
Instead, keep the quotes until all variables are inserted and remove them
at the end.
This also fixes that echo \" resulted in \" instead of ".
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
General coding style cleanup
- add some blank lines
- add whitespaces on on both sides of operators
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This will allow to execute any file and detect it's type to handle it.
This will allow to use shell for bootp bootfile or dfu.
You can register multiple hook for the same filetype. They will be execute
in the invert order of register. If a hook does not handle the file you just
return -ERESTARTNOHAND;
This is only available with hush parser.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
The behaviour of other shells suggest that with source or '.'
the path should be resolved using the PATH environment variable. Do
the same in barebox.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
execute_command is the single point where commands are executed and thus a new
getopt context is needed. currently we call getopt_reset here to reset the
context. This breaks though when a command tries to run a command itself by
calling execute_command or run_command. In this case we have to store the
context and restore it afterwards. The same is necessary in builtin_getopt.
Currently noone does this so this one shouldn't fix a bug, but merely allows
us to do such things later.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Positional parameters are not nice, so implement a getopt
function. This has to be done as a builtin because otherwise
we have no access to the parents argc/argv.
getopt works as expected, here is a little example:
while getopt "hs:" OPT
do
if [ $OPT = h ]; then
echo "usage"
exit 1
else
echo "scr: opt: $OPT optarg: $OPTARG"
fi
done
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Fix memory leak in globbing part of hush. a simple '['
on the command line was enough to trigger it.
We must call globfree() before setting the glob structure
to zero.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
v2: Do not exit from all scripts but only the current one
This fixes the case:
barebox:/ cat /test
if [ 0 = 0 ]; then
exit 1
fi
barebox:/ /test
barebox:/ echo $?
0
barebox:/
Also, remove code to not allow exit from main shell. The for(;;) loop
in common/startup.c will bring us back anyway.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
No need to check for maximum argument counts. The commands are
safe to be called with more arguments, so lets safe some bytes.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This patch removes adding of an additional \ when doing
echo "\""
which gives \" instead of just "
I checked in latest busybox hush and this code is still present there,
but it behaves correctly in busybox due to some other code pathes I
didn't investigate.
If this change has any unwanted side effects feel free to flame on me
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
For practical reasons I changed all string literals assumed to be constant
to reside in .rodata subsection at end of .text section.
Signed-off-by: Carsten Schlote <schlote@vahanus.net>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>