summaryrefslogtreecommitdiffstats
path: root/bin/sh/eval.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2012-12-12 22:01:10 +0000
committerjilles <jilles@FreeBSD.org>2012-12-12 22:01:10 +0000
commite5dd01ef24d5055696b9f61ddc0ad5e9dd3e6884 (patch)
tree62b574be073036de48cb7bc28e7e4aa2b57e010d /bin/sh/eval.c
parentbde43ee183f5f6d6eeb4949510346a87bf3cb414 (diff)
downloadFreeBSD-src-e5dd01ef24d5055696b9f61ddc0ad5e9dd3e6884.zip
FreeBSD-src-e5dd01ef24d5055696b9f61ddc0ad5e9dd3e6884.tar.gz
sh: Detect and flag write errors on stdout in builtins.
If there is a write error on stdout, a message will be printed (to stderr) and the exit status will be changed to 2 if it would have been 0 or 1. PR: bin/158206
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r--bin/sh/eval.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 8973f69..2e1315e 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -1070,6 +1070,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
}
handler = &jmploc;
redirect(cmd->ncmd.redirect, mode);
+ outclearerror(out1);
/*
* If there is no command word, redirection errors should
* not be fatal but assignment errors should.
@@ -1085,6 +1086,11 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
builtin_flags = flags;
exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
flushall();
+ if (outiserror(out1)) {
+ warning("write error on stdout");
+ if (exitstatus == 0 || exitstatus == 1)
+ exitstatus = 2;
+ }
cmddone:
if (argc > 0)
bltinunsetlocale();
OpenPOWER on IntegriCloud