[Toybox] [PATCH] sh: Call clearerr after running builtin command

Koudai Iwahori koudai at google.com
Fri Jan 6 22:18:17 PST 2023


When we run `echo foo > file` and `file` is a device file or FIFO,
writing to `file` can cause an error like Invalid Argument or Broken
Pipe and set an error flag of stdout. The error flag in stdout persists
in subsequent builtin commands and they always print error message
`${COMMAND_NAME}: write`.
This commit adds `clearerr(stdout)` after the execution of sh builtin
command.
---
 toys/pending/sh.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/toys/pending/sh.c b/toys/pending/sh.c
index d9abb61a..4128ee1a 100644
--- a/toys/pending/sh.c
+++ b/toys/pending/sh.c
@@ -2863,6 +2863,7 @@ static struct sh_process *run_command(void)
       }
       toys.rebound = 0;
       pp->exit = toys.exitval;
+      clearerr(stdout);
       if (toys.optargs != toys.argv+1) free(toys.optargs);
       if (toys.old_umask) umask(toys.old_umask);
       memcpy(&toys, &temp, jj);
-- 
2.39.0.314.g84b9a713c41-goog



More information about the Toybox mailing list