diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-07-16 12:36:14 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-07-16 12:36:14 +0200 |
commit | 202a2d121905a6245cdf7441c9f83ff213b5502e (patch) | |
tree | 6e7ab10e31a21668a25df918e4f2ddd809d186a0 | |
parent | 3f5fae07725b0cc24587c7965f17ac57e5610bfb (diff) | |
download | busybox-w32-202a2d121905a6245cdf7441c9f83ff213b5502e.tar.gz busybox-w32-202a2d121905a6245cdf7441c9f83ff213b5502e.tar.bz2 busybox-w32-202a2d121905a6245cdf7441c9f83ff213b5502e.zip |
hush: make set -x support optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/applets.src.h | 5 | ||||
-rw-r--r-- | include/usage.src.h | 6 | ||||
-rw-r--r-- | shell/Config.src | 106 | ||||
-rw-r--r-- | shell/Kbuild.src | 2 | ||||
-rw-r--r-- | shell/hush.c | 155 |
5 files changed, 147 insertions, 127 deletions
diff --git a/include/applets.src.h b/include/applets.src.h index 9162b66c7..5d84597b0 100644 --- a/include/applets.src.h +++ b/include/applets.src.h | |||
@@ -76,7 +76,6 @@ IF_ASH(APPLET(ash, _BB_DIR_BIN, _BB_SUID_DROP)) | |||
76 | IF_AWK(APPLET_NOEXEC(awk, awk, _BB_DIR_USR_BIN, _BB_SUID_DROP, awk)) | 76 | IF_AWK(APPLET_NOEXEC(awk, awk, _BB_DIR_USR_BIN, _BB_SUID_DROP, awk)) |
77 | IF_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_DROP, basename)) | 77 | IF_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_DROP, basename)) |
78 | IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, _BB_DIR_BIN, _BB_SUID_DROP, bash)) | 78 | IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, _BB_DIR_BIN, _BB_SUID_DROP, bash)) |
79 | IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, _BB_DIR_BIN, _BB_SUID_DROP, bash)) | ||
80 | IF_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_DROP)) | 79 | IF_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_DROP)) |
81 | //IF_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_DROP)) | 80 | //IF_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_DROP)) |
82 | IF_BEEP(APPLET(beep, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | 81 | IF_BEEP(APPLET(beep, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
@@ -183,7 +182,6 @@ IF_HEXDUMP(APPLET_NOEXEC(hexdump, hexdump, _BB_DIR_USR_BIN, _BB_SUID_DROP, hexdu | |||
183 | IF_HOSTID(APPLET_NOFORK(hostid, hostid, _BB_DIR_USR_BIN, _BB_SUID_DROP, hostid)) | 182 | IF_HOSTID(APPLET_NOFORK(hostid, hostid, _BB_DIR_USR_BIN, _BB_SUID_DROP, hostid)) |
184 | IF_HOSTNAME(APPLET(hostname, _BB_DIR_BIN, _BB_SUID_DROP)) | 183 | IF_HOSTNAME(APPLET(hostname, _BB_DIR_BIN, _BB_SUID_DROP)) |
185 | IF_HTTPD(APPLET(httpd, _BB_DIR_USR_SBIN, _BB_SUID_DROP)) | 184 | IF_HTTPD(APPLET(httpd, _BB_DIR_USR_SBIN, _BB_SUID_DROP)) |
186 | IF_HUSH(APPLET(hush, _BB_DIR_BIN, _BB_SUID_DROP)) | ||
187 | IF_HWCLOCK(APPLET(hwclock, _BB_DIR_SBIN, _BB_SUID_DROP)) | 185 | IF_HWCLOCK(APPLET(hwclock, _BB_DIR_SBIN, _BB_SUID_DROP)) |
188 | IF_ID(APPLET(id, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | 186 | IF_ID(APPLET(id, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
189 | IF_IFCONFIG(APPLET(ifconfig, _BB_DIR_SBIN, _BB_SUID_DROP)) | 187 | IF_IFCONFIG(APPLET(ifconfig, _BB_DIR_SBIN, _BB_SUID_DROP)) |
@@ -218,7 +216,6 @@ IF_KILL(APPLET(kill, _BB_DIR_BIN, _BB_SUID_DROP)) | |||
218 | IF_KILLALL(APPLET_ODDNAME(killall, kill, _BB_DIR_USR_BIN, _BB_SUID_DROP, killall)) | 216 | IF_KILLALL(APPLET_ODDNAME(killall, kill, _BB_DIR_USR_BIN, _BB_SUID_DROP, killall)) |
219 | IF_KILLALL5(APPLET_ODDNAME(killall5, kill, _BB_DIR_USR_BIN, _BB_SUID_DROP, killall5)) | 217 | IF_KILLALL5(APPLET_ODDNAME(killall5, kill, _BB_DIR_USR_BIN, _BB_SUID_DROP, killall5)) |
220 | IF_KLOGD(APPLET(klogd, _BB_DIR_SBIN, _BB_SUID_DROP)) | 218 | IF_KLOGD(APPLET(klogd, _BB_DIR_SBIN, _BB_SUID_DROP)) |
221 | IF_LASH(APPLET(lash, _BB_DIR_BIN, _BB_SUID_DROP)) | ||
222 | IF_LAST(APPLET(last, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | 219 | IF_LAST(APPLET(last, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
223 | IF_LENGTH(APPLET_NOFORK(length, length, _BB_DIR_USR_BIN, _BB_SUID_DROP, length)) | 220 | IF_LENGTH(APPLET_NOFORK(length, length, _BB_DIR_USR_BIN, _BB_SUID_DROP, length)) |
224 | IF_LESS(APPLET(less, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | 221 | IF_LESS(APPLET(less, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
@@ -273,7 +270,6 @@ IF_MODPROBE_SMALL(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_DROP)) | |||
273 | IF_MORE(APPLET(more, _BB_DIR_BIN, _BB_SUID_DROP)) | 270 | IF_MORE(APPLET(more, _BB_DIR_BIN, _BB_SUID_DROP)) |
274 | IF_MOUNT(APPLET(mount, _BB_DIR_BIN, IF_DESKTOP(_BB_SUID_MAYBE) IF_NOT_DESKTOP(_BB_SUID_DROP))) | 271 | IF_MOUNT(APPLET(mount, _BB_DIR_BIN, IF_DESKTOP(_BB_SUID_MAYBE) IF_NOT_DESKTOP(_BB_SUID_DROP))) |
275 | IF_MOUNTPOINT(APPLET(mountpoint, _BB_DIR_BIN, _BB_SUID_DROP)) | 272 | IF_MOUNTPOINT(APPLET(mountpoint, _BB_DIR_BIN, _BB_SUID_DROP)) |
276 | IF_MSH(APPLET(msh, _BB_DIR_BIN, _BB_SUID_DROP)) | ||
277 | IF_MT(APPLET(mt, _BB_DIR_BIN, _BB_SUID_DROP)) | 273 | IF_MT(APPLET(mt, _BB_DIR_BIN, _BB_SUID_DROP)) |
278 | IF_MV(APPLET(mv, _BB_DIR_BIN, _BB_SUID_DROP)) | 274 | IF_MV(APPLET(mv, _BB_DIR_BIN, _BB_SUID_DROP)) |
279 | IF_NAMEIF(APPLET(nameif, _BB_DIR_SBIN, _BB_SUID_DROP)) | 275 | IF_NAMEIF(APPLET(nameif, _BB_DIR_SBIN, _BB_SUID_DROP)) |
@@ -349,7 +345,6 @@ IF_SETSEBOOL(APPLET(setsebool, _BB_DIR_USR_SBIN, _BB_SUID_DROP)) | |||
349 | IF_SETSID(APPLET(setsid, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | 345 | IF_SETSID(APPLET(setsid, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
350 | IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, _BB_DIR_USR_BIN, _BB_SUID_DROP, setuidgid)) | 346 | IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, _BB_DIR_USR_BIN, _BB_SUID_DROP, setuidgid)) |
351 | IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, _BB_DIR_BIN, _BB_SUID_DROP, sh)) | 347 | IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, _BB_DIR_BIN, _BB_SUID_DROP, sh)) |
352 | IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, _BB_DIR_BIN, _BB_SUID_DROP, sh)) | ||
353 | IF_SHA1SUM(APPLET_ODDNAME(sha1sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_DROP, sha1sum)) | 348 | IF_SHA1SUM(APPLET_ODDNAME(sha1sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_DROP, sha1sum)) |
354 | IF_SHA256SUM(APPLET_ODDNAME(sha256sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_DROP, sha256sum)) | 349 | IF_SHA256SUM(APPLET_ODDNAME(sha256sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_DROP, sha256sum)) |
355 | IF_SHA512SUM(APPLET_ODDNAME(sha512sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_DROP, sha512sum)) | 350 | IF_SHA512SUM(APPLET_ODDNAME(sha512sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_DROP, sha512sum)) |
diff --git a/include/usage.src.h b/include/usage.src.h index 94a3256b1..b3396006f 100644 --- a/include/usage.src.h +++ b/include/usage.src.h | |||
@@ -119,12 +119,6 @@ INSERT | |||
119 | #define sh_full_usage "" | 119 | #define sh_full_usage "" |
120 | #define ash_trivial_usage NOUSAGE_STR | 120 | #define ash_trivial_usage NOUSAGE_STR |
121 | #define ash_full_usage "" | 121 | #define ash_full_usage "" |
122 | #define hush_trivial_usage NOUSAGE_STR | ||
123 | #define hush_full_usage "" | ||
124 | #define lash_trivial_usage NOUSAGE_STR | ||
125 | #define lash_full_usage "" | ||
126 | #define msh_trivial_usage NOUSAGE_STR | ||
127 | #define msh_full_usage "" | ||
128 | #define bash_trivial_usage NOUSAGE_STR | 122 | #define bash_trivial_usage NOUSAGE_STR |
129 | #define bash_full_usage "" | 123 | #define bash_full_usage "" |
130 | 124 | ||
diff --git a/shell/Config.src b/shell/Config.src index 800911966..f415a5fa6 100644 --- a/shell/Config.src +++ b/shell/Config.src | |||
@@ -110,112 +110,6 @@ config ASH_EXPAND_PRMT | |||
110 | This option recreates the prompt string from the environment | 110 | This option recreates the prompt string from the environment |
111 | variable each time it is displayed. | 111 | variable each time it is displayed. |
112 | 112 | ||
113 | config HUSH | ||
114 | bool "hush" | ||
115 | default y | ||
116 | help | ||
117 | hush is a small shell (22k). It handles the normal flow control | ||
118 | constructs such as if/then/elif/else/fi, for/in/do/done, while loops, | ||
119 | case/esac. Redirections, here documents, $((arithmetic)) | ||
120 | and functions are supported. | ||
121 | |||
122 | It will compile and work on no-mmu systems. | ||
123 | |||
124 | It does not handle select, aliases, brace expansion, | ||
125 | tilde expansion, &>file and >&file redirection of stdout+stderr. | ||
126 | |||
127 | config HUSH_BASH_COMPAT | ||
128 | bool "bash-compatible extensions" | ||
129 | default y | ||
130 | depends on HUSH | ||
131 | help | ||
132 | Enable bash-compatible extensions. | ||
133 | |||
134 | config HUSH_HELP | ||
135 | bool "help builtin" | ||
136 | default y | ||
137 | depends on HUSH | ||
138 | help | ||
139 | Enable help builtin in hush. Code size + ~1 kbyte. | ||
140 | |||
141 | config HUSH_INTERACTIVE | ||
142 | bool "Interactive mode" | ||
143 | default y | ||
144 | depends on HUSH | ||
145 | help | ||
146 | Enable interactive mode (prompt and command editing). | ||
147 | Without this, hush simply reads and executes commands | ||
148 | from stdin just like a shell script from a file. | ||
149 | No prompt, no PS1/PS2 magic shell variables. | ||
150 | |||
151 | config HUSH_JOB | ||
152 | bool "Job control" | ||
153 | default y | ||
154 | depends on HUSH_INTERACTIVE | ||
155 | help | ||
156 | Enable job control: Ctrl-Z backgrounds, Ctrl-C interrupts current | ||
157 | command (not entire shell), fg/bg builtins work. Without this option, | ||
158 | "cmd &" still works by simply spawning a process and immediately | ||
159 | prompting for next command (or executing next command in a script), | ||
160 | but no separate process group is formed. | ||
161 | |||
162 | config HUSH_TICK | ||
163 | bool "Process substitution" | ||
164 | default y | ||
165 | depends on HUSH | ||
166 | help | ||
167 | Enable process substitution `command` and $(command) in hush. | ||
168 | |||
169 | config HUSH_IF | ||
170 | bool "Support if/then/elif/else/fi" | ||
171 | default y | ||
172 | depends on HUSH | ||
173 | help | ||
174 | Enable if/then/elif/else/fi in hush. | ||
175 | |||
176 | config HUSH_LOOPS | ||
177 | bool "Support for, while and until loops" | ||
178 | default y | ||
179 | depends on HUSH | ||
180 | help | ||
181 | Enable for, while and until loops in hush. | ||
182 | |||
183 | config HUSH_CASE | ||
184 | bool "Support case ... esac statement" | ||
185 | default y | ||
186 | depends on HUSH | ||
187 | help | ||
188 | Enable case ... esac statement in hush. +400 bytes. | ||
189 | |||
190 | config HUSH_FUNCTIONS | ||
191 | bool "Support funcname() { commands; } syntax" | ||
192 | default y | ||
193 | depends on HUSH | ||
194 | help | ||
195 | Enable support for shell functions in hush. +800 bytes. | ||
196 | |||
197 | config HUSH_LOCAL | ||
198 | bool "Support local builtin" | ||
199 | default y | ||
200 | depends on HUSH_FUNCTIONS | ||
201 | help | ||
202 | Enable support for local variables in functions. | ||
203 | |||
204 | config HUSH_EXPORT_N | ||
205 | bool "Support export '-n' option" | ||
206 | default y | ||
207 | depends on HUSH | ||
208 | help | ||
209 | Enable support for export '-n' option in hush. It is a bash extension. | ||
210 | |||
211 | config HUSH_RANDOM_SUPPORT | ||
212 | bool "Pseudorandom generator and $RANDOM variable" | ||
213 | default y | ||
214 | depends on HUSH | ||
215 | help | ||
216 | Enable pseudorandom generator and dynamic variable "$RANDOM". | ||
217 | Each read of "$RANDOM" will generate a new pseudorandom value. | ||
218 | |||
219 | 113 | ||
220 | choice | 114 | choice |
221 | prompt "Choose which shell is aliased to 'sh' name" | 115 | prompt "Choose which shell is aliased to 'sh' name" |
diff --git a/shell/Kbuild.src b/shell/Kbuild.src index d76b35386..c7eb5b61a 100644 --- a/shell/Kbuild.src +++ b/shell/Kbuild.src | |||
@@ -9,9 +9,7 @@ lib-y:= | |||
9 | INSERT | 9 | INSERT |
10 | 10 | ||
11 | lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o | 11 | lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o |
12 | lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o | ||
13 | lib-$(CONFIG_CTTYHACK) += cttyhack.o | 12 | lib-$(CONFIG_CTTYHACK) += cttyhack.o |
14 | 13 | ||
15 | lib-$(CONFIG_SH_MATH_SUPPORT) += math.o | 14 | lib-$(CONFIG_SH_MATH_SUPPORT) += math.o |
16 | lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o | 15 | lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o |
17 | lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o | ||
diff --git a/shell/hush.c b/shell/hush.c index 7640bd6ba..c67aebdd7 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -101,6 +101,136 @@ | |||
101 | # define PIPE_BUF 4096 /* amount of buffering in a pipe */ | 101 | # define PIPE_BUF 4096 /* amount of buffering in a pipe */ |
102 | #endif | 102 | #endif |
103 | 103 | ||
104 | //applet:IF_HUSH(APPLET(hush, _BB_DIR_BIN, _BB_SUID_DROP)) | ||
105 | //applet:IF_MSH(APPLET(msh, _BB_DIR_BIN, _BB_SUID_DROP)) | ||
106 | //applet:IF_LASH(APPLET(lash, _BB_DIR_BIN, _BB_SUID_DROP)) | ||
107 | //applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, _BB_DIR_BIN, _BB_SUID_DROP, sh)) | ||
108 | //applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, _BB_DIR_BIN, _BB_SUID_DROP, bash)) | ||
109 | |||
110 | //kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o | ||
111 | //kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o | ||
112 | |||
113 | //config:config HUSH | ||
114 | //config: bool "hush" | ||
115 | //config: default y | ||
116 | //config: help | ||
117 | //config: hush is a small shell (22k). It handles the normal flow control | ||
118 | //config: constructs such as if/then/elif/else/fi, for/in/do/done, while loops, | ||
119 | //config: case/esac. Redirections, here documents, $((arithmetic)) | ||
120 | //config: and functions are supported. | ||
121 | //config: | ||
122 | //config: It will compile and work on no-mmu systems. | ||
123 | //config: | ||
124 | //config: It does not handle select, aliases, brace expansion, | ||
125 | //config: tilde expansion, &>file and >&file redirection of stdout+stderr. | ||
126 | //config: | ||
127 | //config:config HUSH_BASH_COMPAT | ||
128 | //config: bool "bash-compatible extensions" | ||
129 | //config: default y | ||
130 | //config: depends on HUSH | ||
131 | //config: help | ||
132 | //config: Enable bash-compatible extensions. | ||
133 | //config: | ||
134 | //config:config HUSH_HELP | ||
135 | //config: bool "help builtin" | ||
136 | //config: default y | ||
137 | //config: depends on HUSH | ||
138 | //config: help | ||
139 | //config: Enable help builtin in hush. Code size + ~1 kbyte. | ||
140 | //config: | ||
141 | //config:config HUSH_INTERACTIVE | ||
142 | //config: bool "Interactive mode" | ||
143 | //config: default y | ||
144 | //config: depends on HUSH | ||
145 | //config: help | ||
146 | //config: Enable interactive mode (prompt and command editing). | ||
147 | //config: Without this, hush simply reads and executes commands | ||
148 | //config: from stdin just like a shell script from a file. | ||
149 | //config: No prompt, no PS1/PS2 magic shell variables. | ||
150 | //config: | ||
151 | //config:config HUSH_JOB | ||
152 | //config: bool "Job control" | ||
153 | //config: default y | ||
154 | //config: depends on HUSH_INTERACTIVE | ||
155 | //config: help | ||
156 | //config: Enable job control: Ctrl-Z backgrounds, Ctrl-C interrupts current | ||
157 | //config: command (not entire shell), fg/bg builtins work. Without this option, | ||
158 | //config: "cmd &" still works by simply spawning a process and immediately | ||
159 | //config: prompting for next command (or executing next command in a script), | ||
160 | //config: but no separate process group is formed. | ||
161 | //config: | ||
162 | //config:config HUSH_TICK | ||
163 | //config: bool "Process substitution" | ||
164 | //config: default y | ||
165 | //config: depends on HUSH | ||
166 | //config: help | ||
167 | //config: Enable process substitution `command` and $(command) in hush. | ||
168 | //config: | ||
169 | //config:config HUSH_IF | ||
170 | //config: bool "Support if/then/elif/else/fi" | ||
171 | //config: default y | ||
172 | //config: depends on HUSH | ||
173 | //config: help | ||
174 | //config: Enable if/then/elif/else/fi in hush. | ||
175 | //config: | ||
176 | //config:config HUSH_LOOPS | ||
177 | //config: bool "Support for, while and until loops" | ||
178 | //config: default y | ||
179 | //config: depends on HUSH | ||
180 | //config: help | ||
181 | //config: Enable for, while and until loops in hush. | ||
182 | //config: | ||
183 | //config:config HUSH_CASE | ||
184 | //config: bool "Support case ... esac statement" | ||
185 | //config: default y | ||
186 | //config: depends on HUSH | ||
187 | //config: help | ||
188 | //config: Enable case ... esac statement in hush. +400 bytes. | ||
189 | //config: | ||
190 | //config:config HUSH_FUNCTIONS | ||
191 | //config: bool "Support funcname() { commands; } syntax" | ||
192 | //config: default y | ||
193 | //config: depends on HUSH | ||
194 | //config: help | ||
195 | //config: Enable support for shell functions in hush. +800 bytes. | ||
196 | //config: | ||
197 | //config:config HUSH_LOCAL | ||
198 | //config: bool "Support local builtin" | ||
199 | //config: default y | ||
200 | //config: depends on HUSH_FUNCTIONS | ||
201 | //config: help | ||
202 | //config: Enable support for local variables in functions. | ||
203 | //config: | ||
204 | //config:config HUSH_RANDOM_SUPPORT | ||
205 | //config: bool "Pseudorandom generator and $RANDOM variable" | ||
206 | //config: default y | ||
207 | //config: depends on HUSH | ||
208 | //config: help | ||
209 | //config: Enable pseudorandom generator and dynamic variable "$RANDOM". | ||
210 | //config: Each read of "$RANDOM" will generate a new pseudorandom value. | ||
211 | //config: | ||
212 | //config:config HUSH_EXPORT_N | ||
213 | //config: bool "Support 'export -n' option" | ||
214 | //config: default y | ||
215 | //config: depends on HUSH | ||
216 | //config: help | ||
217 | //config: export -n unexports variables. It is a bash extension. | ||
218 | //config: | ||
219 | //config:config HUSH_MODE_X | ||
220 | //config: bool "Support 'hush -x' option and 'set -x' command" | ||
221 | //config: default y | ||
222 | //config: depends on HUSH | ||
223 | //config: help | ||
224 | //config: This instructs hush to print commands before execution. Adds ~300 bytes. | ||
225 | //config: | ||
226 | |||
227 | //usage:#define hush_trivial_usage NOUSAGE_STR | ||
228 | //usage:#define hush_full_usage "" | ||
229 | //usage:#define lash_trivial_usage NOUSAGE_STR | ||
230 | //usage:#define lash_full_usage "" | ||
231 | //usage:#define msh_trivial_usage NOUSAGE_STR | ||
232 | //usage:#define msh_full_usage "" | ||
233 | |||
104 | 234 | ||
105 | /* Build knobs */ | 235 | /* Build knobs */ |
106 | #define LEAK_HUNTING 0 | 236 | #define LEAK_HUNTING 0 |
@@ -531,8 +661,13 @@ struct globals { | |||
531 | */ | 661 | */ |
532 | smallint flag_return_in_progress; | 662 | smallint flag_return_in_progress; |
533 | #endif | 663 | #endif |
534 | smallint fake_mode; | 664 | smallint n_mode; |
665 | #if ENABLE_HUSH_MODE_X | ||
535 | smallint x_mode; | 666 | smallint x_mode; |
667 | # define G_x_mode G.x_mode | ||
668 | #else | ||
669 | # define G_x_mode 0 | ||
670 | #endif | ||
536 | smallint exiting; /* used to prevent EXIT trap recursion */ | 671 | smallint exiting; /* used to prevent EXIT trap recursion */ |
537 | /* These four support $?, $#, and $1 */ | 672 | /* These four support $?, $#, and $1 */ |
538 | smalluint last_exitcode; | 673 | smalluint last_exitcode; |
@@ -3693,9 +3828,10 @@ static void execvp_or_die(char **argv) | |||
3693 | _exit(127); /* bash compat */ | 3828 | _exit(127); /* bash compat */ |
3694 | } | 3829 | } |
3695 | 3830 | ||
3831 | #if ENABLE_HUSH_MODE_X | ||
3696 | static void dump_cmd_in_x_mode(char **argv) | 3832 | static void dump_cmd_in_x_mode(char **argv) |
3697 | { | 3833 | { |
3698 | if (G.x_mode && argv) { | 3834 | if (G_x_mode && argv) { |
3699 | /* We want to output the line in one write op */ | 3835 | /* We want to output the line in one write op */ |
3700 | char *buf, *p; | 3836 | char *buf, *p; |
3701 | int len; | 3837 | int len; |
@@ -3717,6 +3853,9 @@ static void dump_cmd_in_x_mode(char **argv) | |||
3717 | free(buf); | 3853 | free(buf); |
3718 | } | 3854 | } |
3719 | } | 3855 | } |
3856 | #else | ||
3857 | # define dump_cmd_in_x_mode(argv) ((void)0) | ||
3858 | #endif | ||
3720 | 3859 | ||
3721 | #if BB_MMU | 3860 | #if BB_MMU |
3722 | #define pseudo_exec_argv(nommu_save, argv, assignment_cnt, argv_expanded) \ | 3861 | #define pseudo_exec_argv(nommu_save, argv, assignment_cnt, argv_expanded) \ |
@@ -4267,18 +4406,18 @@ static NOINLINE int run_pipe(struct pipe *pi) | |||
4267 | rcode = setup_redirects(command, squirrel); | 4406 | rcode = setup_redirects(command, squirrel); |
4268 | restore_redirects(squirrel); | 4407 | restore_redirects(squirrel); |
4269 | /* Set shell variables */ | 4408 | /* Set shell variables */ |
4270 | if (G.x_mode) | 4409 | if (G_x_mode) |
4271 | bb_putchar_stderr('+'); | 4410 | bb_putchar_stderr('+'); |
4272 | while (*argv) { | 4411 | while (*argv) { |
4273 | p = expand_string_to_string(*argv); | 4412 | p = expand_string_to_string(*argv); |
4274 | if (G.x_mode) | 4413 | if (G_x_mode) |
4275 | fprintf(stderr, " %s", p); | 4414 | fprintf(stderr, " %s", p); |
4276 | debug_printf_exec("set shell var:'%s'->'%s'\n", | 4415 | debug_printf_exec("set shell var:'%s'->'%s'\n", |
4277 | *argv, p); | 4416 | *argv, p); |
4278 | set_local_var(p, /*exp:*/ 0, /*lvl:*/ 0, /*ro:*/ 0); | 4417 | set_local_var(p, /*exp:*/ 0, /*lvl:*/ 0, /*ro:*/ 0); |
4279 | argv++; | 4418 | argv++; |
4280 | } | 4419 | } |
4281 | if (G.x_mode) | 4420 | if (G_x_mode) |
4282 | bb_putchar_stderr('\n'); | 4421 | bb_putchar_stderr('\n'); |
4283 | /* Redirect error sets $? to 1. Otherwise, | 4422 | /* Redirect error sets $? to 1. Otherwise, |
4284 | * if evaluating assignment value set $?, retain it. | 4423 | * if evaluating assignment value set $?, retain it. |
@@ -4943,7 +5082,7 @@ static int run_and_free_list(struct pipe *pi) | |||
4943 | { | 5082 | { |
4944 | int rcode = 0; | 5083 | int rcode = 0; |
4945 | debug_printf_exec("run_and_free_list entered\n"); | 5084 | debug_printf_exec("run_and_free_list entered\n"); |
4946 | if (!G.fake_mode) { | 5085 | if (!G.n_mode) { |
4947 | debug_printf_exec(": run_list: 1st pipe with %d cmds\n", pi->num_cmds); | 5086 | debug_printf_exec(": run_list: 1st pipe with %d cmds\n", pi->num_cmds); |
4948 | rcode = run_list(pi); | 5087 | rcode = run_list(pi); |
4949 | } | 5088 | } |
@@ -6969,8 +7108,8 @@ static int set_mode(const char cstate, const char mode) | |||
6969 | { | 7108 | { |
6970 | int state = (cstate == '-' ? 1 : 0); | 7109 | int state = (cstate == '-' ? 1 : 0); |
6971 | switch (mode) { | 7110 | switch (mode) { |
6972 | case 'n': G.fake_mode = state; break; | 7111 | case 'n': G.n_mode = state; break; |
6973 | case 'x': G.x_mode = state; break; | 7112 | case 'x': IF_HUSH_MODE_X(G_x_mode = state;) break; |
6974 | default: return EXIT_FAILURE; | 7113 | default: return EXIT_FAILURE; |
6975 | } | 7114 | } |
6976 | return EXIT_SUCCESS; | 7115 | return EXIT_SUCCESS; |