summaryrefslogtreecommitdiffstats
path: root/common/hush.c
Commit message (Collapse)AuthorAgeFilesLines
* Shell: Handle aborting loops betterSascha Hauer2019-04-241-1/+2
| | | | | | | | | | | | | | | | | | It's easy to get stuck in an infinite loop in the hush shell: while true; do sleep 1; done The 'sleep' command will check for ctrl-c with the ctrlc() function. This will abort the sleep command. Hush then checks for ctrl-c again in the loop. The ctrl-c in the buffer has already been eaten by the sleep command, so the loop will continue. With this patch we remember the presence of a ctrl-c character in a variable instead of checking for a new character each time. The variable must be resetted explicitly by calling ctrlc_handled() which will be called by the shell in the outer loop. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: Add extra define for hush debuggingSascha Hauer2018-11-271-25/+30
| | | | | | | | | | I've seen people increasing the compile loglevel to get more debugging output from barebox. This is generally a good idea, but the tons of hush debugging printed makes barebox quite unusable. This patch puts hush debugging behind an extra HUSH_DEBUG define so increasing the compile loglevel no longer results in hush debugging. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: Add pr_fmt defineSascha Hauer2018-11-271-0/+3
| | | | | | To give the hush debug output more context. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: make source_aliases[] constIan Abbott2017-05-191-1/+1
| | | | | | | | Although the elements of `source_aliases[]` are of type `const char *`, the elements themselves are not const-qualified. Make them `const`. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: fix indentationSascha Hauer2016-01-111-17/+17
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: Initialize struct p_contextSascha Hauer2016-01-111-3/+3
| | | | | | | The hush context must be initialized before it is used. Add initialization where necessary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: Add missing initialize_context() in some placesSascha Hauer2015-11-051-0/+6
| | | | | | | | | Before a context can be used it must be initialized. This was forgotten in several places. Add the missing calls to initialize_context(). This fixes crashes when sourcing empty files Reported-by: Wjatscheslaw Stoljarski <wjatscheslaw.stoljarski@kiwigrid.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* login: rework login mechanismSascha Hauer2015-08-281-0/+3
| | | | | | | | | | | | | | We used to have the login functionality in the /env/bin/init script. This is hard to review and it's too easy to break the login functionality with changes to this script. Move the places to ask for a password to C code where we have only a few places where we have to ask for a password. Mainly these are run_shell() and the menutree command. This patch introduces a login() function which will only return if the correct password has been entered. Following calls will return immediately without asking for a password again. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Fix spelling: pathes -> pathsWadim Egorov2015-01-281-1/+1
| | | | | Signed-off-by: Wadim Egorov <w.egorov@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2014-08-071-1/+1
|\ | | | | | | | | Conflicts: lib/Makefile
| * hush: Fix error code returned valueHerve Codina2014-07-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | Just returns error code instead of 0 or 1. With this fix, $? is set to child exit code in all cases. Without this fix, /child $PATH;echo $? displays 1 even if child script calls exit with a specific non zero error code. Signed-off-by: Herve Codina <Herve.CODINA@celad.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | move file helper functions to separate fileSascha Hauer2014-08-071-0/+1
|/ | | | | | | | | | We have our file helper functions in several places. Move them all to lib/libfile.c. With this we no longer have file helpers in fs/fs.c which contains the core fs functions and no functions in lib/libbb.c which are not from busybox. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2014-06-041-5/+7
|\ | | | | | | | | Conflicts: commands/devinfo.c
| * hush: setting variables may failSascha Hauer2014-05-161-5/+7
| | | | | | | | | | | | | | | | 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>
* | commands: HUSH_GETOPT -> CMD_GETOPTHolger Schurig2014-05-141-4/+4
| | | | | | | | | | | | | | | | | | | | | | * 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>
* | commands: harmonize in-barebox documentationHolger Schurig2014-05-141-33/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | commands: group 'help' outputHolger Schurig2014-05-141-0/+4
|/ | | | | | | | | | | | | | | | | | | 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>
* Add shell_expand functionSascha Hauer2014-03-281-0/+33
| | | | | | shell_expand expands shell variables in a string. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* run_command: remove unused flag parameterSascha Hauer2014-03-071-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: refactor reserved_word()Sascha Hauer2013-11-121-32/+32
| | | | | | Save indentation level for easier readability. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: use standard ARRAY_SIZESascha Hauer2013-11-121-2/+4
| | | | | | Use standard ARRAY_SIZE instead of handcrafted NRES. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: Be more informative on syntax errorSascha Hauer2013-11-121-3/+22
| | | | | | | Print the token that led to a syntax error, at least for the common case. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* consolidate syntax() and syntax_err()Sascha Hauer2013-11-121-4/+3
| | | | | | syntax is defined as syntax_err. Drop syntax_err and call syntax instead. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: rename __promptme to interruptSascha Hauer2013-11-121-10/+8
| | | | | | | 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>
* hush: refactor file_get()Sascha Hauer2013-11-121-13/+15
| | | | | | Save indentation level by returning early. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: refactor get_user_input()Sascha Hauer2013-11-121-15/+17
| | | | | | Save indentation level by returning early. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: refactor readline callSascha Hauer2013-11-121-5/+6
| | | | | | | Don't call readline in if/else, instead setup a variable and call it once. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: fix exit on syntax error behaviourSascha Hauer2013-11-121-2/+5
| | | | | | | | | | | | 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>
* process_escape_sequence: add support to \$?Jean-Christophe PLAGNIOL-VILLARD2013-09-181-0/+6
| | | | | Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Fix typo seperate -> separateSascha Hauer2013-05-211-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: implement $*Sascha Hauer2013-02-261-0/+21
| | | | | | To get all arguments a script is called with. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* hush: add getopt only if it enabledAlexander Aring2013-02-111-1/+2
| | | | | | | | | 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>
* treewide: fix format specifiersSascha Hauer2013-01-271-3/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Treewide: remove address of the Free Software FoundationSascha Hauer2012-09-171-3/+0
| | | | | | | 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>
* hush: catch errors from execute_binfmtSascha Hauer2012-08-101-3/+8
| | | | | | | 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>
* hush: Make exit a shell builtinSascha Hauer2012-08-101-5/+31
| | | | | | | | | | | | | | | | | | | | '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>
* hush getopt: shift argv argumentsSascha Hauer2012-07-041-1/+4
| | | | | | | | 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>
* hush: do not convert to return code too earlySascha Hauer2012-05-231-5/+11
| | | | | | | | | | | | | | | | | 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>
* run_shell: run again on ctrl-cSascha Hauer2012-05-211-4/+6
| | | | | | | | 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>
* Merge branch 'next'Sascha Hauer2012-05-031-316/+486
|\ | | | | | | | | | | | | Conflicts: common/hush.c Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * hush: allow to run interactive shell in do_shSascha Hauer2012-04-301-1/+1
| | | | | | | | | | | | | | 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: Fix globbingSascha Hauer2012-04-301-48/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * hush: pass GLOB_NOCHECK to globSascha Hauer2012-04-301-6/+1
| | | | | | | | | | | | | | 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: simplify globhackSascha Hauer2012-04-301-31/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: remove quotes at end of processingSascha Hauer2012-04-301-23/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * hush: run_pipe_real: bail out early to safe an indention levelSascha Hauer2012-04-301-51/+47
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * hush: run_pipe_real must have num_progs == 1Sascha Hauer2012-04-301-7/+9
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * hush: remove bogus 'else'Sascha Hauer2012-04-301-1/+3
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * hush: cleanup coding styleSascha Hauer2012-04-301-109/+221
| | | | | | | | | | | | | | | | | | 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>
| * hush: safe an indention level by continueing a loopSascha Hauer2012-04-301-66/+69
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>