1 From f5470419404d643070db99d058405b714695b817 Mon Sep 17 00:00:00 2001
2 From: Denys Vlasenko <vda.linux@googlemail.com>
3 Date: Mon, 22 May 2017 19:34:45 +0200
4 Subject: [PATCH] ash,hush: fix SIGCHLD interrupting read builtin
8 shell_builtin_read 1087 1097 +10
10 builtin_read 197 193 -4
11 ------------------------------------------------------------------------------
12 (add/remove: 0/0 grow/shrink: 2/2 up/down: 58/-6) Total: 52 bytes
14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
15 Signed-off-by: Bastian Bittorf <bb@npl.de>
17 shell/ash.c | 7 +++++++
18 shell/ash_test/ash-read/read_SIGCHLD.right | 2 ++
19 shell/ash_test/ash-read/read_SIGCHLD.tests | 4 ++++
20 shell/hush.c | 5 ++++-
21 shell/hush_test/hush-read/read_SIGCHLD.right | 2 ++
22 shell/hush_test/hush-read/read_SIGCHLD.tests | 4 ++++
23 shell/shell_common.c | 20 +++++++++++---------
24 7 files changed, 34 insertions(+), 10 deletions(-)
25 create mode 100644 shell/ash_test/ash-read/read_SIGCHLD.right
26 create mode 100755 shell/ash_test/ash-read/read_SIGCHLD.tests
27 create mode 100644 shell/hush_test/hush-read/read_SIGCHLD.right
28 create mode 100755 shell/hush_test/hush-read/read_SIGCHLD.tests
30 diff --git a/shell/ash.c b/shell/ash.c
31 index 70ee15e..60c8ffe 100644
34 @@ -13268,6 +13268,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
35 /* "read -s" needs to save/restore termios, can't allow ^C
40 r = shell_builtin_read(setvar0,
42 @@ -13280,6 +13281,12 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
46 + if ((uintptr_t)r == 1 && errno == EINTR) {
47 + /* to get SIGCHLD: sleep 1 & read x; echo $x */
48 + if (pending_sig == 0)
53 ash_msg_and_raise_error(r);
55 diff --git a/shell/ash_test/ash-read/read_SIGCHLD.right b/shell/ash_test/ash-read/read_SIGCHLD.right
57 index 0000000..b3dc7ab
59 +++ b/shell/ash_test/ash-read/read_SIGCHLD.right
63 diff --git a/shell/ash_test/ash-read/read_SIGCHLD.tests b/shell/ash_test/ash-read/read_SIGCHLD.tests
65 index 0000000..c5f673a
67 +++ b/shell/ash_test/ash-read/read_SIGCHLD.tests
70 +{ sleep 0.4; echo Ok; } | { sleep 0.2 & read x; echo "x='$x'"; }
73 diff --git a/shell/hush.c b/shell/hush.c
74 index e18920f..125463a 100644
77 @@ -9038,6 +9038,9 @@ static int FAST_FUNC builtin_type(char **argv)
78 * - terminates shell (regardless of interactivity);
79 * if it has non-empty trap:
80 * - executes trap and returns to read;
81 + * SIGCHLD from children:
82 + * - does not interrupt read regardless of interactivity:
83 + * try: sleep 1 & read x; echo $x
85 static int FAST_FUNC builtin_read(char **argv)
87 @@ -9071,7 +9074,7 @@ static int FAST_FUNC builtin_read(char **argv)
89 if ((uintptr_t)r == 1 && errno == EINTR) {
90 unsigned sig = check_and_run_traps();
91 - if (sig && sig != SIGINT)
96 diff --git a/shell/hush_test/hush-read/read_SIGCHLD.right b/shell/hush_test/hush-read/read_SIGCHLD.right
98 index 0000000..b3dc7ab
100 +++ b/shell/hush_test/hush-read/read_SIGCHLD.right
104 diff --git a/shell/hush_test/hush-read/read_SIGCHLD.tests b/shell/hush_test/hush-read/read_SIGCHLD.tests
106 index 0000000..c5f673a
108 +++ b/shell/hush_test/hush-read/read_SIGCHLD.tests
111 +{ sleep 0.4; echo Ok; } | { sleep 0.2 & read x; echo "x='$x'"; }
114 diff --git a/shell/shell_common.c b/shell/shell_common.c
115 index fb86e68..03b7d0b 100644
116 --- a/shell/shell_common.c
117 +++ b/shell/shell_common.c
118 @@ -204,15 +204,17 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
128 - if (!(read_flags & BUILTIN_READ_RAW) && c == '\\') {
131 + if (!(read_flags & BUILTIN_READ_RAW)) {