function old new delta
readcmd 169 217 +48
shell_builtin_read 1087 1097 +10
localcmd 366 364 -2
builtin_read 197 193 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 58/-6) Total: 52 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
/* "read -s" needs to save/restore termios, can't allow ^C
* to jump out of it.
*/
+ again:
INT_OFF;
r = shell_builtin_read(setvar0,
argptr,
);
INT_ON;
+ if ((uintptr_t)r == 1 && errno == EINTR) {
+ /* to get SIGCHLD: sleep 1 & read x; echo $x */
+ if (pending_sig == 0)
+ goto again;
+ }
+
if ((uintptr_t)r > 1)
ash_msg_and_raise_error(r);
--- /dev/null
+x='Ok'
+exitcode:0
--- /dev/null
+x=BAD
+{ sleep 0.4; echo Ok; } | { sleep 0.2 & read x; echo "x='$x'"; }
+echo "exitcode:$?"
+
* - terminates shell (regardless of interactivity);
* if it has non-empty trap:
* - executes trap and returns to read;
+ * SIGCHLD from children:
+ * - does not interrupt read regardless of interactivity:
+ * try: sleep 1 & read x; echo $x
*/
static int FAST_FUNC builtin_read(char **argv)
{
if ((uintptr_t)r == 1 && errno == EINTR) {
unsigned sig = check_and_run_traps();
- if (sig && sig != SIGINT)
+ if (sig != SIGINT)
goto again;
}
--- /dev/null
+x='Ok'
+exitcode:0
--- /dev/null
+x=BAD
+{ sleep 0.4; echo Ok; } | { sleep 0.2 & read x; echo "x='$x'"; }
+echo "exitcode:$?"
+
c = buffer[bufpos];
if (c == '\0')
continue;
- if (backslash) {
- backslash = 0;
- if (c != '\n')
- goto put;
- continue;
- }
- if (!(read_flags & BUILTIN_READ_RAW) && c == '\\') {
- backslash = 1;
- continue;
+ if (!(read_flags & BUILTIN_READ_RAW)) {
+ if (backslash) {
+ backslash = 0;
+ if (c != '\n')
+ goto put;
+ continue;
+ }
+ if (c == '\\') {
+ backslash = 1;
+ continue;
+ }
}
if (c == '\n')
break;