firmware-utils: update to version 2021-10-05
[openwrt/staging/dedeckeh.git] / package / utils / busybox / patches / 002-backport-ash-process-substitution.patch
1 Stacy Harper reports that this script:
2
3 test() { . /tmp/bb_test; }
4 echo "export TEST=foo" >/tmp/bb_test
5 test 2>/dev/null
6 echo "$TEST"
7
8 correctly prints 'foo' in BusyBox 1.33 but hangs in 1.34.
9
10 Bisection suggested the problem was caused by commit a1b0d3856 (ash: add
11 process substitution in bash-compatibility mode). Removing the call to
12 unwindredir() in cmdloop() introduced in that commit makes the script
13 work again.
14
15 Additionally, these examples of process substitution:
16
17 while true; do cat <(echo hi); done
18 f() { while true; do cat <(echo hi); done }
19 f
20
21 result in running out of file descriptors. This is a regression from
22 v5 of the process substitution patch caused by changes to evalcommand()
23 not being transferred to v6.
24
25 function old new delta
26 static.pushredir - 99 +99
27 evalcommand 1729 1750 +21
28 exitreset 69 86 +17
29 cmdloop 372 365 -7
30 unwindredir 28 - -28
31 pushredir 112 - -112
32 ------------------------------------------------------------------------------
33 (add/remove: 1/2 grow/shrink: 2/1 up/down: 137/-147) Total: -10 bytes
34
35 Signed-off-by: Ron Yorston <rmy at pobox.com>
36 ---
37 shell/ash.c | 10 +++++++---
38 1 file changed, 7 insertions(+), 3 deletions(-)
39
40 diff --git a/shell/ash.c b/shell/ash.c
41 index b5947147a..53c140930 100644
42 --- a/shell/ash.c
43 +++ b/shell/ash.c
44 @@ -10278,6 +10278,9 @@ evalcommand(union node *cmd, int flags)
45
46 /* First expand the arguments. */
47 TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
48 +#if BASH_PROCESS_SUBST
49 + redir_stop = redirlist;
50 +#endif
51 file_stop = g_parsefile;
52 back_exitstatus = 0;
53
54 @@ -10356,7 +10359,11 @@ evalcommand(union node *cmd, int flags)
55 lastarg = nargv[-1];
56
57 expredir(cmd->ncmd.redirect);
58 +#if !BASH_PROCESS_SUBST
59 redir_stop = pushredir(cmd->ncmd.redirect);
60 +#else
61 + pushredir(cmd->ncmd.redirect);
62 +#endif
63 preverrout_fd = 2;
64 if (BASH_XTRACEFD && xflag) {
65 /* NB: bash closes fd == $BASH_XTRACEFD when it is changed.
66 @@ -13476,9 +13483,6 @@ cmdloop(int top)
67 #if JOBS
68 if (doing_jobctl)
69 showjobs(SHOW_CHANGED|SHOW_STDERR);
70 -#endif
71 -#if BASH_PROCESS_SUBST
72 - unwindredir(NULL);
73 #endif
74 inter = 0;
75 if (iflag && top) {
76 --
77 2.31.1