9
0
Fork 0
Commit Graph

114 Commits

Author SHA1 Message Date
Sascha Hauer 6331e58a2c Merge branch 'for-next/misc'
Conflicts:
	commands/devinfo.c
2014-06-04 21:03:36 +02:00
Sascha Hauer f81f26afbd hush: setting variables may fail
In case of device parameters setting variables may fail. return
the result of set_local_var so that the user has a chance to detect
the failure with $?.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-16 15:12:57 +02:00
Holger Schurig 26a34100e8 commands: HUSH_GETOPT -> CMD_GETOPT
* this compile option actually turns on a command, so name it
  accordingly
* also move the Kconfig definition into commands/Kconfig, thus
  placing getopt into the "Shell scripting commands" section
* while at it, improve Kconfig documention

Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-14 10:03:48 +02:00
Holger Schurig f1f532084a commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:

* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
  options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
  is listed by character in this (short) option string (the long
  description is in the long help text, as before)
* help texts have been reworked, to make them
  - sometimes smaller
  - sometimes describe the options better
  - more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
  macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
  all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
  is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
  errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
  compiled long help texts
* 'help -v' gives a list of commands with their short description, this
  is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands

Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-14 10:03:43 +02:00
Holger Schurig ab23d0bb3f commands: group 'help' output
The old output of "help" was just producing a long list, that usually
scrolled of the screen (even on a X11 terminal). This list is more
compact, and also sorted by groups.

The old output format (plus grouping) is now available with 'help -v'.

Example:

   Information commands:
     ?, devinfo, help, iomem, meminfo, version
   Boot commands:
     boot, bootm, go, loadb, loads, loadx, loady, saves, uimage
   ...

Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-14 07:59:55 +02:00
Sascha Hauer 45693e0265 Add shell_expand function
shell_expand expands shell variables in a string.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-03-28 09:36:36 +01:00
Sascha Hauer 93578fb233 run_command: remove unused flag parameter
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-03-07 07:41:26 +01:00
Sascha Hauer f5923be4c6 hush: refactor reserved_word()
Save indentation level for easier readability.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:47:15 +01:00
Sascha Hauer b763f01728 hush: use standard ARRAY_SIZE
Use standard ARRAY_SIZE instead of handcrafted NRES.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:47:15 +01:00
Sascha Hauer cc3fc44dbf hush: Be more informative on syntax error
Print the token that led to a syntax error, at least for the common
case.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:47:15 +01:00
Sascha Hauer 671cf43e56 consolidate syntax() and syntax_err()
syntax is defined as syntax_err. Drop syntax_err and call syntax instead.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:47:15 +01:00
Sascha Hauer 1d8041b03f hush: rename __promptme to interrupt
the name '__promptme' does not make clear what the variable means. rename
it to 'interrupt' which is set to true when the user has hit ctrl-c.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:46:05 +01:00
Sascha Hauer ad560a1797 hush: refactor file_get()
Save indentation level by returning early.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:45:04 +01:00
Sascha Hauer 8875a39679 hush: refactor get_user_input()
Save indentation level by returning early.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:45:03 +01:00
Sascha Hauer 86e7032568 hush: refactor readline call
Don't call readline in if/else, instead setup a variable and call
it once.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:45:03 +01:00
Sascha Hauer 091ef4fcfc hush: fix exit on syntax error behaviour
input.__promptme is no valid indicator that run_shell should be left.
It should be left on executing the 'exit' builtin which is indicated
by a return code < 0 from parse_stream_outer(). Track this with an extra
variable and use it as a condition to return from an interactive shell.

This fixes the weird behaviour that hush exits (and the user finds itself
in the menu) when a syntax error occured.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-11-12 14:41:07 +01:00
Jean-Christophe PLAGNIOL-VILLARD 56ee5d3aac process_escape_sequence: add support to \$?
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-09-18 09:17:13 +02:00
Sascha Hauer fe85ff4761 treewide: Fix typo seperate -> separate
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-05-21 21:38:21 +02:00
Sascha Hauer 6ad2bdb8e1 hush: implement $*
To get all arguments a script is called with.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-02-26 11:05:02 +01:00
Alexander Aring c7a9534359 hush: add getopt only if it enabled
This patch add getopt to the command list if it enabled via
Kconfig. With this patch we get a 'command not found' error.
Otherwise getopt doing nothing.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-02-11 20:57:33 +01:00
Sascha Hauer a01e54d201 treewide: fix format specifiers
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-01-27 14:24:10 +01:00
Sascha Hauer 77322aa896 Treewide: remove address of the Free Software Foundation
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>
2012-09-17 10:57:41 +02:00
Sascha Hauer 4d902142a5 hush: catch errors from execute_binfmt
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>
2012-08-10 20:59:58 +02:00
Sascha Hauer 16edced39e hush: Make exit a shell builtin
'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>
2012-08-10 20:59:55 +02:00
Sascha Hauer 1d3ab47e13 hush getopt: shift argv arguments
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>
2012-07-04 23:39:05 +02:00
Sascha Hauer 169a770faf hush: do not convert to return code too early
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>
2012-05-23 16:12:50 +02:00
Sascha Hauer 9448aa57ec run_shell: run again on ctrl-c
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>
2012-05-21 09:08:29 +02:00
Sascha Hauer ce38019845 Merge branch 'next'
Conflicts:
	common/hush.c

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-05-03 20:10:13 +02:00
Sascha Hauer ebde5ae5ac hush: bail out of scripts on syntax error
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>
2012-05-02 10:37:33 +02:00
Sascha Hauer e21a340e39 hush: allow to run interactive shell in do_sh
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>
2012-04-30 13:08:55 +02:00
Sascha Hauer f034ed2044 hush: Fix globbing
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>
2012-04-30 13:08:55 +02:00
Sascha Hauer f4762eb5e7 hush: pass GLOB_NOCHECK to glob
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>
2012-04-30 13:08:55 +02:00
Sascha Hauer 87681170f5 hush: simplify globhack
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>
2012-04-30 13:08:54 +02:00
Sascha Hauer 1aad6d033a hush: remove quotes at end of processing
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>
2012-04-30 13:08:54 +02:00
Sascha Hauer 37e77d3cfe hush: run_pipe_real: bail out early to safe an indention level
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-04-30 13:08:54 +02:00
Sascha Hauer 162e2a820d hush: run_pipe_real must have num_progs == 1
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-04-30 13:08:54 +02:00
Sascha Hauer 86c031783f hush: remove bogus 'else'
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-04-30 13:08:54 +02:00
Sascha Hauer 3996c942f2 hush: cleanup coding style
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>
2012-04-30 13:06:46 +02:00
Sascha Hauer b1c5b646b3 hush: safe an indention level by continueing a loop
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-04-30 13:06:43 +02:00
Sascha Hauer 8c3cc9621f hush: safe indention level by continueing a loop
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-04-30 13:04:49 +02:00
Jean-Christophe PLAGNIOL-VILLARD 071ceba1e3 Introduce binfmt support
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>
2012-04-18 20:14:12 +08:00
Sascha Hauer d94579abaf hush source: expand $PATH
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>
2012-03-18 15:03:31 +01:00
Sascha Hauer 33d1cc4bf2 commands: remove struct command pointer from commands
This is unused in all commands and thus can be removed.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2012-02-27 20:28:07 +01:00
Sascha Hauer aed0e6ba03 getopt: save and restore context
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>
2012-02-27 19:53:47 +01:00
Sascha Hauer 76dca8279e hush: Add magicvars
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2011-11-29 20:51:32 +01:00
Sascha Hauer 8e8c61e786 move simple_itoa to libbb so that others can use it
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2011-04-12 09:54:56 +02:00
Sascha Hauer 345d93eb7c hush: sparse fixes
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2010-10-21 22:21:24 +02:00
Sascha Hauer 914e2f8f7f hush: implement getopt builtin
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>
2010-10-08 15:30:43 +02:00
Sascha Hauer 97b2a33c50 hush: fix nasty memory leak in hush
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>
2010-10-08 14:18:37 +02:00
Sascha Hauer dff63d2399 hush: pass context around in shell
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2010-10-08 11:40:09 +02:00