diff options
| author | Wenlin Kang <wenlin.kang@windriver.com> | 2023-11-30 01:31:22 -0800 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2023-12-12 04:20:34 -1000 |
| commit | 75b08b43a43980f7fc0a46c57411deaffefce03c (patch) | |
| tree | b6f22ee783d98eb83619c92a7f82d553618dda4c | |
| parent | c4f28d96439f20419013ce73fcb51053cabe0406 (diff) | |
| download | poky-75b08b43a43980f7fc0a46c57411deaffefce03c.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
Fixed issue:
https://lists.gnu.org/archive/html/bug-bash/2023-10/msg00131.html
(From OE-Core rev: a351d62ca7deff548542c849a6fa696280b5533a)
Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
| -rw-r--r-- | meta/recipes-extended/bash/bash/0001-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch | 229 | ||||
| -rw-r--r-- | meta/recipes-extended/bash/bash_5.1.16.bb | 1 |
2 files changed, 230 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..c12b4b7766 --- /dev/null +++ b/meta/recipes-extended/bash/bash/0001-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch | |||
| @@ -0,0 +1,229 @@ | |||
| 1 | From 7e84276e07c0835a8729d6fe1265e70eedb2a7f7 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 | ||
| 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 | Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com> | ||
| 12 | --- | ||
| 13 | general.c | 5 +++-- | ||
| 14 | jobs.c | 26 ++++++++++++++++---------- | ||
| 15 | tests/redir.right | 4 ++-- | ||
| 16 | tests/redir11.sub | 2 ++ | ||
| 17 | tests/type.right | 16 ++++++++-------- | ||
| 18 | tests/type.tests | 24 ++++++++++++------------ | ||
| 19 | 6 files changed, 43 insertions(+), 34 deletions(-) | ||
| 20 | |||
| 21 | diff --git a/general.c b/general.c | ||
| 22 | index 50d5216..68987e2 100644 | ||
| 23 | --- a/general.c | ||
| 24 | +++ b/general.c | ||
| 25 | @@ -262,8 +262,9 @@ legal_number (string, result) | ||
| 26 | if (errno || ep == string) | ||
| 27 | return 0; /* errno is set on overflow or underflow */ | ||
| 28 | |||
| 29 | - /* Skip any trailing whitespace, since strtoimax does not. */ | ||
| 30 | - while (whitespace (*ep)) | ||
| 31 | + /* Skip any trailing whitespace, since strtoimax does not, using the same | ||
| 32 | + test that strtoimax uses for leading whitespace. */ | ||
| 33 | + while (isspace ((unsigned char) *ep)) | ||
| 34 | ep++; | ||
| 35 | |||
| 36 | /* If *string is not '\0' but *ep is '\0' on return, the entire string | ||
| 37 | diff --git a/jobs.c b/jobs.c | ||
| 38 | index 7c3b6e8..84dab4d 100644 | ||
| 39 | --- a/jobs.c | ||
| 40 | +++ b/jobs.c | ||
| 41 | @@ -2727,6 +2727,10 @@ wait_for_background_pids (ps) | ||
| 42 | #define INVALID_SIGNAL_HANDLER (SigHandler *)wait_for_background_pids | ||
| 43 | static SigHandler *old_sigint_handler = INVALID_SIGNAL_HANDLER; | ||
| 44 | |||
| 45 | +/* The current SIGINT handler as set by restore_sigint_handler. Only valid | ||
| 46 | + immediately after restore_sigint_handler, used for continuations. */ | ||
| 47 | +static SigHandler *cur_sigint_handler = INVALID_SIGNAL_HANDLER; | ||
| 48 | + | ||
| 49 | static int wait_sigint_received; | ||
| 50 | static int child_caught_sigint; | ||
| 51 | |||
| 52 | @@ -2743,6 +2747,7 @@ wait_sigint_cleanup () | ||
| 53 | static void | ||
| 54 | restore_sigint_handler () | ||
| 55 | { | ||
| 56 | + cur_sigint_handler = old_sigint_handler; | ||
| 57 | if (old_sigint_handler != INVALID_SIGNAL_HANDLER) | ||
| 58 | { | ||
| 59 | set_signal_handler (SIGINT, old_sigint_handler); | ||
| 60 | @@ -2766,8 +2771,7 @@ wait_sigint_handler (sig) | ||
| 61 | restore_sigint_handler (); | ||
| 62 | /* If we got a SIGINT while in `wait', and SIGINT is trapped, do | ||
| 63 | what POSIX.2 says (see builtins/wait.def for more info). */ | ||
| 64 | - if (this_shell_builtin && this_shell_builtin == wait_builtin && | ||
| 65 | - signal_is_trapped (SIGINT) && | ||
| 66 | + if (signal_is_trapped (SIGINT) && | ||
| 67 | ((sigint_handler = trap_to_sighandler (SIGINT)) == trap_handler)) | ||
| 68 | { | ||
| 69 | trap_handler (SIGINT); /* set pending_traps[SIGINT] */ | ||
| 70 | @@ -2792,6 +2796,8 @@ wait_sigint_handler (sig) | ||
| 71 | { | ||
| 72 | set_exit_status (128+SIGINT); | ||
| 73 | restore_sigint_handler (); | ||
| 74 | + if (cur_sigint_handler == INVALID_SIGNAL_HANDLER) | ||
| 75 | + set_sigint_handler (); /* XXX - only do this in one place */ | ||
| 76 | kill (getpid (), SIGINT); | ||
| 77 | } | ||
| 78 | |||
| 79 | @@ -2934,15 +2940,15 @@ wait_for (pid, flags) | ||
| 80 | { | ||
| 81 | SigHandler *temp_sigint_handler; | ||
| 82 | |||
| 83 | - temp_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler); | ||
| 84 | - if (temp_sigint_handler == wait_sigint_handler) | ||
| 85 | - { | ||
| 86 | + temp_sigint_handler = old_sigint_handler; | ||
| 87 | + old_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler); | ||
| 88 | + if (old_sigint_handler == wait_sigint_handler) | ||
| 89 | + { | ||
| 90 | #if defined (DEBUG) | ||
| 91 | - internal_warning ("wait_for: recursively setting old_sigint_handler to wait_sigint_handler: running_trap = %d", running_trap); | ||
| 92 | + internal_debug ("wait_for: recursively setting old_sigint_handler to wait_sigint_handler: running_trap = %d", running_trap); | ||
| 93 | #endif | ||
| 94 | - } | ||
| 95 | - else | ||
| 96 | - old_sigint_handler = temp_sigint_handler; | ||
| 97 | + old_sigint_handler = temp_sigint_handler; | ||
| 98 | + } | ||
| 99 | waiting_for_child = 0; | ||
| 100 | if (old_sigint_handler == SIG_IGN) | ||
| 101 | set_signal_handler (SIGINT, old_sigint_handler); | ||
| 102 | @@ -4148,7 +4154,7 @@ set_job_status_and_cleanup (job) | ||
| 103 | SIGINT (if we reset the sighandler to the default). | ||
| 104 | In this case, we have to fix things up. What a crock. */ | ||
| 105 | if (temp_handler == trap_handler && signal_is_trapped (SIGINT) == 0) | ||
| 106 | - temp_handler = trap_to_sighandler (SIGINT); | ||
| 107 | + temp_handler = trap_to_sighandler (SIGINT); | ||
| 108 | restore_sigint_handler (); | ||
| 109 | if (temp_handler == SIG_DFL) | ||
| 110 | termsig_handler (SIGINT); /* XXX */ | ||
| 111 | diff --git a/tests/redir.right b/tests/redir.right | ||
| 112 | index 8db1041..9e1403c 100644 | ||
| 113 | --- a/tests/redir.right | ||
| 114 | +++ b/tests/redir.right | ||
| 115 | @@ -154,10 +154,10 @@ foo | ||
| 116 | 1 | ||
| 117 | 7 | ||
| 118 | after: 42 | ||
| 119 | -./redir11.sub: line 53: $(ss= declare -i ss): ambiguous redirect | ||
| 120 | +./redir11.sub: line 55: $(ss= declare -i ss): ambiguous redirect | ||
| 121 | after: 42 | ||
| 122 | a+=3 | ||
| 123 | foo | ||
| 124 | foo | ||
| 125 | -./redir11.sub: line 75: 42: No such file or directory | ||
| 126 | +./redir11.sub: line 77: 42: No such file or directory | ||
| 127 | 42 | ||
| 128 | diff --git a/tests/redir11.sub b/tests/redir11.sub | ||
| 129 | index d417cdb..2a9f2b8 100644 | ||
| 130 | --- a/tests/redir11.sub | ||
| 131 | +++ b/tests/redir11.sub | ||
| 132 | @@ -56,6 +56,8 @@ foo() | ||
| 133 | a=4 b=7 foo | ||
| 134 | echo after: $a | ||
| 135 | |||
| 136 | +exec 7>&- 4>&- | ||
| 137 | + | ||
| 138 | unset a | ||
| 139 | typeset -i a | ||
| 140 | a=4 eval echo $(echo a+=3) | ||
| 141 | diff --git a/tests/type.right b/tests/type.right | ||
| 142 | index f876715..c09ab73 100644 | ||
| 143 | --- a/tests/type.right | ||
| 144 | +++ b/tests/type.right | ||
| 145 | @@ -24,15 +24,15 @@ func () | ||
| 146 | } | ||
| 147 | while | ||
| 148 | while is a shell keyword | ||
| 149 | -./type.tests: line 56: type: m: not found | ||
| 150 | -alias m='more' | ||
| 151 | -alias m='more' | ||
| 152 | -m is aliased to `more' | ||
| 153 | +./type.tests: line 56: type: morealias: not found | ||
| 154 | +alias morealias='more' | ||
| 155 | +alias morealias='more' | ||
| 156 | +morealias is aliased to `more' | ||
| 157 | alias | ||
| 158 | -alias m='more' | ||
| 159 | -alias m='more' | ||
| 160 | -alias m='more' | ||
| 161 | -m is aliased to `more' | ||
| 162 | +alias morealias='more' | ||
| 163 | +alias morealias='more' | ||
| 164 | +alias morealias='more' | ||
| 165 | +morealias is aliased to `more' | ||
| 166 | builtin | ||
| 167 | builtin is a shell builtin | ||
| 168 | /bin/sh | ||
| 169 | diff --git a/tests/type.tests b/tests/type.tests | ||
| 170 | index fd39c18..ddc1540 100644 | ||
| 171 | --- a/tests/type.tests | ||
| 172 | +++ b/tests/type.tests | ||
| 173 | @@ -25,8 +25,6 @@ type -r ${THIS_SH} | ||
| 174 | type notthere | ||
| 175 | command -v notthere | ||
| 176 | |||
| 177 | -alias m=more | ||
| 178 | - | ||
| 179 | unset -f func 2>/dev/null | ||
| 180 | func() { echo this is func; } | ||
| 181 | |||
| 182 | @@ -49,24 +47,26 @@ command -V func | ||
| 183 | command -v while | ||
| 184 | command -V while | ||
| 185 | |||
| 186 | +alias morealias=more | ||
| 187 | + | ||
| 188 | # the following two lines should produce the same output | ||
| 189 | # post-3.0 patch makes command -v silent, as posix specifies | ||
| 190 | # first test with alias expansion off (should all fail or produce no output) | ||
| 191 | -type -t m | ||
| 192 | -type m | ||
| 193 | -command -v m | ||
| 194 | +type -t morealias | ||
| 195 | +type morealias | ||
| 196 | +command -v morealias | ||
| 197 | alias -p | ||
| 198 | -alias m | ||
| 199 | +alias morealias | ||
| 200 | |||
| 201 | # then test with alias expansion on | ||
| 202 | shopt -s expand_aliases | ||
| 203 | -type m | ||
| 204 | -type -t m | ||
| 205 | -command -v m | ||
| 206 | +type morealias | ||
| 207 | +type -t morealias | ||
| 208 | +command -v morealias | ||
| 209 | alias -p | ||
| 210 | -alias m | ||
| 211 | +alias morealias | ||
| 212 | |||
| 213 | -command -V m | ||
| 214 | +command -V morealias | ||
| 215 | shopt -u expand_aliases | ||
| 216 | |||
| 217 | command -v builtin | ||
| 218 | @@ -76,7 +76,7 @@ command -V /bin/sh | ||
| 219 | |||
| 220 | unset -f func | ||
| 221 | type func | ||
| 222 | -unalias m | ||
| 223 | +unalias morealias | ||
| 224 | type m | ||
| 225 | |||
| 226 | hash -r | ||
| 227 | -- | ||
| 228 | 2.25.1 | ||
| 229 | |||
diff --git a/meta/recipes-extended/bash/bash_5.1.16.bb b/meta/recipes-extended/bash/bash_5.1.16.bb index 11c2314fbf..ab1ecffb3d 100644 --- a/meta/recipes-extended/bash/bash_5.1.16.bb +++ b/meta/recipes-extended/bash/bash_5.1.16.bb | |||
| @@ -16,6 +16,7 @@ SRC_URI = "${GNU_MIRROR}/bash/${BP}.tar.gz;name=tarball \ | |||
| 16 | file://makerace.patch \ | 16 | file://makerace.patch \ |
| 17 | file://makerace2.patch \ | 17 | file://makerace2.patch \ |
| 18 | file://CVE-2022-3715.patch \ | 18 | file://CVE-2022-3715.patch \ |
| 19 | file://0001-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch \ | ||
| 19 | " | 20 | " |
| 20 | 21 | ||
| 21 | SRC_URI[tarball.sha256sum] = "5bac17218d3911834520dad13cd1f85ab944e1c09ae1aba55906be1f8192f558" | 22 | SRC_URI[tarball.sha256sum] = "5bac17218d3911834520dad13cd1f85ab944e1c09ae1aba55906be1f8192f558" |
