echo: do not retry on write errors
function old new delta echo_main 297 336 +39 stpcpy - 22 +22 run_pipe 1561 1566 +5 pseudo_exec_argv 187 192 +5 hush_exit 75 80 +5 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 4/0 up/down: 98/0) Total: 76 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
2
shell/ash_test/ash-misc/echo_write_error.right
Normal file
2
shell/ash_test/ash-misc/echo_write_error.right
Normal file
@@ -0,0 +1,2 @@
|
||||
ash: write error: Broken pipe
|
||||
Ok: 1
|
||||
7
shell/ash_test/ash-misc/echo_write_error.tests
Normal file
7
shell/ash_test/ash-misc/echo_write_error.tests
Normal file
@@ -0,0 +1,7 @@
|
||||
trap "" PIPE
|
||||
|
||||
{
|
||||
sleep 1
|
||||
echo Cant write this - get EPIPE
|
||||
echo Ok: $? >&2
|
||||
} | { true; }
|
||||
@@ -1 +1,2 @@
|
||||
ash: write error: Bad file descriptor
|
||||
TEST
|
||||
|
||||
@@ -1418,6 +1418,7 @@ static void sigexit(int sig)
|
||||
static void hush_exit(int exitcode) NORETURN;
|
||||
static void hush_exit(int exitcode)
|
||||
{
|
||||
fflush_all();
|
||||
if (G.exiting <= 0 && G.traps && G.traps[0] && G.traps[0][0]) {
|
||||
/* Prevent recursion:
|
||||
* trap "echo Hi; exit" EXIT; exit
|
||||
@@ -6105,10 +6106,13 @@ static void exec_builtin(char ***to_free,
|
||||
char **argv)
|
||||
{
|
||||
#if BB_MMU
|
||||
int rcode = x->b_function(argv);
|
||||
int rcode;
|
||||
fflush_all();
|
||||
rcode = x->b_function(argv);
|
||||
fflush_all();
|
||||
_exit(rcode);
|
||||
#else
|
||||
fflush_all();
|
||||
/* On NOMMU, we must never block!
|
||||
* Example: { sleep 99 | read line; } & echo Ok
|
||||
*/
|
||||
@@ -6832,6 +6836,7 @@ static NOINLINE int run_pipe(struct pipe *pi)
|
||||
if (!funcp) {
|
||||
debug_printf_exec(": builtin '%s' '%s'...\n",
|
||||
x->b_cmd, argv_expanded[1]);
|
||||
fflush_all();
|
||||
rcode = x->b_function(argv_expanded) & 0xff;
|
||||
fflush_all();
|
||||
}
|
||||
@@ -7641,6 +7646,7 @@ int hush_main(int argc, char **argv)
|
||||
G.global_argc -= builtin_argc; /* skip [BARGV...] "" */
|
||||
G.global_argv += builtin_argc;
|
||||
G.global_argv[-1] = NULL; /* replace "" */
|
||||
fflush_all();
|
||||
G.last_exitcode = x->b_function(argv + optind - 1);
|
||||
}
|
||||
goto final_return;
|
||||
|
||||
2
shell/hush_test/hush-misc/echo_write_error.right
Normal file
2
shell/hush_test/hush-misc/echo_write_error.right
Normal file
@@ -0,0 +1,2 @@
|
||||
hush: write error: Broken pipe
|
||||
Ok: 1
|
||||
7
shell/hush_test/hush-misc/echo_write_error.tests
Executable file
7
shell/hush_test/hush-misc/echo_write_error.tests
Executable file
@@ -0,0 +1,7 @@
|
||||
trap "" PIPE
|
||||
|
||||
{
|
||||
sleep 1
|
||||
echo Cant write this - get EPIPE
|
||||
echo Ok: $? >&2
|
||||
} | { true; }
|
||||
Reference in New Issue
Block a user