aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-08 18:28:43 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-08 18:28:43 +0100
commit10d5ece64ae6b2338a13a58340a03ff988d46a85 (patch)
tree69c26f7c85f6887b72c1bc810ebdd602958add97 /shell
parent7a85c60e7e370d0bc171bd10043c1eb7c20ab913 (diff)
downloadbusybox-w32-10d5ece64ae6b2338a13a58340a03ff988d46a85.tar.gz
busybox-w32-10d5ece64ae6b2338a13a58340a03ff988d46a85.tar.bz2
busybox-w32-10d5ece64ae6b2338a13a58340a03ff988d46a85.zip
hush: make set/unset builtins optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index e6e8c1baf..4604240d8 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -258,6 +258,20 @@
258//config: help 258//config: help
259//config: Enable read builtin in hush. 259//config: Enable read builtin in hush.
260//config: 260//config:
261//config:config HUSH_SET
262//config: bool "set builtin"
263//config: default y
264//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
265//config: help
266//config: Enable set builtin in hush.
267//config:
268//config:config HUSH_UNSET
269//config: bool "unset builtin"
270//config: default y
271//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
272//config: help
273//config: Enable unset builtin in hush.
274//config:
261//config:config MSH 275//config:config MSH
262//config: bool "msh (deprecated: aliased to hush)" 276//config: bool "msh (deprecated: aliased to hush)"
263//config: default n 277//config: default n
@@ -920,7 +934,9 @@ static int builtin_pwd(char **argv) FAST_FUNC;
920#if ENABLE_HUSH_READ 934#if ENABLE_HUSH_READ
921static int builtin_read(char **argv) FAST_FUNC; 935static int builtin_read(char **argv) FAST_FUNC;
922#endif 936#endif
937#if ENABLE_HUSH_SET
923static int builtin_set(char **argv) FAST_FUNC; 938static int builtin_set(char **argv) FAST_FUNC;
939#endif
924static int builtin_shift(char **argv) FAST_FUNC; 940static int builtin_shift(char **argv) FAST_FUNC;
925static int builtin_source(char **argv) FAST_FUNC; 941static int builtin_source(char **argv) FAST_FUNC;
926static int builtin_test(char **argv) FAST_FUNC; 942static int builtin_test(char **argv) FAST_FUNC;
@@ -932,7 +948,9 @@ static int builtin_type(char **argv) FAST_FUNC;
932#endif 948#endif
933static int builtin_true(char **argv) FAST_FUNC; 949static int builtin_true(char **argv) FAST_FUNC;
934static int builtin_umask(char **argv) FAST_FUNC; 950static int builtin_umask(char **argv) FAST_FUNC;
951#if ENABLE_HUSH_UNSET
935static int builtin_unset(char **argv) FAST_FUNC; 952static int builtin_unset(char **argv) FAST_FUNC;
953#endif
936#if ENABLE_HUSH_KILL 954#if ENABLE_HUSH_KILL
937static int builtin_kill(char **argv) FAST_FUNC; 955static int builtin_kill(char **argv) FAST_FUNC;
938#endif 956#endif
@@ -1008,7 +1026,9 @@ static const struct built_in_command bltins1[] = {
1008#if ENABLE_HUSH_FUNCTIONS 1026#if ENABLE_HUSH_FUNCTIONS
1009 BLTIN("return" , builtin_return , "Return from a function"), 1027 BLTIN("return" , builtin_return , "Return from a function"),
1010#endif 1028#endif
1029#if ENABLE_HUSH_SET
1011 BLTIN("set" , builtin_set , "Set/unset positional parameters"), 1030 BLTIN("set" , builtin_set , "Set/unset positional parameters"),
1031#endif
1012 BLTIN("shift" , builtin_shift , "Shift positional parameters"), 1032 BLTIN("shift" , builtin_shift , "Shift positional parameters"),
1013#if ENABLE_HUSH_BASH_COMPAT 1033#if ENABLE_HUSH_BASH_COMPAT
1014 BLTIN("source" , builtin_source , "Run commands in a file"), 1034 BLTIN("source" , builtin_source , "Run commands in a file"),
@@ -1021,10 +1041,12 @@ static const struct built_in_command bltins1[] = {
1021 BLTIN("type" , builtin_type , "Show command type"), 1041 BLTIN("type" , builtin_type , "Show command type"),
1022#endif 1042#endif
1023#if ENABLE_HUSH_ULIMIT 1043#if ENABLE_HUSH_ULIMIT
1024 BLTIN("ulimit" , shell_builtin_ulimit , "Control resource limits"), 1044 BLTIN("ulimit" , shell_builtin_ulimit, "Control resource limits"),
1025#endif 1045#endif
1026 BLTIN("umask" , builtin_umask , "Set file creation mask"), 1046 BLTIN("umask" , builtin_umask , "Set file creation mask"),
1047#if ENABLE_HUSH_UNSET
1027 BLTIN("unset" , builtin_unset , "Unset variables"), 1048 BLTIN("unset" , builtin_unset , "Unset variables"),
1049#endif
1028#if ENABLE_HUSH_WAIT 1050#if ENABLE_HUSH_WAIT
1029 BLTIN("wait" , builtin_wait , "Wait for process"), 1051 BLTIN("wait" , builtin_wait , "Wait for process"),
1030#endif 1052#endif
@@ -2107,10 +2129,12 @@ static int unset_local_var_len(const char *name, int name_len)
2107 return EXIT_SUCCESS; 2129 return EXIT_SUCCESS;
2108} 2130}
2109 2131
2132#if ENABLE_HUSH_UNSET
2110static int unset_local_var(const char *name) 2133static int unset_local_var(const char *name)
2111{ 2134{
2112 return unset_local_var_len(name, strlen(name)); 2135 return unset_local_var_len(name, strlen(name));
2113} 2136}
2137#endif
2114 2138
2115static void unset_vars(char **strings) 2139static void unset_vars(char **strings)
2116{ 2140{
@@ -6712,6 +6736,7 @@ static struct function *new_function(char *name)
6712 return funcp; 6736 return funcp;
6713} 6737}
6714 6738
6739# if ENABLE_HUSH_UNSET
6715static void unset_func(const char *name) 6740static void unset_func(const char *name)
6716{ 6741{
6717 struct function **funcpp = find_function_slot(name); 6742 struct function **funcpp = find_function_slot(name);
@@ -6727,13 +6752,14 @@ static void unset_func(const char *name)
6727 if (funcp->body) { 6752 if (funcp->body) {
6728 free_pipe_list(funcp->body); 6753 free_pipe_list(funcp->body);
6729 free(funcp->name); 6754 free(funcp->name);
6730# if !BB_MMU 6755# if !BB_MMU
6731 free(funcp->body_as_string); 6756 free(funcp->body_as_string);
6732# endif 6757# endif
6733 } 6758 }
6734 free(funcp); 6759 free(funcp);
6735 } 6760 }
6736} 6761}
6762# endif
6737 6763
6738# if BB_MMU 6764# if BB_MMU
6739#define exec_function(to_free, funcp, argv) \ 6765#define exec_function(to_free, funcp, argv) \
@@ -9016,6 +9042,7 @@ static int FAST_FUNC builtin_local(char **argv)
9016} 9042}
9017#endif 9043#endif
9018 9044
9045#if ENABLE_HUSH_UNSET
9019/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset */ 9046/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset */
9020static int FAST_FUNC builtin_unset(char **argv) 9047static int FAST_FUNC builtin_unset(char **argv)
9021{ 9048{
@@ -9043,16 +9070,18 @@ static int FAST_FUNC builtin_unset(char **argv)
9043 ret = EXIT_FAILURE; 9070 ret = EXIT_FAILURE;
9044 } 9071 }
9045 } 9072 }
9046#if ENABLE_HUSH_FUNCTIONS 9073# if ENABLE_HUSH_FUNCTIONS
9047 else { 9074 else {
9048 unset_func(*argv); 9075 unset_func(*argv);
9049 } 9076 }
9050#endif 9077# endif
9051 argv++; 9078 argv++;
9052 } 9079 }
9053 return ret; 9080 return ret;
9054} 9081}
9082#endif
9055 9083
9084#if ENABLE_HUSH_SET
9056/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set 9085/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set
9057 * built-in 'set' handler 9086 * built-in 'set' handler
9058 * SUSv3 says: 9087 * SUSv3 says:
@@ -9135,6 +9164,7 @@ static int FAST_FUNC builtin_set(char **argv)
9135 bb_error_msg("set: %s: invalid option", arg); 9164 bb_error_msg("set: %s: invalid option", arg);
9136 return EXIT_FAILURE; 9165 return EXIT_FAILURE;
9137} 9166}
9167#endif
9138 9168
9139static int FAST_FUNC builtin_shift(char **argv) 9169static int FAST_FUNC builtin_shift(char **argv)
9140{ 9170{