diff options
| author | Xiangyu Chen <xiangyu.chen@windriver.com> | 2023-11-30 20:11:59 +0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-12-04 11:23:37 +0000 |
| commit | b0e7eda54f47510e35f246b6f7dce2c1f88842cb (patch) | |
| tree | c0abb37bde881ae81590b39e271cafc961a79852 /meta | |
| parent | 377078dd943ad34639300fa1263b61e589fb594a (diff) | |
| download | poky-b0e7eda54f47510e35f246b6f7dce2c1f88842cb.tar.gz | |
bash: changes to SIGINT handler while waiting for a child
It rarely observes the problem while running shell script aborting
test repeatedly, at the problem, the test shell script never returns
to shell
Steps to reproduce:
1. Run test script and ctrl-c repeatedly
2. Observe whether returns to shell after ctrl-c
(From OE-Core rev: 1b69769b52c888d74c0ba258b7450e05a6c82a5a)
Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/recipes-extended/bash/bash/0001-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch | 226 | ||||
| -rw-r--r-- | meta/recipes-extended/bash/bash_5.2.21.bb | 1 |
2 files changed, 227 insertions, 0 deletions
diff --git a/meta/recipes-extended/bash/bash/0001-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch b/meta/recipes-extended/bash/bash/0001-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch new file mode 100644 index 0000000000..df92c2475d --- /dev/null +++ b/meta/recipes-extended/bash/bash/0001-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch | |||
| @@ -0,0 +1,226 @@ | |||
| 1 | From 721d5be99eb37d31e48bd66d61808a66a4c5ab84 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Chet Ramey <chet.ramey@case.edu> | ||
| 3 | Date: Mon, 30 Oct 2023 12:16:07 -0400 | ||
| 4 | Subject: [PATCH] changes to SIGINT handler while waiting for a child; skip | ||
| 5 | vertical whitespace after translating an integer | ||
| 6 | |||
| 7 | Upstream-Status: Backport from | ||
| 8 | [https://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=fe24a6a55e8850298b496c5b9d82f1866eba190e] | ||
| 9 | |||
| 10 | [Adjust and drop some codes to be applicable the tree] | ||
| 11 | |||
| 12 | Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com> | ||
| 13 | --- | ||
| 14 | general.c | 5 +++-- | ||
| 15 | jobs.c | 24 ++++++++++++++++-------- | ||
| 16 | tests/redir.right | 4 ++-- | ||
| 17 | tests/redir11.sub | 2 ++ | ||
| 18 | tests/type.right | 16 ++++++++-------- | ||
| 19 | tests/type.tests | 24 ++++++++++++------------ | ||
| 20 | 6 files changed, 43 insertions(+), 32 deletions(-) | ||
| 21 | |||
| 22 | diff --git a/general.c b/general.c | ||
| 23 | index 85c5a8b6..65e2ee06 100644 | ||
| 24 | --- a/general.c | ||
| 25 | +++ b/general.c | ||
| 26 | @@ -262,8 +262,9 @@ legal_number (string, result) | ||
| 27 | if (errno || ep == string) | ||
| 28 | return 0; /* errno is set on overflow or underflow */ | ||
| 29 | |||
| 30 | - /* Skip any trailing whitespace, since strtoimax does not. */ | ||
| 31 | - while (whitespace (*ep)) | ||
| 32 | + /* Skip any trailing whitespace, since strtoimax does not, using the same | ||
| 33 | + test that strtoimax uses for leading whitespace. */ | ||
| 34 | + while (isspace ((unsigned char) *ep)) | ||
| 35 | ep++; | ||
| 36 | |||
| 37 | /* If *string is not '\0' but *ep is '\0' on return, the entire string | ||
| 38 | diff --git a/jobs.c b/jobs.c | ||
| 39 | index 6b986ed7..262d78de 100644 | ||
| 40 | --- a/jobs.c | ||
| 41 | +++ b/jobs.c | ||
| 42 | @@ -2718,6 +2718,10 @@ wait_for_background_pids (ps) | ||
| 43 | #define INVALID_SIGNAL_HANDLER (SigHandler *)wait_for_background_pids | ||
| 44 | static SigHandler *old_sigint_handler = INVALID_SIGNAL_HANDLER; | ||
| 45 | |||
| 46 | +/* The current SIGINT handler as set by restore_sigint_handler. Only valid | ||
| 47 | + immediately after restore_sigint_handler, used for continuations. */ | ||
| 48 | +static SigHandler *cur_sigint_handler = INVALID_SIGNAL_HANDLER; | ||
| 49 | + | ||
| 50 | static int wait_sigint_received; | ||
| 51 | static int child_caught_sigint; | ||
| 52 | |||
| 53 | @@ -2735,6 +2739,7 @@ wait_sigint_cleanup () | ||
| 54 | static void | ||
| 55 | restore_sigint_handler () | ||
| 56 | { | ||
| 57 | + cur_sigint_handler = old_sigint_handler; | ||
| 58 | if (old_sigint_handler != INVALID_SIGNAL_HANDLER) | ||
| 59 | { | ||
| 60 | set_signal_handler (SIGINT, old_sigint_handler); | ||
| 61 | @@ -2758,8 +2763,7 @@ wait_sigint_handler (sig) | ||
| 62 | restore_sigint_handler (); | ||
| 63 | /* If we got a SIGINT while in `wait', and SIGINT is trapped, do | ||
| 64 | what POSIX.2 says (see builtins/wait.def for more info). */ | ||
| 65 | - if (this_shell_builtin && this_shell_builtin == wait_builtin && | ||
| 66 | - signal_is_trapped (SIGINT) && | ||
| 67 | + if (signal_is_trapped (SIGINT) && | ||
| 68 | ((sigint_handler = trap_to_sighandler (SIGINT)) == trap_handler)) | ||
| 69 | { | ||
| 70 | trap_handler (SIGINT); /* set pending_traps[SIGINT] */ | ||
| 71 | @@ -2782,6 +2786,8 @@ wait_sigint_handler (sig) | ||
| 72 | { | ||
| 73 | set_exit_status (128+SIGINT); | ||
| 74 | restore_sigint_handler (); | ||
| 75 | + if (cur_sigint_handler == INVALID_SIGNAL_HANDLER) | ||
| 76 | + set_sigint_handler (); /* XXX - only do this in one place */ | ||
| 77 | kill (getpid (), SIGINT); | ||
| 78 | } | ||
| 79 | |||
| 80 | @@ -2926,11 +2932,13 @@ wait_for (pid, flags) | ||
| 81 | { | ||
| 82 | SigHandler *temp_sigint_handler; | ||
| 83 | |||
| 84 | - temp_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler); | ||
| 85 | - if (temp_sigint_handler == wait_sigint_handler) | ||
| 86 | - internal_debug ("wait_for: recursively setting old_sigint_handler to wait_sigint_handler: running_trap = %d", running_trap); | ||
| 87 | - else | ||
| 88 | - old_sigint_handler = temp_sigint_handler; | ||
| 89 | + temp_sigint_handler = old_sigint_handler; | ||
| 90 | + old_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler); | ||
| 91 | + if (old_sigint_handler == wait_sigint_handler) | ||
| 92 | + { | ||
| 93 | + internal_debug ("wait_for: recursively setting old_sigint_handler to wait_sigint_handler: running_trap = %d", running_trap); | ||
| 94 | + old_sigint_handler = temp_sigint_handler; | ||
| 95 | + } | ||
| 96 | waiting_for_child = 0; | ||
| 97 | if (old_sigint_handler == SIG_IGN) | ||
| 98 | set_signal_handler (SIGINT, old_sigint_handler); | ||
| 99 | @@ -4136,7 +4144,7 @@ set_job_status_and_cleanup (job) | ||
| 100 | SIGINT (if we reset the sighandler to the default). | ||
| 101 | In this case, we have to fix things up. What a crock. */ | ||
| 102 | if (temp_handler == trap_handler && signal_is_trapped (SIGINT) == 0) | ||
| 103 | - temp_handler = trap_to_sighandler (SIGINT); | ||
| 104 | + temp_handler = trap_to_sighandler (SIGINT); | ||
| 105 | restore_sigint_handler (); | ||
| 106 | if (temp_handler == SIG_DFL) | ||
| 107 | termsig_handler (SIGINT); /* XXX */ | ||
| 108 | diff --git a/tests/redir.right b/tests/redir.right | ||
| 109 | index 8db10414..9e1403c8 100644 | ||
| 110 | --- a/tests/redir.right | ||
| 111 | +++ b/tests/redir.right | ||
| 112 | @@ -154,10 +154,10 @@ foo | ||
| 113 | 1 | ||
| 114 | 7 | ||
| 115 | after: 42 | ||
| 116 | -./redir11.sub: line 53: $(ss= declare -i ss): ambiguous redirect | ||
| 117 | +./redir11.sub: line 55: $(ss= declare -i ss): ambiguous redirect | ||
| 118 | after: 42 | ||
| 119 | a+=3 | ||
| 120 | foo | ||
| 121 | foo | ||
| 122 | -./redir11.sub: line 75: 42: No such file or directory | ||
| 123 | +./redir11.sub: line 77: 42: No such file or directory | ||
| 124 | 42 | ||
| 125 | diff --git a/tests/redir11.sub b/tests/redir11.sub | ||
| 126 | index d417cdb6..ca9854cd 100644 | ||
| 127 | --- a/tests/redir11.sub | ||
| 128 | +++ b/tests/redir11.sub | ||
| 129 | @@ -34,6 +34,8 @@ a=4 b=7 ss=4 declare -i ss | ||
| 130 | a=4 b=7 foo | ||
| 131 | echo after: $a | ||
| 132 | |||
| 133 | +exec 7>&- 4>&- | ||
| 134 | + | ||
| 135 | unset a | ||
| 136 | a=4 echo foo 2>&1 >&$(foo) | { grep -q 'Bad file' || echo 'redir11 bad 3'; } | ||
| 137 | a=1 echo foo 2>&1 >&$(foo) | { grep -q 'Bad file' || echo 'redir11 bad 4'; } | ||
| 138 | diff --git a/tests/type.right b/tests/type.right | ||
| 139 | index bbc228e8..e0a66745 100644 | ||
| 140 | --- a/tests/type.right | ||
| 141 | +++ b/tests/type.right | ||
| 142 | @@ -24,15 +24,15 @@ func () | ||
| 143 | } | ||
| 144 | while | ||
| 145 | while is a shell keyword | ||
| 146 | -./type.tests: line 56: type: m: not found | ||
| 147 | -alias m='more' | ||
| 148 | -alias m='more' | ||
| 149 | -m is aliased to `more' | ||
| 150 | +./type.tests: line 59: type: morealias: not found | ||
| 151 | +alias morealias='more' | ||
| 152 | +alias morealias='more' | ||
| 153 | +morealias is aliased to `more' | ||
| 154 | alias | ||
| 155 | -alias m='more' | ||
| 156 | -alias m='more' | ||
| 157 | -alias m='more' | ||
| 158 | -m is aliased to `more' | ||
| 159 | +alias morealias='more' | ||
| 160 | +alias morealias='more' | ||
| 161 | +alias morealias='more' | ||
| 162 | +morealias is aliased to `more' | ||
| 163 | builtin | ||
| 164 | builtin is a shell builtin | ||
| 165 | /bin/sh | ||
| 166 | diff --git a/tests/type.tests b/tests/type.tests | ||
| 167 | index fd39c18a..ddc15407 100644 | ||
| 168 | --- a/tests/type.tests | ||
| 169 | +++ b/tests/type.tests | ||
| 170 | @@ -25,8 +25,6 @@ type -r ${THIS_SH} | ||
| 171 | type notthere | ||
| 172 | command -v notthere | ||
| 173 | |||
| 174 | -alias m=more | ||
| 175 | - | ||
| 176 | unset -f func 2>/dev/null | ||
| 177 | func() { echo this is func; } | ||
| 178 | |||
| 179 | @@ -49,24 +47,26 @@ command -V func | ||
| 180 | command -v while | ||
| 181 | command -V while | ||
| 182 | |||
| 183 | +alias morealias=more | ||
| 184 | + | ||
| 185 | # the following two lines should produce the same output | ||
| 186 | # post-3.0 patch makes command -v silent, as posix specifies | ||
| 187 | # first test with alias expansion off (should all fail or produce no output) | ||
| 188 | -type -t m | ||
| 189 | -type m | ||
| 190 | -command -v m | ||
| 191 | +type -t morealias | ||
| 192 | +type morealias | ||
| 193 | +command -v morealias | ||
| 194 | alias -p | ||
| 195 | -alias m | ||
| 196 | +alias morealias | ||
| 197 | |||
| 198 | # then test with alias expansion on | ||
| 199 | shopt -s expand_aliases | ||
| 200 | -type m | ||
| 201 | -type -t m | ||
| 202 | -command -v m | ||
| 203 | +type morealias | ||
| 204 | +type -t morealias | ||
| 205 | +command -v morealias | ||
| 206 | alias -p | ||
| 207 | -alias m | ||
| 208 | +alias morealias | ||
| 209 | |||
| 210 | -command -V m | ||
| 211 | +command -V morealias | ||
| 212 | shopt -u expand_aliases | ||
| 213 | |||
| 214 | command -v builtin | ||
| 215 | @@ -76,7 +76,7 @@ command -V /bin/sh | ||
| 216 | |||
| 217 | unset -f func | ||
| 218 | type func | ||
| 219 | -unalias m | ||
| 220 | +unalias morealias | ||
| 221 | type m | ||
| 222 | |||
| 223 | hash -r | ||
| 224 | -- | ||
| 225 | 2.35.5 | ||
| 226 | |||
diff --git a/meta/recipes-extended/bash/bash_5.2.21.bb b/meta/recipes-extended/bash/bash_5.2.21.bb index 6df73b653b..46d921bbe6 100644 --- a/meta/recipes-extended/bash/bash_5.2.21.bb +++ b/meta/recipes-extended/bash/bash_5.2.21.bb | |||
| @@ -12,6 +12,7 @@ SRC_URI = "${GNU_MIRROR}/bash/${BP}.tar.gz;name=tarball \ | |||
| 12 | file://run-bash-ptests \ | 12 | file://run-bash-ptests \ |
| 13 | file://fix-run-builtins.patch \ | 13 | file://fix-run-builtins.patch \ |
| 14 | file://use_aclocal.patch \ | 14 | file://use_aclocal.patch \ |
| 15 | file://0001-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch \ | ||
| 15 | " | 16 | " |
| 16 | 17 | ||
| 17 | SRC_URI[tarball.sha256sum] = "c8e31bdc59b69aaffc5b36509905ba3e5cbb12747091d27b4b977f078560d5b8" | 18 | SRC_URI[tarball.sha256sum] = "c8e31bdc59b69aaffc5b36509905ba3e5cbb12747091d27b4b977f078560d5b8" |
